Skip to content

Commit

Permalink
add new workflow step to test with bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed May 17, 2024
1 parent 7c650b5 commit 0419291
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 12 deletions.
36 changes: 30 additions & 6 deletions .github/workflows/demo-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,49 @@ jobs:
env:
PULL_REQUEST_BODY: ${{ github.event.pull_request.body }}
run: |
echo "BUILD_BUNDLE=false" >> $GITHUB_OUTPUT
# if this is a PR, we should use the base branch
# else, use the branch on which this is running
if [ ! -z ${GITHUB_BASE_REF} ]; then
echo "Using ${GITHUB_BASE_REF}"
echo "API_TESTS_REF=${GITHUB_BASE_REF}" >> $GITHUB_OUTPUT
echo "ADDON_REF=${GITHUB_BASE_REF}" >>$GITHUB_ENV
echo "JAVA_BUNDLE_REF=${GITHUB_BASE_REF}" >>$GITHUB_OUTPUT
else
echo "Using ${GITHUB_REF_NAME}"
echo "API_TESTS_REF=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
echo "ADDON_REF=${GITHUB_REF_NAME}" >>$GITHUB_ENV
echo "JAVA_BUNDLE_REF=${GITHUB_REF_NAME}" >>$GITHUB_OUTPUT
fi
# override with explicitely set value in PR description
echo "${PULL_REQUEST_BODY}"
PULL_REQUEST_NUMBER=$(echo "${PULL_REQUEST_BODY}" | grep -oP '[A|a]ddon [P|p][R|r]: \K\d+' || true)
if [ ! -z "$PULL_REQUEST_NUMBER" ]; then
echo "Using pull/${PULL_REQUEST_NUMBER} for addon"
echo "ADDON_REF=refs/pull/$PULL_REQUEST_NUMBER/merge" >>$GITHUB_ENV
fi
ADDON_PULL_REQUEST_NUMBER=$(echo "${PULL_REQUEST_BODY}" | grep -oP '[A|a]ddon [P|p][R|r]: \K\d+' || true)
if [ ! -z "$ADDON_PULL_REQUEST_NUMBER" ]; then
echo "Using pull/${ADDON_PULL_REQUEST_NUMBER} for addon"
echo "ADDON_REF=refs/pull/$ADDON_PULL_REQUEST_NUMBER/merge" >>$GITHUB_ENV
fi
JAVA_BUNDLE_PR_NUMBER=$(echo "${PULL_REQUEST_BODY}" | grep -oP '[B|b]undle [P|p][R|r]: \K\d+' || true)
if [ ! -z "$JAVA_BUNDLE_PR_NUMBER" ]; then
echo "Using bundle PR pull/${JAVA_BUNDLE_PR_NUMBER}"
echo "JAVA_BUNDLE_REF=refs/pull/$JAVA_BUNDLE_PR_NUMBER/merge" >> $GITHUB_OUTPUT
echo "BUILD_BUNDLE=true" >>$GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
if: steps.extract-info.outputs.BUILD_BUNDLE
with:
fetch-depth: 0
repository: konveyor/java-analyzer-bundle
ref: "${{ env.JAVA_BUNDLE_REF }}"
path: java-analyzer-bundle

- name: build java analyzer bundle image
if: steps.extract-info.outputs.BUILD_BUNDLE
working-directory: java-analyzer-bundle
run: |
podman build -t quay.io/konveyor/jdtls-server-base:latest -f Dockerfile .
- uses: actions/checkout@v3

Expand Down Expand Up @@ -64,7 +88,7 @@ jobs:
with:
fetch-depth: 0
repository: konveyor/tackle2-addon-analyzer
ref: "${{ env.ADDON_REF}}"
ref: "${{ env.ADDON_REF }}"
path: tackle2-addon-analyzer

