1
+ # Copyright 2024 - 2025 Crunchy Data Solutions, Inc.
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ #
5
+ # schema documentation: https://docs.github.com/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions
6
+ # yaml-language-server: $schema=https://json.schemastore.org/github-action.json
7
+
1
8
name : Trivy
2
9
description : Scan this project using Trivy
3
10
4
11
# The Trivy team maintains an action, but it has trouble caching its vulnerability data:
5
12
# https://github.com/aquasecurity/trivy-action/issues/389
6
13
#
14
+ # 1. It caches vulnerability data once per calendar day, despite Trivy wanting
15
+ # to download more frequently than that.
16
+ # 2. When it fails to download the data, it fails the workflow *and* caches
17
+ # the incomplete data.
18
+ # 3. When (1) and (2) coincide, every following run that day *must* update the data,
19
+ # producing more opportunities for (2) and more failed workflows.
20
+ #
7
21
# The action below uses any recent cache matching `cache-prefix` and calculates a cache key
8
- # derived from the data Trivy downloads.
22
+ # derived from the data Trivy downloads. An older database is better than no scans at all.
23
+ # When a run successfully updates the data, that data is cached and available to other runs.
9
24
10
25
inputs :
11
26
cache :
12
27
default : restore,success,use
13
28
description : >-
14
29
What Trivy data to cache; one or more of restore, save, success, or use.
30
+ The value "use" instructs Trivy to read and write to its cache.
31
+ The value "restore" loads the Trivy cache from GitHub.
32
+ The value "success" saves the Trivy cache to GitHub when Trivy succeeds.
33
+ The value "save" saves the Trivy cache to GitHub regardless of Trivy.
15
34
16
35
database :
17
36
default : update
18
37
description : >-
19
38
How Trivy should handle its data; one of update or skip.
39
+ The value "skip" fetches no Trivy data at all.
20
40
21
41
setup :
22
- default : v0.57 .1,cache
42
+ default : v0.62 .1,cache
23
43
description : >-
24
44
How to install Trivy; one or more of version, none, or cache.
45
+ The value "none" does not install Trivy at all.
25
46
26
47
cache-directory :
27
48
default : ${{ github.workspace }}/.cache/trivy
49
+ description : >-
50
+ Directory where Trivy should store its data
28
51
29
52
cache-prefix :
30
53
default : cache-trivy
54
+ description : >-
55
+ Name (key) where Trivy data should be stored in the GitHub cache
31
56
32
57
scan-target :
33
58
default : .
59
+ description : >-
60
+ What Trivy should scan
34
61
35
62
scan-type :
36
- default : filesystem
63
+ default : repository
64
+ description : >-
65
+ How Trivy should interpret scan-target; one of filesystem, image, repository, or sbom.
37
66
38
67
runs :
39
68
using : composite
50
79
"setup=\(split("[,\\s]+"; "") - [""])",
51
80
"version=\(split("[,\\s]+"; "") | max_by(split("[v.]"; "") | map(tonumber?)))"
52
81
'
53
- ) | tee --append $ GITHUB_OUTPUT
82
+ ) | tee --append "${ GITHUB_OUTPUT}"
54
83
55
84
# Install Trivy as requested.
85
+ # NOTE: `setup-trivy` can download a "latest" version but cannot cache it.
56
86
- if : ${{ ! contains(fromJSON(steps.parsed.outputs.setup), 'none') }}
57
87
uses : aquasecurity/setup-trivy@v0.2.3
58
88
with :
@@ -75,12 +105,13 @@ runs:
75
105
TRIVY_SKIP_CHECK_UPDATE : ${{ inputs.database == 'skip' }}
76
106
TRIVY_SKIP_DB_UPDATE : ${{ inputs.database == 'skip' }}
77
107
TRIVY_SKIP_JAVA_DB_UPDATE : ${{ inputs.database == 'skip' }}
108
+ TRIVY_SKIP_VEX_REPO_UPDATE : ${{ inputs.database == 'skip' }}
78
109
run : |
79
110
# Run Trivy
80
111
trivy '${{ inputs.scan-type }}' '${{ inputs.scan-target }}' || result=$?
81
112
82
113
checksum=$([[ -z "${TRIVY_CACHE_DIR}" ]] || cat "${TRIVY_CACHE_DIR}/"*/metadata.json | sha256sum)
83
- echo 'cache-key=${{ inputs.cache-prefix }}-'"${checksum%% *}" >> $ GITHUB_OUTPUT
114
+ echo 'cache-key=${{ inputs.cache-prefix }}-'"${checksum%% *}" >> "${ GITHUB_OUTPUT}"
84
115
85
116
exit "${result-0}"
86
117
0 commit comments