@@ -37,11 +37,11 @@ jobs:
37
37
make docker-build IMG="${{ env.IMAGE_NAME }}:${{ github.sha }}"
38
38
39
39
- name : Run Trivy vulnerability scanner
40
- uses : aquasecurity/trivy-action@master
40
+ uses : aquasecurity/trivy-action@0.18.0
41
41
with :
42
42
scan-type : image
43
43
image-ref : " ${{ env.IMAGE_NAME }}:${{ github.sha }}"
44
- exit-code : 1
44
+ exit-code : 0
45
45
ignore-unfixed : true
46
46
vuln-type : os,library
47
47
severity : HIGH,CRITICAL
@@ -51,19 +51,32 @@ jobs:
51
51
template : " @.github/ISSUE_TEMPLATE/trivy-results.tpl"
52
52
output : ${{ env.TRIVY_RESULTS_MARKDOWN }}
53
53
54
+ - name : Extract total count of vulnerabilities
55
+ id : extract-total-cnt-of-vulns
56
+ run : |
57
+ if [[ $(cat "${{ env.TRIVY_RESULTS_MARKDOWN }}") =~ Total\ count\ of\ vulnerabilities:\ ([0-9]+) ]]; then
58
+ result=${BASH_REMATCH[0]}
59
+ echo "$result"
60
+ total_cnt_of_vulns=${BASH_REMATCH[1]}
61
+ echo "total_cnt_of_vulns=$total_cnt_of_vulns" >> "$GITHUB_OUTPUT"
62
+ else
63
+ echo "Error: Failed to extract total count of vulnerabilities"
64
+ exit 1
65
+ fi
66
+
54
67
- name : Insert YAML front matter into the results markdown
55
- if : always()
68
+ if : ${{ fromJson(steps.extract-total-cnt-of-vulns.outputs.total_cnt_of_vulns) > 0 }}
56
69
run : |
57
70
sed -i '1i\
58
71
---\
59
- title: "[DO NOT CHANGE] Security Alert"\
72
+ title: "Security Alert by Trivy "\
60
73
labels: "trivy, vulnerability"\
61
74
---\
62
75
' "${{ env.TRIVY_RESULTS_MARKDOWN }}"
63
76
64
77
- name : Create or update the trivy results issue
78
+ if : ${{ fromJson(steps.extract-total-cnt-of-vulns.outputs.total_cnt_of_vulns) > 0 }}
65
79
uses : JasonEtco/create-an-issue@v2
66
- if : always()
67
80
env :
68
81
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69
82
with :
0 commit comments