Skip to content

Commit bd4a91e

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 1534331 commit bd4a91e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.github/actions/trivy/action.yaml

Lines changed: 8 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 or skip.
20+
1621
setup:
1722
default: v0.57.0,cache
1823
description: >-
@@ -67,6 +72,9 @@ runs:
6772
env:
6873
TRIVY_CACHE_DIR: >-
6974
${{ contains(fromJSON(steps.parsed.outputs.cache), 'use') && inputs.cache-directory || '' }}
75+
TRIVY_SKIP_CHECK_UPDATE: ${{ inputs.database == 'skip' }}
76+
TRIVY_SKIP_DB_UPDATE: ${{ inputs.database == 'skip' }}
77+
TRIVY_SKIP_JAVA_DB_UPDATE: ${{ inputs.database == 'skip' }}
7078
run: |
7179
# Run Trivy
7280
trivy '${{ inputs.scan-type }}' '${{ inputs.scan-target }}' || result=$?

.github/workflows/trivy.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ 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:
@@ -29,7 +31,11 @@ jobs:
2931
TRIVY_SCANNERS: license,secret,vuln
3032

3133
licenses:
34+
# Run this job after the cache job regardless of its success or failure.
3235
needs: [cache]
36+
if: >-
37+
${{ !cancelled() }}
38+
3339
runs-on: ubuntu-latest
3440
steps:
3541
- uses: actions/checkout@v4
@@ -48,13 +54,16 @@ jobs:
4854
TRIVY_SCANNERS: license
4955
with:
5056
cache: restore,use
57+
database: skip
5158

5259
vulnerabilities:
53-
if: ${{ github.repository == 'CrunchyData/postgres-operator' }}
60+
# Run this job after the cache job regardless of its success or failure.
61+
needs: [cache]
62+
if: >-
63+
${{ github.repository == 'CrunchyData/postgres-operator' && !cancelled() }}
5464
permissions:
5565
security-events: write
5666

57-
needs: [cache]
5867
runs-on: ubuntu-latest
5968
steps:
6069
- uses: actions/checkout@v4
@@ -68,6 +77,7 @@ jobs:
6877
TRIVY_SCANNERS: secret,vuln
6978
with:
7079
cache: restore,use
80+
database: skip
7181

7282
# Produce a SARIF report of actionable results. This step fails only when
7383
# Trivy is unable to scan.
@@ -80,6 +90,7 @@ jobs:
8090
TRIVY_SCANNERS: secret,vuln
8191
with:
8292
cache: use
93+
database: skip
8394
setup: none
8495

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

0 commit comments

Comments
 (0)