Skip to content

Commit

Permalink
ci: use actions/cache for restore/save cache, gh for deleting cache
Browse files Browse the repository at this point in the history
`actions/cache` does not allow for updating the cache, so we need to
delete the old cache and save a new one in order to keep reusing the
key.
  • Loading branch information
kwvg committed Nov 19, 2024
1 parent 25f92ee commit 00598f8
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,36 @@ jobs:
restore-keys: |
depends-sources-
- name: Cache dependencies
uses: actions/cache@v4
- name: Restore dependencies cache
id: cache-restore-deps
uses: actions/cache/restore@v4
with:
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}
restore-keys: |
${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}
${{ runner.os }}-depends-${{ matrix.depends_name }}

- name: Build dependencies
run: env HOST=${{ matrix.host }} ${{ matrix.dep_opts }} make -j$(nproc) -C depends

- name: Upload built depends
uses: actions/upload-artifact@v4
- name: Delete dependencies cache
id: cache-delete-deps
if: ${{ steps.cache-restore-deps.outputs.cache-hit }}
continue-on-error: true
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete "${{ steps.cache-restore-deps.outputs.cache-primary-key }}" --confirm
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Save dependencies cache
id: cache-save-deps
uses: actions/cache/save@v4
with:
name: depends-${{ matrix.depends_name }}
path: depends/${{ matrix.host }}
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ steps.cache-restore-deps.outputs.cache-primary-key }}

build:
name: ${{ matrix.build_target }}
Expand Down Expand Up @@ -157,11 +169,13 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Download built depends
uses: actions/download-artifact@v4
- name: Restore dependencies cache
uses: actions/cache/restore@v4
with:
name: depends-${{ matrix.depends_name }}
path: depends/${{ matrix.host }}
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}

- name: Determine PR Base SHA
id: vars
Expand Down

0 comments on commit 00598f8

Please sign in to comment.