Skip to content

Commit f1abf90

Browse files
committed
Update to sourcehawk 0.6.0
1 parent 49c2274 commit f1abf90

File tree

9 files changed

+33
-25
lines changed

9 files changed

+33
-25
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
77
USER root

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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
3134
outputs:
3235
scan-passed:
3336
description: '"true" if scan passed, "false" otherwise'
@@ -41,4 +44,5 @@ runs:
4144
- ${{ inputs.output-file }}
4245
- ${{ inputs.fail-on-warnings }}
4346
- ${{ inputs.fail-build }}
47+
- ${{ inputs.tags }}
4448

entrypoint.sh

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@ OUTPUT_FORMAT=${3:-TEXT}
2222
OUTPUT_FILE=${4:-'sourcehawk-scan-results.txt'}
2323
FAIL_ON_WARNINGS=${5:-false}
2424
FAIL_BUILD=${6:-true}
25+
TAGS=$7
2526

27+
# Global variables
2628
PASSED=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
4140
cat "$OUTPUT_FILE"
@@ -44,11 +43,7 @@ cat "$OUTPUT_FILE"
4443
echo "::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

tests/scan-custom.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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")
44
SCAN_EXIT_CODE=$?
55

66
PASSED=()
@@ -19,11 +19,11 @@ TEST_NAME="SCAN_RESULT_JSON"
1919
OUTPUT_JSON="$(echo "$OUTPUT" | head -n -1 | sed 's/ *$//')"
2020
read -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
}
2929
EOS

tests/scan-custom/file2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Foo Bar

tests/scan-custom/sh.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

22
file-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

tests/scan-error.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ else
2424
fi
2525

2626
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')
2828
EXPECTED="[ERROR] sourcehawk.yml :: Configuration file not found"
2929
if [[ "$SECOND_LINE" = "$EXPECTED" ]]; then
3030
echo " > $TEST_NAME: Correct"

tests/scan-failed.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ else
2424
fi
2525

2626
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')
2828
EXPECTED="[ERROR] foo.bar :: File not found"
2929
if [[ "$SECOND_LINE" = "$EXPECTED" ]]; then
3030
echo " > $TEST_NAME: Correct"

tests/scan-warning-fail.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ else
2727
fi
2828

2929
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')
3131
EXPECTED="[WARN] foo.bar :: File not found"
3232
if [[ "$SECOND_LINE" = "$EXPECTED" ]]; then
3333
echo " > $TEST_NAME: Correct"

0 commit comments

Comments
 (0)