From 4d0a48ad242ace99949e9cbfdaa08137d751b05b Mon Sep 17 00:00:00 2001 From: Lucille Hua Date: Wed, 22 Jan 2025 12:59:53 -0500 Subject: [PATCH] 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 https://github.com/jetify-com/devbox-install-action/issues/64 --------- Signed-off-by: Lucille Hua --- .github/workflows/test.yaml | 24 ++++++++++++++---------- README.md | 4 ++-- action.yml | 24 +++++++++++++++++++++--- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 295bff1..6e5259f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,8 +24,8 @@ 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 @@ -33,18 +33,22 @@ jobs: 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: @@ -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: @@ -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' @@ -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' }}" diff --git a/README.md b/README.md index 8189e06..a1c8d01 100644 --- a/README.md +++ b/README.md @@ -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!" @@ -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' diff --git a/action.yml b/action.yml index 16515d0..82affe3 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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' @@ -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' @@ -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'