Skip to content

Commit 196964f

Browse files
authored
Merge pull request #7 from neuvector/NVSHAS-8797-improve-set-output
[NVSHAS-8797] Add variable to the GITHUB_OUTPUT for future reference
2 parents a171182 + fa8e0a3 commit 196964f

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ RUN zypper in -y jq docker && zypper clean
55
COPY run-scan.sh /usr/bin
66
COPY utils.sh /usr/bin
77

8+
RUN chmod +x /usr/bin/run-scan.sh
9+
810
ENTRYPOINT ["/usr/bin/run-scan.sh"]

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ runs:
7272
NV_SCANNER_IMAGE: ${{ inputs.nv-scanner-image }}
7373
DEBUG: ${{ inputs.debug }}
7474
OUTPUT: ${{ inputs.output }}
75+
GITHUB_OUTPUT: $GITHUB_OUTPUT
7576

7677
branding:
7778
icon: search

run-scan.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ FOUND_MEDIUM=$(cat scan_result.json | jq '.report.vulnerabilities[] | select(.se
4545
VUL_LIST=$(printf '["%s"]' "${VUL_NAMES_TO_FAIL//,/\",\"}")
4646
VUL_LIST_FOUND=$(cat scan_result.json | jq --arg arr "$VUL_LIST" '.report.vulnerabilities[] | select(.name as $n | $arr | index($n)) |.name')
4747

48+
echo "GITHUB_OUTPUT: $GITHUB_OUTPUT"
49+
echo "vulnerability_count=$VUL_NUM" >> "$GITHUB_OUTPUT"
50+
echo "high_vulnerability_count=$FOUND_HIGH" >> "$GITHUB_OUTPUT"
51+
echo "medium_vulnerability_count=$FOUND_MEDIUM" >> "$GITHUB_OUTPUT"
52+
4853
# we must count the high and med before we put.
4954
if [[ -n $VUL_LIST_FOUND ]]; then
5055
fail_reason="Found specific named vulnerabilities."

test/scan-image.bats

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env bats
2+
export GITHUB_OUTPUT="/github-output"
23

34
setup_file() {
45
docker build . -t neuvector/scan-action
56
}
67

78
@test "docker daemon not reachable" {
8-
run docker run --rm -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 neuvector/scan-action
9+
run docker run --rm -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
910
echo "Status $status"
1011
echo "Output"
1112
echo -e $output
@@ -14,7 +15,7 @@ setup_file() {
1415
}
1516

1617
@test "invalid scanner image" {
17-
run docker run --rm -e NV_SCANNER_IMAGE=invalid-image:latest -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
18+
run docker run --rm -e NV_SCANNER_IMAGE=invalid-image:latest -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
1819
echo "Status $status"
1920
echo "Output"
2021
echo -e $output
@@ -23,7 +24,7 @@ setup_file() {
2324
}
2425

2526
@test "scan image with vulnerabilities but don't fail" {
26-
run docker run --rm -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
27+
run docker run --rm -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
2728
echo "Status $status"
2829
echo "Output"
2930
echo -e $output
@@ -32,7 +33,7 @@ setup_file() {
3233
}
3334

3435
@test "scan image with vulnerabilities and high severity fail" {
35-
run docker run --rm -e HIGH_VUL_TO_FAIL=1 -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
36+
run docker run --rm -e HIGH_VUL_TO_FAIL=1 -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
3637
echo "Status $status"
3738
echo "Output"
3839
echo -e $output
@@ -41,7 +42,7 @@ setup_file() {
4142
}
4243

4344
@test "scan image with vulnerabilities and medium severity fail" {
44-
run docker run --rm -e MEDIUM_VUL_TO_FAIL=1 -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
45+
run docker run --rm -e MEDIUM_VUL_TO_FAIL=1 -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
4546
echo "Status $status"
4647
echo "Output"
4748
echo -e $output
@@ -50,7 +51,7 @@ setup_file() {
5051
}
5152

5253
@test "scan image with vulnerabilities and specific CVE fail" {
53-
run docker run --rm -e VUL_NAMES_TO_FAIL=invalid,CVE-2020-16156 -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
54+
run docker run --rm -e VUL_NAMES_TO_FAIL=invalid,CVE-2020-16156 -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
5455
echo "Status $status"
5556
echo "Output"
5657
echo -e $output
@@ -59,7 +60,7 @@ setup_file() {
5960
}
6061

6162
@test "scan image with json output" {
62-
run docker run --rm -e OUTPUT=json -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
63+
run docker run --rm -e OUTPUT=json -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
6364
echo "Status $status"
6465
echo "Output"
6566
echo -e $output
@@ -68,7 +69,7 @@ setup_file() {
6869
}
6970

7071
@test "scan image with csv output" {
71-
run docker run --rm -e OUTPUT=csv -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock neuvector/scan-action
72+
run docker run --rm -e OUTPUT=csv -e SCANNER_REGISTRY=https://index.docker.io/ -e SCANNER_REPOSITORY=library/debian -e SCANNER_TAG=11.0 -v /var/run/docker.sock:/var/run/docker.sock -e GITHUB_OUTPUT="${GITHUB_OUTPUT}" -v "/github/output:/tmp" neuvector/scan-action
7273
echo "Status $status"
7374
echo "Output"
7475
echo -e $output

0 commit comments

Comments
 (0)