Skip to content

Commit

Permalink
Merge branch 'aeisenberg/check-sarif-action' into aeisenberg/remove-q…
Browse files Browse the repository at this point in the history
…ueries
  • Loading branch information
aeisenberg committed Jun 16, 2022
2 parents 6db77ee + 6834383 commit d7459f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
33 changes: 12 additions & 21 deletions .github/check-sarif/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
'use strict'

const core = require('@actions/core');
const core = require('@actions/core')
const fs = require('fs')

const sarif = JSON.parse(fs.readFileSync(core.getInput('sarif-file'), 'utf8'))
const rules = sarif.runs[0].tool.extensions.flatMap(ext => ext.rules || [])
const ruleIds = rules.map(rule => rule.id)

// Expected Queries
const expectedQueriesRun = getInput('queries-run')
const queriesThatShouldHaveRunButDidnt = expectedQueriesRun.reduce((acc, queryId) => {
if (!rules.some(rule => rule.id === queryId)) {
acc.push(queryId)
}
return acc
}, []);

if (queriesThatShouldHaveRunButDidnt.length > 0) {
core.setFailed(`The following queries were expected to run but did not: ${queriesThatShouldHaveRunButDidnt.join(', ')}`)
// Check that all the expected queries ran
const expectedQueriesRun = getQueryIdsInput('queries-run')
const queriesThatShouldHaveRunButDidNot = expectedQueriesRun.filter(queryId => !ruleIds.includes(queryId))

if (queriesThatShouldHaveRunButDidNot.length > 0) {
core.setFailed(`The following queries were expected to run but did not: ${queriesThatShouldHaveRunButDidNot.join(', ')}`)
}

// Unexpected Queries
const expectedQueriesNotRun = getInput('queries-not-run')
// Check that all the unexpected queries did not run
const expectedQueriesNotRun = getQueryIdsInput('queries-not-run')

const queriesThatShouldNotHaveRunButDid = expectedQueriesNotRun.reduce((acc, queryId) => {
if (rules.some(rule => rule.id === queryId)) {
acc.push(queryId)
}
return acc
}, []);
const queriesThatShouldNotHaveRunButDid = expectedQueriesNotRun.filter(queryId => ruleIds.includes(queryId))

if (queriesThatShouldNotHaveRunButDid.length > 0) {
core.setFailed(`The following queries were NOT expected to have run but did: ${queriesThatShouldNotHaveRunButDid.join(', ')}`)
Expand All @@ -44,7 +35,7 @@ core.startGroup('Full SARIF')
core.info(JSON.stringify(sarif, null, 2))
core.endGroup()

function getInput(name) {
function getQueryIdsInput(name) {
return core.getInput(name)
.split(',')
.map(q => q.trim())
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/expected-queries-runs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jobs:
- name: Check Sarif
uses: ./../action/.github/check-sarif
with:
sarif-file: ${{ runner.temp }}/results/javascript.sarif
sarif-file: ${{ runner.temp }}/results/javascript.sarif
queries-run: js/incomplete-hostname-regexp,js/path-injection
queries-not-run: foo,bar

0 comments on commit d7459f0

Please sign in to comment.