Update Trivy Cache #413
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Trivy Cache | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Run daily at midnight UTC | |
| workflow_dispatch: | |
| permissions: read-all | |
| jobs: | |
| update-trivy-db: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.ref_name == github.event.repository.default_branch }} | |
| steps: | |
| - name: Setup oras | |
| uses: oras-project/setup-oras@22ce207df3b08e061f537244349aac6ae1d214f6 # v1.2.4 | |
| - name: Get current date | |
| id: date | |
| run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
| - name: Prepare DB directory | |
| run: | | |
| mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db | |
| - name: Download vulnerability database | |
| uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2 | |
| with: | |
| max_attempts: 60 | |
| retry_on: error | |
| timeout_seconds: 30 | |
| retry_wait_seconds: 60 | |
| command: | | |
| oras pull ghcr.io/aquasecurity/trivy-db:2 | |
| tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db | |
| rm db.tar.gz | |
| - name: Cache DBs | |
| uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| with: | |
| path: ${{ github.workspace }}/.cache/trivy | |
| key: cache-trivy-${{ steps.date.outputs.date }} |