1212 # https://github.com/actions/setup-go/issues/457
1313 GOTOOLCHAIN : local
1414
15- # Manage the Trivy data directory until upstream can do it reliably
16- # https://github.com/aquasecurity/trivy-action/issues/389
17- #
18- # NOTE: This must match the default "cache-dir" upstream:
19- # https://github.com/aquasecurity/trivy-action/blob/-/action.yaml
20- TRIVY_CACHE_DIR : ${{ github.workspace }}/.cache/trivy
21-
2215jobs :
2316 cache :
2417 runs-on : ubuntu-latest
2518 steps :
26- -
uses :
aquasecurity/[email protected] 27- with :
28- cache : true
29- version : v0.57.0
30-
31- # The "aquasecurity/trivy-action" looks for data in the GitHub action
32- # cache under a key with today's date.
33- # - https://github.com/actions/cache/blob/-/restore#readme
34- # - https://github.com/aquasecurity/trivy-action/blob/-/action.yaml
35- - id : values
36- run : |
37- (
38- date +'date=%Y-%m-%d'
39- echo "glob=${TRIVY_CACHE_DIR}/*/metadata.json"
40- ) |
41- tee --append $GITHUB_OUTPUT
42- - id : restore
43- uses : actions/cache/restore@v4
44- with :
45- key : cache-trivy-${{ steps.values.outputs.date }}
46- path : ${{ env.TRIVY_CACHE_DIR }}
47- restore-keys : cache-trivy-
48-
49- # Validate or update the Trivy data cache.
50- - id : validate
19+ - uses : actions/checkout@v4
20+ - uses : ./.github/actions/trivy
5121 env :
52- METADATA_HASH : ${{ hashFiles(steps.values.outputs.glob) }}
53- run : |
54- <<< "before=${METADATA_HASH}" tee --append $GITHUB_OUTPUT
55- trivy filesystem --download-db-only --scanners license,secret,vuln --quiet
56-
57- # Save any successful changes back to the GitHub action cache.
58- # - https://github.com/actions/cache/blob/-/save#readme
59- - if : ${{ hashFiles(steps.values.outputs.glob) != steps.validate.outputs.before }}
60- uses : actions/cache/save@v4
61- with :
62- key : ${{ steps.restore.outputs.cache-primary-key }}
63- path : ${{ env.TRIVY_CACHE_DIR }}
22+ TRIVY_DB_DOWNLOAD_ONLY : true
23+ TRIVY_QUIET : true
24+ TRIVY_SCANNERS : license,secret,vuln
6425
6526 licenses :
6627 needs : [cache]
@@ -75,13 +36,13 @@ jobs:
7536
7637 # Report success only when detected licenses are listed in [/trivy.yaml].
7738 - name : Scan licenses
78- uses :
aquasecurity/[email protected] 39+ uses : ./.github/actions/trivy
7940 env :
8041 TRIVY_DEBUG : true
42+ TRIVY_EXIT_CODE : 1
43+ TRIVY_SCANNERS : license
8144 with :
82- scan-type : filesystem
83- scanners : license
84- exit-code : 1
45+ cache : restore,use
8546
8647 vulnerabilities :
8748 if : ${{ github.repository == 'CrunchyData/postgres-operator' }}
@@ -97,21 +58,24 @@ jobs:
9758 # human consumption. This step fails only when Trivy is unable to scan.
9859 # A later step uploads results to GitHub as a pull request check.
9960 - name : Log detected vulnerabilities
100- uses :
aquasecurity/[email protected] 61+ uses : ./.github/actions/trivy
62+ env :
63+ TRIVY_SCANNERS : secret,vuln
10164 with :
102- scan-type : filesystem
103- scanners : secret,vuln
65+ cache : restore,use
10466
10567 # Produce a SARIF report of actionable results. This step fails only when
10668 # Trivy is unable to scan.
10769 - name : Report actionable vulnerabilities
108- uses :
aquasecurity/[email protected] 70+ uses : ./.github/actions/trivy
71+ env :
72+ TRIVY_IGNORE_UNFIXED : true
73+ TRIVY_FORMAT : ' sarif'
74+ TRIVY_OUTPUT : ' trivy-results.sarif'
75+ TRIVY_SCANNERS : secret,vuln
10976 with :
110- scan-type : filesystem
111- ignore-unfixed : true
112- format : ' sarif'
113- output : ' trivy-results.sarif'
114- scanners : secret,vuln
77+ cache : use
78+ setup : none
11579
11680 # Submit the SARIF report to GitHub code scanning. Pull requests checks
11781 # succeed or fail according to branch protection rules.
0 commit comments