Skip to content

Commit 23f1445

Browse files
committed
fix: configure cache paths correctly
1 parent dabcce6 commit 23f1445

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,42 @@ runs:
1919
uses: actions/setup-node@v4
2020
with:
2121
node-version: ${{ inputs.node-version }}
22+
23+
- name: Set cache configuration
24+
shell: bash
25+
run: |
26+
if [ "${{ inputs.workspace }}" = "testcontainers" ]; then
27+
echo CACHE_PATHS<<EOF >> $GITHUB_ENV
28+
echo node_modules >> $GITHUB_ENV
29+
echo packages/testcontainers/node_modules >> $GITHUB_ENV
30+
echo EOF >> $GITHUB_ENV
31+
echo HASH_PATHS="'package-lock.json','packages/testcontainers/package-lock.json'" >> $GITHUB_ENV
32+
else
33+
echo CACHE_PATHS<<EOF >> $GITHUB_ENV
34+
echo node_modules >> $GITHUB_ENV
35+
echo packages/testcontainers/node_modules >> $GITHUB_ENV
36+
echo packages/modules/${{ inputs.workspace }}/node_modules >> $GITHUB_ENV
37+
echo EOF >> $GITHUB_ENV
38+
echo HASH_PATHS="'package-lock.json','packages/testcontainers/package-lock.json','packages/modules/${{ inputs.workspace }}/package-lock.json'" >> $GITHUB_ENV
39+
fi
40+
2241
- uses: actions/cache/restore@v4
2342
id: npm-cache
2443
with:
25-
path: node_modules
26-
# the key is built using both package-lock.json files: the one in the root dir and the one for the module to be built
27-
key: ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}-${{ hashFiles(format('{0}-{1}/{2}', 'package-lock.json', inputs.workspace, 'package-lock.json')) }}
44+
path: ${{ env.CACHE_PATHS }}
45+
key: ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}-${{ hashFiles(env.HASH_PATHS) }}
2846
restore-keys: |
2947
${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}-
48+
${{ inputs.runner }}-node-${{ inputs.node-version }}-
49+
3050
- name: Install dependencies
3151
if: steps.npm-cache.outputs.cache-hit != 'true'
3252
shell: bash
33-
run: npm ci --omit=optional -- ${{ inputs.workspace }}
53+
run: npm ci --workspace ${{ inputs.workspace }} --include-workspace-root
54+
3455
- name: Cache npm
35-
id: cache-npm-save
3656
if: steps.npm-cache.outputs.cache-hit != 'true'
3757
uses: actions/cache/save@v4
3858
with:
39-
path: |
40-
node_modules
41-
${{ inputs.workspace }}/node_modules
59+
path: ${{ env.CACHE_PATHS }}
4260
key: ${{ steps.npm-cache.outputs.cache-primary-key }}

0 commit comments

Comments
 (0)