Skip to content

Commit 0121f86

Browse files
committed
Continue the Trivy workflow when its data download fails
Later steps will use data from the action cache and ignore its age. The workflow fails when the download fails and the cache is empty. Issue: PGO-1893
1 parent 2c3d3d0 commit 0121f86

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

.github/actions/trivy/action.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ inputs:
1313
description: >-
1414
What Trivy data to cache; one or more of restore, save, success, or use.
1515
16+
database:
17+
default: update
18+
description: >-
19+
How Trivy should handle its data; one of update, only, or skip.
20+
1621
setup:
1722
default: v0.57.0,cache
1823
description: >-
@@ -67,6 +72,11 @@ runs:
6772
env:
6873
TRIVY_CACHE_DIR: >-
6974
${{ contains(fromJSON(steps.parsed.outputs.cache), 'use') && inputs.cache-directory || '' }}
75+
TRIVY_DB_DOWNLOAD_ONLY: ${{ inputs.database == 'only' }}
76+
TRIVY_DB_SKIP_UPDATE: ${{ inputs.database == 'skip' }}
77+
TRIVY_DB_DOWNLOAD_JAVA_ONLY: ${{ inputs.database == 'only' }}
78+
TRIVY_DB_JAVA_SKIP_UPDATE: ${{ inputs.database == 'skip' }}
79+
TRIVY_REGO_SKIP_CHECK_UPDATE: ${{ inputs.database == 'skip' }}
7080
run: |
7181
# Run Trivy
7282
trivy '${{ inputs.scan-type }}' '${{ inputs.scan-target }}' || result=$?

.github/workflows/trivy.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@ jobs:
1616
cache:
1717
# Run only one of these jobs at a time across the entire project.
1818
concurrency: { group: trivy-cache }
19+
# Do not fail this workflow when this job fails.
20+
continue-on-error: true
1921

2022
runs-on: ubuntu-latest
2123
steps:
2224
- uses: actions/checkout@v4
2325
- uses: ./.github/actions/trivy
2426
env:
25-
TRIVY_DB_DOWNLOAD_ONLY: true
2627
TRIVY_DB_NO_PROGRESS: true
2728
TRIVY_SCANNERS: license,secret,vuln
29+
with:
30+
database: only
2831

2932
licenses:
33+
# Run this job after the cache job regardless of its success or failure.
3034
needs: [cache]
35+
if: >-
36+
${{ !cancelled() }}
37+
3138
runs-on: ubuntu-latest
3239
steps:
3340
- uses: actions/checkout@v4
@@ -46,13 +53,16 @@ jobs:
4653
TRIVY_SCANNERS: license
4754
with:
4855
cache: restore,use
56+
database: skip
4957

5058
vulnerabilities:
51-
if: ${{ github.repository == 'CrunchyData/postgres-operator' }}
59+
# Run this job after the cache job regardless of its success or failure.
60+
needs: [cache]
61+
if: >-
62+
${{ github.repository == 'CrunchyData/postgres-operator' && !cancelled() }}
5263
permissions:
5364
security-events: write
5465

55-
needs: [cache]
5666
runs-on: ubuntu-latest
5767
steps:
5868
- uses: actions/checkout@v4
@@ -66,6 +76,7 @@ jobs:
6676
TRIVY_SCANNERS: secret,vuln
6777
with:
6878
cache: restore,use
79+
database: skip
6980

7081
# Produce a SARIF report of actionable results. This step fails only when
7182
# Trivy is unable to scan.
@@ -78,6 +89,7 @@ jobs:
7889
TRIVY_SCANNERS: secret,vuln
7990
with:
8091
cache: use
92+
database: skip
8193
setup: none
8294

8395
# Submit the SARIF report to GitHub code scanning. Pull requests checks

0 commit comments

Comments
 (0)