Skip to content

Commit

Permalink
Add nix version as part of the nix cache key (#65)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
LucilleH authored Jan 22, 2025
1 parent fed86d3 commit 4d0a48a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,31 @@ jobs:
test-action:
strategy:
matrix:
os: [macos-12, macos-13, macos-14, macos-latest, ubuntu-latest]
use-cache: [true, false]
os: [macos-13, macos-14, macos-latest, ubuntu-latest]
enable-cache: ['true', 'false']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install devbox
uses: ./
with:
project-path: 'testdata'
enable-cache: ${{ matrix.use-cache }}
enable-cache: ${{ matrix.enable-cache }}
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"

test-action-with-version:
test-action-with-devbox-version:
runs-on: ubuntu-latest
strategy:
matrix:
enable-cache: ['true', 'false']
steps:
- uses: actions/checkout@v4
- name: Install devbox
uses: ./
with:
devbox-version: 0.9.1
devbox-version: 0.13.6
project-path: 'testdata'
enable-cache: ${{ matrix.enable-cache }}
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"

test-action-with-sha256-checksum:
Expand All @@ -54,10 +58,10 @@ jobs:
- name: Install devbox
uses: ./
with:
devbox-version: 0.9.1
devbox-version: 0.13.6
refresh-cli: true
project-path: 'testdata'
sha256-checksum: 'f58202279237b9e0e7d69ef9334c7ca0628db31e5575f105dad6f41a171ebb6a'
sha256-checksum: '22a31081df183aab7b8f88a794505c7c0ae217d6314e61b3e0bfe6972b992199'
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"

test-action-with-sha256-checksum-failure:
Expand All @@ -69,7 +73,7 @@ jobs:
uses: ./
continue-on-error: true
with:
devbox-version: 0.9.1
devbox-version: 0.13.6
refresh-cli: true
sha256-checksum: 'bad-sha'
project-path: 'testdata'
Expand All @@ -85,8 +89,8 @@ jobs:
- name: Install devbox
uses: ./
with:
devbox-version: 0.9.1
devbox-version: 0.13.6
refresh-cli: true
sha256-checksum: 'e7793acf6dadecc6a04eb64d6352665698c75f6c9f59fbe3efee3b04dbec294d'
sha256-checksum: '169836de22c41a1c68ac5a43e0514d4021137647c7c08ee8bd921faa430ee286'
project-path: 'testdata'
disable-nix-access-token: "${{ github.ref != 'refs/heads/main' }}"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install devbox
uses: jetify-com/devbox-install-action@v0.11.0
uses: jetify-com/devbox-install-action@v0.12.0
- name: Run arbitrary commands
run: devbox run -- echo "done!"
Expand Down Expand Up @@ -47,7 +47,7 @@ Here's an example job with all inputs:

```
- name: Install devbox
uses: jetify-com/devbox-install-action@v0.11.0
uses: jetify-com/devbox-install-action@v0.12.0
with:
project-path: 'path-to-folder'
enable-cache: 'true'
Expand Down
24 changes: 21 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ runs:
if: inputs.refresh-cli == 'false' && steps.cache-devbox-cli.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ~/.local/bin/devbox
path: |
~/.local/bin/devbox
/usr/local/bin/devbox
key: ${{ runner.os }}-${{ runner.arch }}-devbox-cli-${{ env.latest_version }}

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

- name: Get nix version
shell: bash
run: |
NIX_VERSION_OUTPUT=$(nix --version)
NIX_VERSION=$(echo "${NIX_VERSION_OUTPUT}" | awk '{print $NF}')
echo "nix-version=$NIX_VERSION" >> $GITHUB_ENV
- name: Mount nix store cache
id: cache-devbox-nix-store
if: inputs.enable-cache == 'true'
Expand All @@ -148,12 +157,21 @@ runs:
~/.nix-profile
/nix/store
/nix/var/nix
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
key: ${{ runner.os }}-${{ runner.arch }}-devbox-nix-store-${{ env.nix-version }}-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}

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

- name: Restore tar command
if: inputs.enable-cache == 'true'
Expand Down

0 comments on commit 4d0a48a

Please sign in to comment.