Skip to content

Commit 380e478

Browse files
committed
chore: refine cache keys
1 parent 56334fa commit 380e478

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

.github/actions/npm-setup/action.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@ runs:
1616
uses: actions/setup-node@v4
1717
with:
1818
node-version: ${{ inputs.node-version }}
19-
- name: Get npm cache directory
20-
id: npm-cache-dir
21-
shell: bash
22-
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
2319
- uses: actions/cache/restore@v4
24-
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
20+
id: npm-cache
2521
with:
26-
path: ${{ steps.npm-cache-dir.outputs.dir }}
27-
key: ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ hashFiles('**/package-lock.json') }}
22+
path: node_modules
23+
key: ${{ github.head_ref || 'main' }}-${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ hashFiles('**/package-lock.json') }}
2824
restore-keys: |
29-
${{ inputs.runner }}-node-${{ inputs.node-version }}-
25+
${{ github.head_ref || 'main' }}-${{ inputs.runner }}-node-${{ inputs.node-version }}-
3026
- name: Install dependencies
27+
if: steps.npm-cache.outputs.cache-hit != 'true'
3128
shell: bash
3229
run: npm ci --omit=optional
3330
- name: Cache npm
3431
id: cache-npm-save
32+
if: steps.npm-cache.outputs.cache-hit != 'true'
3533
uses: actions/cache/save@v4
3634
with:
37-
path: ${{ steps.npm-cache-dir.outputs.dir }}
35+
path: node_modules
3836
key: ${{ steps.npm-cache.outputs.cache-primary-key }}

0 commit comments

Comments
 (0)