Skip to content

Commit bf9551d

Browse files
add a new action for trivy's cache (#64)
1 parent 4b80446 commit bf9551d

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

trivy-update-cache/action.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
---
3+
name: 'Trivy Cache Update'
4+
description: 'Composite action to run download the trivy cache'
5+
6+
# See https://github.com/aquasecurity/trivy-action#updating-caches-in-the-default-branch
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Checkout tools repo
11+
uses: actions/checkout@v4
12+
with:
13+
repository: Consensys/docs-gha
14+
path: .docs-gha
15+
16+
- name: Get current date
17+
id: date
18+
shell: sh
19+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
20+
21+
# May need to use https://github.com/marketplace/actions/retry-step to retry
22+
- name: Download and extract the vulnerability DB
23+
shell: sh
24+
run: |
25+
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db
26+
oras pull ghcr.io/aquasecurity/trivy-db:2
27+
tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
28+
rm db.tar.gz
29+
30+
- name: Download and extract the Java DB
31+
shell: sh
32+
run: |
33+
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
34+
oras pull ghcr.io/aquasecurity/trivy-java-db:1
35+
tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db
36+
rm javadb.tar.gz
37+
38+
- name: Cache DBs
39+
uses: actions/cache/save@v4
40+
with:
41+
path: ${{ github.workspace }}/.cache/trivy
42+
key: cache-trivy-${{ steps.date.outputs.date }}
43+

trivy/action.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
name: 'Trivy'
44
description: 'Composite action to run trivy on the npm package.json'
55

6+
7+
inputs:
8+
TRIVY_SKIP_DB_UPDATE:
9+
description: "Whether trivy should use cache instead of pulling latest db"
10+
required: false
11+
default: true
12+
TRIVY_SKIP_JAVA_DB_UPDATE:
13+
description: "Whether trivy should use cache instead of pulling latest java db"
14+
required: false
15+
default: true
16+
617
runs:
718
using: "composite"
819
steps:
@@ -12,15 +23,20 @@ runs:
1223
repository: Consensys/docs-gha
1324
path: .docs-gha
1425

15-
# 0.23.0
26+
# 0.28.0
27+
# Refer to https://github.com/aquasecurity/trivy-action#updating-caches-in-the-default-branch for the env vars
1628
- name: Run Trivy vulnerability scanner
17-
uses: aquasecurity/trivy-action@6e7b7d1fd3e4fef0c5fa8cce1229c54b2c9bd0d8
29+
uses: aquasecurity/trivy-action@915b19bbe73b92a6cf82a1bc12b087c9a19a5fe2
1830
with:
1931
scan-type: 'fs'
2032
ignore-unfixed: true
2133
format: 'sarif'
2234
output: 'trivy-results.sarif'
2335
severity: 'CRITICAL'
36+
cache: 'true'
37+
env:
38+
TRIVY_SKIP_DB_UPDATE: ${{ inputs.TRIVY_SKIP_DB_UPDATE && inputs.TRIVY_SKIP_DB_UPDATE != 'false' }}
39+
TRIVY_SKIP_JAVA_DB_UPDATE: ${{ inputs.TRIVY_SKIP_JAVA_DB_UPDATE && inputs.TRIVY_SKIP_JAVA_DB_UPDATE != 'false' }}
2440

2541
- name: Upload Trivy scan results to GitHub Security tab
2642
uses: github/codeql-action/upload-sarif@v3

0 commit comments

Comments
 (0)