File tree Expand file tree Collapse file tree 9 files changed +33
-25
lines changed Expand file tree Collapse file tree 9 files changed +33
-25
lines changed Original file line number Diff line number Diff line change 1
1
# Github Docs: https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/dockerfile-support-for-github-actions
2
2
3
3
# Small Linux based image with sourcehawk installed
4
- FROM optumopensource/sourcehawk:0.4.4
4
+ FROM optumopensource/sourcehawk:0.6.0
5
5
6
6
# Need root to write
7
7
USER root
Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ inputs:
28
28
description : ' Whether or not to fail the build on scan failure'
29
29
required : false
30
30
default : ' true'
31
+ tags :
32
+ description : ' Tags to filter the scan on'
33
+ required : false
31
34
outputs :
32
35
scan-passed :
33
36
description : ' "true" if scan passed, "false" otherwise'
41
44
- ${{ inputs.output-file }}
42
45
- ${{ inputs.fail-on-warnings }}
43
46
- ${{ inputs.fail-build }}
47
+ - ${{ inputs.tags }}
44
48
Original file line number Diff line number Diff line change @@ -22,20 +22,19 @@ OUTPUT_FORMAT=${3:-TEXT}
22
22
OUTPUT_FILE=${4:- ' sourcehawk-scan-results.txt' }
23
23
FAIL_ON_WARNINGS=${5:- false}
24
24
FAIL_BUILD=${6:- true}
25
+ TAGS=$7
25
26
27
+ # Global variables
26
28
PASSED=false
27
29
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 "
34
35
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
39
38
40
39
# Show the scan results
41
40
cat " $OUTPUT_FILE "
@@ -44,11 +43,7 @@ cat "$OUTPUT_FILE"
44
43
echo " ::set-output name=scan-passed::$PASSED "
45
44
46
45
# Exit cleanly if scan passes
47
- if [ " $PASSED " = " true" ]; then
48
- exit 0
49
- fi
46
+ [ " $PASSED " = " true" ] && exit 0
50
47
51
48
# 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 1
1
#! /usr/bin/env bash
2
2
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 " )
4
4
SCAN_EXIT_CODE=$?
5
5
6
6
PASSED=()
@@ -19,11 +19,11 @@ TEST_NAME="SCAN_RESULT_JSON"
19
19
OUTPUT_JSON=" $( echo " $OUTPUT " | head -n -1 | sed ' s/ *$//' ) "
20
20
read -r -d ' ' EXPECTED_JSON << EOS
21
21
{
22
- "passedWithNoWarnings " : true ,
22
+ "errorCount " : 0 ,
23
23
"passed" : true,
24
- "warningCount" : 0,
25
24
"messages" : { },
26
- "errorCount" : 0,
25
+ "passedWithNoWarnings" : true,
26
+ "warningCount" : 0,
27
27
"formattedMessages" : [ ]
28
28
}
29
29
EOS
Original file line number Diff line number Diff line change
1
+ Foo Bar
Original file line number Diff line number Diff line change 1
1
2
2
file-protocols :
3
3
- 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 24
24
fi
25
25
26
26
TEST_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 ' )
28
28
EXPECTED=" [ERROR] sourcehawk.yml :: Configuration file not found"
29
29
if [[ " $SECOND_LINE " = " $EXPECTED " ]]; then
30
30
echo " > $TEST_NAME : Correct"
Original file line number Diff line number Diff line change 24
24
fi
25
25
26
26
TEST_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 ' )
28
28
EXPECTED=" [ERROR] foo.bar :: File not found"
29
29
if [[ " $SECOND_LINE " = " $EXPECTED " ]]; then
30
30
echo " > $TEST_NAME : Correct"
Original file line number Diff line number Diff line change 27
27
fi
28
28
29
29
TEST_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 ' )
31
31
EXPECTED=" [WARN] foo.bar :: File not found"
32
32
if [[ " $SECOND_LINE " = " $EXPECTED " ]]; then
33
33
echo " > $TEST_NAME : Correct"
You can’t perform that action at this time.
0 commit comments