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 :
17+ # Run only one of these jobs at a time across the entire project.
18+ concurrency : { group: trivy-cache }
19+
2420 runs-on : ubuntu-latest
2521 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
22+ - uses : actions/checkout@v4
23+ - name : Download Trivy
24+ uses : ./.github/actions/trivy
5125 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 }}
26+ TRIVY_DEBUG : true
27+ TRIVY_DOWNLOAD_DB_ONLY : true
28+ TRIVY_NO_PROGRESS : true
29+ TRIVY_SCANNERS : license,secret,vuln
6430
6531 licenses :
6632 needs : [cache]
@@ -75,13 +41,13 @@ jobs:
7541
7642 # Report success only when detected licenses are listed in [/trivy.yaml].
7743 - name : Scan licenses
78- uses :
aquasecurity/[email protected] 44+ uses : ./.github/actions/trivy
7945 env :
8046 TRIVY_DEBUG : true
47+ TRIVY_EXIT_CODE : 1
48+ TRIVY_SCANNERS : license
8149 with :
82- scan-type : filesystem
83- scanners : license
84- exit-code : 1
50+ cache : restore,use
8551
8652 vulnerabilities :
8753 if : ${{ github.repository == 'CrunchyData/postgres-operator' }}
@@ -97,21 +63,24 @@ jobs:
9763 # human consumption. This step fails only when Trivy is unable to scan.
9864 # A later step uploads results to GitHub as a pull request check.
9965 - name : Log detected vulnerabilities
100- uses :
aquasecurity/[email protected] 66+ uses : ./.github/actions/trivy
67+ env :
68+ TRIVY_SCANNERS : secret,vuln
10169 with :
102- scan-type : filesystem
103- scanners : secret,vuln
70+ cache : restore,use
10471
10572 # Produce a SARIF report of actionable results. This step fails only when
10673 # Trivy is unable to scan.
10774 - name : Report actionable vulnerabilities
108- uses :
aquasecurity/[email protected] 75+ uses : ./.github/actions/trivy
76+ env :
77+ TRIVY_IGNORE_UNFIXED : true
78+ TRIVY_FORMAT : ' sarif'
79+ TRIVY_OUTPUT : ' trivy-results.sarif'
80+ TRIVY_SCANNERS : secret,vuln
10981 with :
110- scan-type : filesystem
111- ignore-unfixed : true
112- format : ' sarif'
113- output : ' trivy-results.sarif'
114- scanners : secret,vuln
82+ cache : use
83+ setup : none
11584
11685 # Submit the SARIF report to GitHub code scanning. Pull requests checks
11786 # succeed or fail according to branch protection rules.
0 commit comments