File tree Expand file tree Collapse file tree 3 files changed +120
-0
lines changed Expand file tree Collapse file tree 3 files changed +120
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Check SARIF
2
+ description : Checks a SARIF file to see if certain queries were run and others were not run.
3
+ inputs :
4
+ sarif-file :
5
+ required : true
6
+ description : The sarif file to check
7
+
8
+ queries-run :
9
+ required : true
10
+ description : |
11
+ Comma separated list of query ids that should be included in this SARIF file.
12
+
13
+ queries-not-run :
14
+ required : true
15
+ description : |
16
+ Comma separated list of query ids that should NOT be included in this SARIF file.
17
+
18
+ runs :
19
+ using : node12
20
+ main : index.js
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const core = require ( '@actions/core' ) ;
4
+ const fs = require ( 'fs' )
5
+
6
+ const sarif = JSON . parse ( fs . readFileSync ( core . getInput ( 'sarif-file' ) , 'utf8' ) )
7
+ const rules = sarif . runs [ 0 ] . tool . extensions . flatMap ( ext => ext . rules || [ ] )
8
+
9
+ // Expected Queries
10
+ const expectedQueriesRun = getInput ( 'queries-run' )
11
+ const queriesThatShouldHaveRunButDidnt = expectedQueriesRun . reduce ( ( acc , queryId ) => {
12
+ if ( ! rules . some ( rule => rule . id === queryId ) ) {
13
+ acc . push ( queryId )
14
+ }
15
+ return acc
16
+ } , [ ] ) ;
17
+
18
+ if ( queriesThatShouldHaveRunButDidnt . length > 0 ) {
19
+ core . setFailed ( `The following queries were expected to run but did not: ${ queriesThatShouldHaveRunButDidnt . join ( ', ' ) } ` )
20
+ }
21
+
22
+ // Unexpected Queries
23
+ const expectedQueriesNotRun = getInput ( 'queries-not-run' )
24
+
25
+ const queriesThatShouldNotHaveRunButDid = expectedQueriesNotRun . reduce ( ( acc , queryId ) => {
26
+ if ( rules . some ( rule => rule . id === queryId ) ) {
27
+ acc . push ( queryId )
28
+ }
29
+ return acc
30
+ } , [ ] ) ;
31
+
32
+ if ( queriesThatShouldNotHaveRunButDid . length > 0 ) {
33
+ core . setFailed ( `The following queries were NOT expected to have run but did: ${ queriesThatShouldNotHaveRunButDid . join ( ', ' ) } ` )
34
+ }
35
+
36
+
37
+ core . startGroup ( 'All queries run' )
38
+ rules . forEach ( rule => {
39
+ core . info ( `${ rule . id } : ${ ( rule . properties && rule . properties . name ) || rule . name } ` )
40
+ } )
41
+ core . endGroup ( )
42
+
43
+ core . startGroup ( 'Full SARIF' )
44
+ core . info ( JSON . stringify ( sarif , null , 2 ) )
45
+ core . endGroup ( )
46
+
47
+ function getInput ( name ) {
48
+ return core . getInput ( name )
49
+ . split ( ',' )
50
+ . map ( q => q . trim ( ) )
51
+ . filter ( q => q . length > 0 )
52
+ }
Original file line number Diff line number Diff line change
1
+ name : Expected queries runs
2
+ env :
3
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4
+
5
+ on :
6
+ push :
7
+ branches :
8
+ - main
9
+ - releases/v1
10
+ - releases/v2
11
+ pull_request :
12
+ types :
13
+ - opened
14
+ - synchronize
15
+ - reopened
16
+ - ready_for_review
17
+ workflow_dispatch : {}
18
+
19
+ jobs :
20
+ expected-queries :
21
+ timeout-minutes : 45
22
+ runs-on : ubuntu-latest
23
+ steps :
24
+ - name : Check out repository
25
+ uses : actions/checkout@v3
26
+ - name : Prepare test
27
+ id : prepare-test
28
+ uses : ./.github/prepare-test
29
+ with :
30
+ version : latest
31
+ - uses : ./../action/init
32
+ with :
33
+ languages : javascript
34
+ tools : ${{ steps.prepare-test.outputs.tools-url }}
35
+ - uses : ./../action/analyze
36
+ with :
37
+ output : ${{ runner.temp }}/results
38
+ upload-database : false
39
+ upload : false
40
+ env :
41
+ TEST_MODE : true
42
+
43
+ - name : Check Sarif
44
+ uses : ./../action/.github/check-sarif
45
+ with :
46
+ sarif-file : ${{ runner.temp }}/results/javascript.sarif
47
+ queries-run : js/incomplete-hostname-regexp,js/path-injection
48
+ queries-not-run : foo,bar
You can’t perform that action at this time.
0 commit comments