Skip to content

Commit e523b1c

Browse files
authored
Replace github cache action with restore and save (#24)
### What Instead of letting `action/cache` do the restoring and saving cache for us, we choose when to restore and when to save cache. In this case, we will be saving cache immediately after the devbox package installation, instead of waiting for the action post run. This way, the `tar` sudo permission stays intact until the cache is saved. More specifically, `action/cache/save` runs before the last step of restoring `tar` to its original permission (as oppose to after)
1 parent 6b09349 commit e523b1c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

action.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ runs:
5353
- name: Mount devbox cli cache
5454
if: inputs.refresh-cli == 'false'
5555
id: cache-devbox-cli
56-
uses: actions/cache@v3
56+
uses: actions/cache/restore@v3
5757
with:
5858
path: /usr/local/bin/devbox
59-
key: ${{ runner.os }}-devbox-${{ env.latest_version }}
59+
key: ${{ runner.os }}-devbox-cli-${{ env.latest_version }}
6060

6161
- name: Install devbox cli
6262
if: steps.cache-devbox-cli.outputs.cache-hit != 'true'
@@ -94,6 +94,13 @@ runs:
9494
fi
9595
sudo mv "$DEVBOX_BINARY" /usr/local/bin/devbox
9696
97+
- name: Save devbox cli cache
98+
if: inputs.refresh-cli == 'false' && steps.cache-devbox-cli.outputs.cache-hit != 'true'
99+
uses: actions/cache/save@v3
100+
with:
101+
path: /usr/local/bin/devbox
102+
key: ${{ runner.os }}-devbox-cli-${{ env.latest_version }}
103+
97104
- name: Workaround nix store cache permission issue
98105
if: inputs.enable-cache == 'true'
99106
shell: bash
@@ -126,8 +133,9 @@ runs:
126133
extra-conf: experimental-features = ca-derivations fetch-closure
127134

128135
- name: Mount nix store cache
136+
id: cache-devbox-nix-store
129137
if: inputs.enable-cache == 'true'
130-
uses: actions/cache@v3
138+
uses: actions/cache/restore@v3
131139
with:
132140
path: |
133141
~/.cache/devbox
@@ -137,13 +145,27 @@ runs:
137145
~/.nix-profile
138146
/nix/store
139147
/nix/var/nix
140-
key: ${{ runner.os }}-devbox-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
148+
key: ${{ runner.os }}-devbox-nix-store-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
141149

142150
- name: Install devbox packages
143151
shell: bash
144152
run: |
145153
devbox run --config=${{ inputs.project-path }} -- echo "Packages installed!"
146154
155+
- name: Save nix store cache
156+
if: inputs.enable-cache == 'true' && steps.cache-devbox-nix-store.outputs.cache-hit != 'true'
157+
uses: actions/cache/save@v3
158+
with:
159+
path: |
160+
~/.cache/devbox
161+
~/.cache/nix
162+
~/.local/state/nix
163+
~/.nix-defexpr
164+
~/.nix-profile
165+
/nix/store
166+
/nix/var/nix
167+
key: ${{ runner.os }}-devbox-nix-store-${{ hashFiles(format('{0}/devbox.lock', inputs.project-path)) }}
168+
147169
- name: Restore tar command
148170
if: inputs.enable-cache == 'true'
149171
shell: bash

0 commit comments

Comments
 (0)