File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Github Docs: https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/dockerfile-support-for-github-actions
22
33# Small Linux based image with sourcehawk installed
4- FROM optumopensource/sourcehawk:0.4.4
4+ FROM optumopensource/sourcehawk:0.6.0
55
66# Need root to write
77USER root
Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ inputs:
2828 description : ' Whether or not to fail the build on scan failure'
2929 required : false
3030 default : ' true'
31+ tags :
32+ description : ' Tags to filter the scan on'
33+ required : false
3134outputs :
3235 scan-passed :
3336 description : ' "true" if scan passed, "false" otherwise'
4144 - ${{ inputs.output-file }}
4245 - ${{ inputs.fail-on-warnings }}
4346 - ${{ inputs.fail-build }}
47+ - ${{ inputs.tags }}
4448
Original file line number Diff line number Diff line change @@ -22,20 +22,19 @@ OUTPUT_FORMAT=${3:-TEXT}
2222OUTPUT_FILE=${4:- ' sourcehawk-scan-results.txt' }
2323FAIL_ON_WARNINGS=${5:- false}
2424FAIL_BUILD=${6:- true}
25+ TAGS=$7
2526
27+ # Global variables
2628PASSED=false
2729
28- # Run the scan and output the results
29- if [ " $FAIL_ON_WARNINGS " = " true" ]; then
30- sourcehawk scan --config-file " $CONFIG_FILE " --output-format " $OUTPUT_FORMAT " --fail-on-warnings " $REPOSITORY_ROOT " > " $OUTPUT_FILE "
31- else
32- sourcehawk scan --config-file " $CONFIG_FILE " --output-format " $OUTPUT_FORMAT " " $REPOSITORY_ROOT " > " $OUTPUT_FILE "
33- fi
30+ # Build command options
31+ set -- -c " $CONFIG_FILE " -f " $OUTPUT_FORMAT "
32+ [ " $FAIL_ON_WARNINGS " = true ] && set -- " $@ " -w
33+ [ -n " $TAGS " ] && set -- " $@ " -t " $TAGS "
34+ set -- " $@ " " $REPOSITORY_ROOT "
3435
35- # Determine if scan passed
36- if [ $? -eq 0 ]; then
37- PASSED=true
38- fi
36+ # Run the scan and output the results
37+ sourcehawk scan " $@ " > " $OUTPUT_FILE " && PASSED=true
3938
4039# Show the scan results
4140cat " $OUTPUT_FILE "
@@ -44,11 +43,7 @@ cat "$OUTPUT_FILE"
4443echo " ::set-output name=scan-passed::$PASSED "
4544
4645# Exit cleanly if scan passes
47- if [ " $PASSED " = " true" ]; then
48- exit 0
49- fi
46+ [ " $PASSED " = " true" ] && exit 0
5047
5148# Exit in error if configured to fail build
52- if [ " $FAIL_BUILD " = " true" ]; then
53- exit 1
54- fi
49+ [ " $FAIL_BUILD " = " true" ] && exit 1
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3- OUTPUT=$( docker run -v " $1 :/github/workspace" " $2 " " tests/scan-custom" " sh.yml" " JSON" " sourcehawk-scan-results.json" )
3+ OUTPUT=$( docker run -v " $1 :/github/workspace" " $2 " " tests/scan-custom" " sh.yml" " JSON" " sourcehawk-scan-results.json" false true " primary " )
44SCAN_EXIT_CODE=$?
55
66PASSED=()
@@ -19,11 +19,11 @@ TEST_NAME="SCAN_RESULT_JSON"
1919OUTPUT_JSON=" $( echo " $OUTPUT " | head -n -1 | sed ' s/ *$//' ) "
2020read -r -d ' ' EXPECTED_JSON << EOS
2121{
22- "passedWithNoWarnings " : true ,
22+ "errorCount " : 0 ,
2323 "passed" : true,
24- "warningCount" : 0,
2524 "messages" : { },
26- "errorCount" : 0,
25+ "passedWithNoWarnings" : true,
26+ "warningCount" : 0,
2727 "formattedMessages" : [ ]
2828}
2929EOS
Original file line number Diff line number Diff line change 1+ Foo Bar
Original file line number Diff line number Diff line change 11
22file-protocols :
33 - name : File
4- repository-path : file.txt
4+ tags :
5+ - file
6+ - primary
7+ repository-path : file.txt
8+ - name : File
9+ tags :
10+ - file
11+ - secondary
12+ repository-path : file2.txt
Original file line number Diff line number Diff line change 2424fi
2525
2626TEST_NAME=" SCAN_RESULT_ERROR"
27- SECOND_LINE=$( echo " $OUTPUT " | tail -2 | head -1 | sed -e ' s/[[:space:]]*$//' )
27+ SECOND_LINE=$( echo " $OUTPUT " | tail -2 | head -1 | sed -e ' s/[[:space:]]*$//' | sed ' s/\x1b\[[0-9;]*m//g ' )
2828EXPECTED=" [ERROR] sourcehawk.yml :: Configuration file not found"
2929if [[ " $SECOND_LINE " = " $EXPECTED " ]]; then
3030 echo " > $TEST_NAME : Correct"
Original file line number Diff line number Diff line change 2424fi
2525
2626TEST_NAME=" SCAN_RESULT_ERROR"
27- SECOND_LINE=$( echo " $OUTPUT " | tail -2 | head -1 | sed -e ' s/[[:space:]]*$//' )
27+ SECOND_LINE=$( echo " $OUTPUT " | tail -2 | head -1 | sed -e ' s/[[:space:]]*$//' | sed ' s/\x1b\[[0-9;]*m//g ' )
2828EXPECTED=" [ERROR] foo.bar :: File not found"
2929if [[ " $SECOND_LINE " = " $EXPECTED " ]]; then
3030 echo " > $TEST_NAME : Correct"
Original file line number Diff line number Diff line change 2727fi
2828
2929TEST_NAME=" SCAN_RESULT_ERROR"
30- SECOND_LINE=$( echo " $OUTPUT " | tail -2 | head -1 | sed -e ' s/[[:space:]]*$//' )
30+ SECOND_LINE=$( echo " $OUTPUT " | tail -2 | head -1 | sed -e ' s/[[:space:]]*$//' | sed ' s/\x1b\[[0-9;]*m//g ' )
3131EXPECTED=" [WARN] foo.bar :: File not found"
3232if [[ " $SECOND_LINE " = " $EXPECTED " ]]; then
3333 echo " > $TEST_NAME : Correct"
You can’t perform that action at this time.
0 commit comments