From c78fb87659d27d2c8d5a2a38ecdb19ebdbfd3b2c Mon Sep 17 00:00:00 2001 From: Mario Campos Date: Thu, 1 Jul 2021 15:26:04 -0500 Subject: [PATCH] Add test case for 'source-root' input to 'init' Action --- .github/workflows/pr-checks.yml | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 1798d4532..a43b274aa 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -894,3 +894,44 @@ jobs: - name: Build code run: ./build.sh - uses: ./../action/analyze + + test-packaging-javascript-source-root: + needs: [check-js, check-node-modules] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Move codeql-action + shell: bash + run: | + mkdir ../action + mv * .github ../action/ + mv ../action/tests/multi-language-repo/{*,.github} . + mv ../action/.github/workflows .github + - uses: ./../action/init + with: + config-file: ".github/codeql/codeql-config-packaging2.yml" + languages: javascript + source-root: tests/multi-language-repo + - name: Build code + shell: bash + run: ./build.sh + - uses: ./../action/analyze + with: + output: "${{ runner.temp }}/results" + env: + TEST_MODE: true + - name: Assert Results + run: | + cd "$RUNNER_TEMP/results" + # We should have 3 hits from these rules + EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/two-block" + + # use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace + RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | xargs)" + echo "Found matching rules '$RULES'" + if [ "$RULES" != "$EXPECTED_RULES" ]; then + echo "Did not match expected rules '$EXPECTED_RULES'." + exit 1 + fi +