- name: Build addon and save image
Expand Down
90 changes: 88 additions & 2 deletions demo-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,58 @@
- Language=Golang
- License=Apache
violations:
builtin-inclusion-test-json:
description: |
This is same as java-io-file-usage but for the builtin providers. There are multiple instances of the same incidents in different directories.
We are filtering some out using includedPaths setting.
category: optional
incidents:
- uri: file:///examples/builtin/inclusion_tests/dir-0/inclusion-test.json
message: Only incidents in dir-0/inclusion-test.json should be found
- uri: file:///examples/builtin/inclusion_tests/dir-0/inclusion-test.json
message: Only incidents in dir-0/inclusion-test.json should be found
codeSnip: |2
1 {
2 "description": "Does your JSON search work?",
3 "name": "test-your-json-search",
4 "inclusionTestNode": "Test this node"
5 }
lineNumber: 4
variables:
data: inclusionTestNode
matchingJSON: Test this node
- uri: file:///examples/builtin/inclusion_tests/dir-0/inclusion-test.xml
message: Only incidents in dir-0/inclusion-test.json should be found
codeSnip: |2
1 <xmlTest>
2 <description>Does your XML search work?</description>
3 <name>xml-search</name>
4 <inclusionTestNode>Test this node</inclusionTestNode>
5 </xmlTest>
lineNumber: 4
variables:
matchingText: inclusionTestNode
builtin-inclusion-test-xml:
description: |
This is same as java-io-file-usage but for the builtin providers. There are multiple instances of the same incidents in different directories.
We are filtering some out using includedPaths setting.
category: optional
incidents:
- uri: file:///examples/builtin/inclusion_tests/dir-0/inclusion-test.xml
message: Only incidents in dir-0/inclusion-test.xml should be found
- uri: file:///examples/builtin/inclusion_tests/dir-0/inclusion-test.xml
message: Only incidents in dir-0/inclusion-test.xml should be found
codeSnip: |2
1 <xmlTest>
2 <description>Does your XML search work?</description>
3 <name>xml-search</name>
4 <inclusionTestNode>Test this node</inclusionTestNode>
5 </xmlTest>
lineNumber: 4
variables:
data: inclusionTestNode
innerText: Test this node
matchingXML: Test this node
chain-pom-001:
description: ""
category: potential
Expand Down Expand Up @@ -306,6 +358,24 @@
description: "This rule tests includedPaths config of the java provider. There should be two instances of this issue in the example app. \nWe are filtering one of them using includedPaths in provider config.\n"
category: mandatory
incidents:
- uri: file:///examples/java/example/src/main/java/com/example/apps/App.java
message: Only incidents in util/FileReader.java should be found
codeSnip: " 1 package com.example.apps;\n 2 \n 3 import java.io.File;\n 4 import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;\n 5 \n 6 public class App \n 7 {\n 8 \n 9 /**\n10 * {@link CustomResourceDefinition}\n11 * @param args\n12 */\n13 public static void main( String[] args )"
lineNumber: 3
variables:
file: file:///examples/java/example/src/main/java/com/example/apps/App.java
kind: Module
name: java.io.File
package: com.example.apps
- uri: file:///examples/java/example/src/main/java/com/example/apps/App.java
message: Only incidents in util/FileReader.java should be found
codeSnip: "12 */\n13 public static void main( String[] args )\n14 {\n15 CustomResourceDefinition crd = new CustomResourceDefinition();\n16 System.out.println( crd );\n17 \n18 GenericClass<String> element = new GenericClass<String>(\"Hello world!\");\n19 element.get();\n20 \n21 // test file usage\n22 File file = new File(\"test\");\n23 if (file.exists()) {\n24 System.out.println(\"file exists\");\n25 }\n26 }\n27 }\n"
lineNumber: 22
variables:
file: file:///examples/java/example/src/main/java/com/example/apps/App.java
kind: Method
name: main
package: com.example.apps
- uri: file:///examples/java/example/src/main/java/com/example/apps/util/FileReader.java
message: Only incidents in util/FileReader.java should be found
codeSnip: " 1 package com.example.apps.util;\n 2 \n 3 import java.io.File;\n 4 \n 5 public class FileReader {\n 6 public static void main(String[] args) {\n 7 File file = new File(\"test\");\n 8 if (file.exists()) {\n 9 System.out.println(\"file exists\");\n10 }\n11 }\n12 \n13 }"
Expand Down Expand Up @@ -520,6 +590,15 @@
kind: Class
name: Singleton
package: com.example.apps
- uri: file:///examples/java/example/src/main/java/com/example/apps/Bean.java
message: condition entries should evaluate out of order
codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public abstract class Bean implements SessionBean {\n 8 \n 9 }\n"
lineNumber: 7
variables:
file: file:///examples/java/example/src/main/java/com/example/apps/Bean.java
kind: Class
name: Bean
package: com.example.apps
singleton-sessionbean-00002:
description: ""
category: potential
Expand All @@ -533,6 +612,15 @@
kind: Class
name: Singleton
package: com.example.apps
- uri: file:///examples/java/example/src/main/java/com/example/apps/Bean.java
message: condition entries should evaluate in order
codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public abstract class Bean implements SessionBean {\n 8 \n 9 }\n"
lineNumber: 7
variables:
file: file:///examples/java/example/src/main/java/com/example/apps/Bean.java
kind: Class
name: Bean
package: com.example.apps
tech-tag-001:
description: ""
category: potential
Expand Down Expand Up @@ -808,8 +896,6 @@
unable to get query info: yaml: unmarshal errors:
line 9: cannot unmarshal !!map into string
unmatched:
- builtin-inclusion-test-json
- builtin-inclusion-test-xml
- file-002
- lang-ref-002
- python-sample-rule-003
3 changes: 1 addition & 2 deletions provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ func queryXMLFile(filePath string, query *xpath.Expr) (nodes []*xmlquery.Node, e
return nodes, err
}

// filterByIncludedPaths given a list of file paths,
// filters-out the ones not present in includedPaths
// isFileIncluded given a path, returns whether the path is included in the includedPaths provider config
func (b *builtinServiceClient) isFileIncluded(absolutePath string) bool {
if b.includedPaths == nil || len(b.includedPaths) == 0 {
return true
Expand Down
4 changes: 2 additions & 2 deletions rule-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
description: |
This is same as java-io-file-usage but for the builtin providers. There are multiple instances of the same incidents in different directories.
We are filtering some out using includedPaths setting.
message: Only incidents in dir-0/test.json should be found
message: Only incidents in dir-0/inclusion-test.json should be found
ruleID: builtin-inclusion-test-json
when:
and:
Expand All @@ -281,7 +281,7 @@
description: |
This is same as java-io-file-usage but for the builtin providers. There are multiple instances of the same incidents in different directories.
We are filtering some out using includedPaths setting.
message: Only incidents in dir-0/test.xml should be found
message: Only incidents in dir-0/inclusion-test.xml should be found
ruleID: builtin-inclusion-test-xml
when:
and:
Expand Down

0 comments on commit 0419291

Please sign in to comment.