Skip to content

Commit 4d0a48a

Browse files
authored
Add nix version as part of the nix cache key (#65)
Sometimes nix ship backwards incompatible changes, which may result in devbox installation error. The following remedy is considered: - [x] Add `nix-version` as part of the Nix cache key - [x] Print out additional error message that prompts user to delete cache if needed Addresses #64 --------- Signed-off-by: Lucille Hua <[email protected]>
1 parent fed86d3 commit 4d0a48a

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

.github/workflows/test.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,31 @@ jobs:
2424
test-action:
2525
strategy:
2626
matrix:
27-
os: [macos-12, macos-13, macos-14, macos-latest, ubuntu-latest]
28-
use-cache: [true, false]
27+
os: [macos-13, macos-14, macos-latest, ubuntu-latest]
28+
enable-cache: ['true', 'false']
2929
runs-on: ${{ matrix.os }}
3030
steps:
3131
- uses: actions/checkout@v4
3232
- name: Install devbox
3333
uses: ./
3434
with:
3535
project-path: 'testdata'
36-
enable-cache: ${{ matrix.use-cache }}
36+
enable-cache: ${{ matrix.enable-cache }}
3737
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"
3838

39-
test-action-with-version:
39+
test-action-with-devbox-version:
4040
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
enable-cache: ['true', 'false']
4144
steps:
4245
- uses: actions/checkout@v4
4346
- name: Install devbox
4447
uses: ./
4548
with:
46-
devbox-version: 0.9.1
49+
devbox-version: 0.13.6
4750
project-path: 'testdata'
51+
enable-cache: ${{ matrix.enable-cache }}
4852
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"
4953

5054
test-action-with-sha256-checksum:
@@ -54,10 +58,10 @@ jobs:
5458
- name: Install devbox
5559
uses: ./
5660
with:
57-
devbox-version: 0.9.1
61+
devbox-version: 0.13.6
5862
refresh-cli: true
5963
project-path: 'testdata'
60-
sha256-checksum: 'f58202279237b9e0e7d69ef9334c7ca0628db31e5575f105dad6f41a171ebb6a'
64+
sha256-checksum: '22a31081df183aab7b8f88a794505c7c0ae217d6314e61b3e0bfe6972b992199'
6165
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"
6266

6367
test-action-with-sha256-checksum-failure:
@@ -69,7 +73,7 @@ jobs:
6973
uses: ./
7074
continue-on-error: true
7175
with:
72-
devbox-version: 0.9.1
76+
devbox-version: 0.13.6
7377
refresh-cli: true
7478
sha256-checksum: 'bad-sha'
7579
project-path: 'testdata'
@@ -85,8 +89,8 @@ jobs:
8589
- name: Install devbox
8690
uses: ./
8791
with:
88-
devbox-version: 0.9.1
92+
devbox-version: 0.13.6
8993
refresh-cli: true
90-
sha256-checksum: 'e7793acf6dadecc6a04eb64d6352665698c75f6c9f59fbe3efee3b04dbec294d'
94+
sha256-checksum: '169836de22c41a1c68ac5a43e0514d4021137647c7c08ee8bd921faa430ee286'
9195
project-path: 'testdata'
9296
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v3
1919
2020
- name: Install devbox
21-
uses: jetify-com/devbox-install-action@v0.11.0
21+
uses: jetify-com/devbox-install-action@v0.12.0
2222
2323
- name: Run arbitrary commands
2424
run: devbox run -- echo "done!"
@@ -47,7 +47,7 @@ Here's an example job with all inputs:
4747

4848
```
4949
- name: Install devbox
50-
uses: jetify-com/devbox-install-action@v0.11.0
50+
uses: jetify-com/devbox-install-action@v0.12.0
5151
with:
5252
project-path: 'path-to-folder'
5353
enable-cache: 'true'

action.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ runs:
100100
if: inputs.refresh-cli == 'false' && steps.cache-devbox-cli.outputs.cache-hit != 'true'
101101
uses: actions/cache/save@v4
102102
with:
103-
path: ~/.local/bin/devbox
103+
path: |
104+
~/.local/bin/devbox
105+
/usr/local/bin/devbox
104106
key: ${{ runner.os }}-${{ runner.arch }}-devbox-cli-${{ env.latest_version }}
105107

106108
- name: Workaround nix store cache permission issue
@@ -135,6 +137,13 @@ runs:
135137
logger: pretty
136138
extra-conf: experimental-features = ca-derivations fetch-closure
137139

140+
- name: Get nix version
141+
shell: bash
142+
run: |
143+
NIX_VERSION_OUTPUT=$(nix --version)
144+
NIX_VERSION=$(echo "${NIX_VERSION_OUTPUT}" | awk '{print $NF}')
145+
echo "nix-version=$NIX_VERSION" >> $GITHUB_ENV
146+
138147
- name: Mount nix store cache
139148
id: cache-devbox-nix-store
140149
if: inputs.enable-cache == 'true'
@@ -148,12 +157,21 @@ runs:
148157
~/.nix-profile
149158
/nix/store
150159
/nix/var/nix
151-
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
160+
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ env.nix-version }}-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
152161

153162
- name: Install devbox packages
154163
shell: bash
155164
run: |
156165
devbox run --config=${{ inputs.project-path }} -- echo "Packages installed!"
166+
167+
- name: List nix store cache on failure
168+
shell: bash
169+
if: failure()
170+
env:
171+
GH_TOKEN: ${{ github.token }}
172+
run: |
173+
echo "It is likely that nix has shipped a backwards incompatible change. Proceed to the actions tab and manually delete the following cache objects:"
174+
gh cache list --key ${{ runner.os }}-${{ runner.arch }}-devbox --json key
157175
158176
- name: Save nix store cache
159177
if: inputs.enable-cache == 'true' && steps.cache-devbox-nix-store.outputs.cache-hit != 'true'
@@ -167,7 +185,7 @@ runs:
167185
~/.nix-profile
168186
/nix/store
169187
/nix/var/nix
170-
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
188+
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ env.nix-version }}-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
171189

172190
- name: Restore tar command
173191
if: inputs.enable-cache == 'true'

0 commit comments

Comments
 (0)