Skip to content

Commit

Permalink
fix(ci): don't save a cache on hit
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed May 2, 2024
1 parent c895115 commit 1d257c1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/buildjet-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,14 @@ jobs:
- uses: nixbuild/nix-quick-install-action@v28

- name: Restore and save Nix store - ${{ matrix.id }}
uses: ./.
- name: Restore Nix store - ${{ matrix.id }}
id: restore
uses: ./restore
with:
# save a new cache every time `ci.yaml` changes
primary-key: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-${{ hashFiles('.github/workflows/ci.yaml') }}
# otherwise, restore a common cache if and only if it matches the current `ci.yaml`
restore-prefixes-first-match: similar-cache-${{ matrix.os }}-common-${{ hashFiles('.github/workflows/ci.yaml') }}
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never
# use BuildJet backend
backend: buildjet

- name: Pin nixpkgs
run: ${{ env.pin_nixpkgs }}
Expand All @@ -131,6 +122,23 @@ jobs:
if: ${{ matrix.id == 2 }}
run: nix profile install nixpkgs#nodejs

- name: Save Nix store - ${{ matrix.id }}
if: steps.restore.outputs.hit == 'false'
uses: ./save
with:
# save a new cache every time `ci.yaml` changes
primary-key: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-${{ hashFiles('.github/workflows/ci.yaml') }}
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never
# use BuildJet backend
backend: buildjet

# Merge similar `individual` caches
# Purge `individual` caches and old `common` caches
# Save new `common` caches
Expand Down
28 changes: 18 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,14 @@ jobs:
- uses: nixbuild/nix-quick-install-action@v28

- name: Restore and save Nix store - ${{ matrix.id }}
uses: ./.
- name: Restore Nix store - ${{ matrix.id }}
id: restore
uses: ./restore
with:
# save a new cache every time `ci.yaml` changes
primary-key: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-${{ hashFiles('.github/workflows/ci.yaml') }}
# otherwise, restore a common cache if and only if it matches the current `ci.yaml`
restore-prefixes-first-match: similar-cache-${{ matrix.os }}-common-${{ hashFiles('.github/workflows/ci.yaml') }}
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never

- name: Pin nixpkgs
run: ${{ env.pin_nixpkgs }}
Expand All @@ -137,6 +130,21 @@ jobs:
if: ${{ matrix.id == 2 }}
run: nix profile install nixpkgs#nodejs

- name: Save Nix store - ${{ matrix.id }}
if: steps.restore.outputs.hit == 'false'
uses: ./save
with:
# save a new cache every time `ci.yaml` changes
primary-key: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-${{ hashFiles('.github/workflows/ci.yaml') }}
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: similar-cache-${{ matrix.os }}-individual-${{ matrix.id }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never

# Merge similar `individual` caches
# Purge `individual` caches and old `common` caches
# Save new `common` caches
Expand Down
30 changes: 19 additions & 11 deletions nix/ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,14 @@ in
${indent 6 nix-quick-install-action}
- name: Restore and save Nix store - ''${{ matrix.id }}
uses: ./.
- name: Restore Nix store - ''${{ matrix.id }}
id: restore
uses: ./restore
with:
# save a new cache every time `ci.yaml` changes
primary-key: similar-cache-''${{ matrix.os }}-individual-''${{ matrix.id }}-''${{ hashFiles('.github/workflows/ci.yaml') }}
# otherwise, restore a common cache if and only if it matches the current `ci.yaml`
restore-prefixes-first-match: similar-cache-''${{ matrix.os }}-common-''${{ hashFiles('.github/workflows/ci.yaml') }}
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: similar-cache-''${{ matrix.os }}-individual-''${{ matrix.id }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never
${indent 10 backend_}
- name: Pin nixpkgs
run: ''${{ env.pin_nixpkgs }}
Expand All @@ -170,6 +162,22 @@ in
- name: Install nixpkgs#nodejs
if: ''${{ matrix.id == 2 }}
run: nix profile install nixpkgs#nodejs
- name: Save Nix store - ''${{ matrix.id }}
if: steps.restore.outputs.hit == 'false'
uses: ./save
with:
# save a new cache every time `ci.yaml` changes
primary-key: similar-cache-''${{ matrix.os }}-individual-''${{ matrix.id }}-''${{ hashFiles('.github/workflows/ci.yaml') }}
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: similar-cache-''${{ matrix.os }}-individual-''${{ matrix.id }}-
# created more than 0 seconds ago relative to the start of the `Post Restore` phase
purge-created: 0
# except the version with the `primary-key`, if it exists
purge-primary-key: never
${indent 10 backend_}
''
+ (
let
Expand Down

0 comments on commit 1d257c1

Please sign in to comment.