Skip to content

Commit cb83f40

Browse files
authored
ci: fix vercel gha, and correct the way node_modules are cached (#2230)
1 parent 2634313 commit cb83f40

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ jobs:
2626
with:
2727
node-version-file: ".nvmrc"
2828

29+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
30+
- name: Get npm cache directory
31+
id: npm-cache-dir
32+
shell: bash
33+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
34+
2935
- name: Cache node modules
3036
uses: actions/cache@v4
31-
env:
32-
cache-name: cache-node-modules
37+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
3338
with:
34-
path: |
35-
~/.npm
36-
**/node_modules
37-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
39+
path: ${{ steps.npm-cache-dir.outputs.dir }}
40+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
3841
restore-keys: |
39-
${{ runner.os }}-build-${{ env.cache-name }}-
40-
${{ runner.os }}-build-
41-
${{ runner.os }}-
42+
${{ runner.os }}-node-
4243
4344
- name: Install deps
4445
run: npm ci --audit=false
@@ -75,19 +76,20 @@ jobs:
7576
with:
7677
node-version-file: ".nvmrc"
7778

79+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
80+
- name: Get npm cache directory
81+
id: npm-cache-dir
82+
shell: bash
83+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
84+
7885
- name: Cache node modules
7986
uses: actions/cache@v4
80-
env:
81-
cache-name: cache-node-modules
87+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
8288
with:
83-
path: |
84-
~/.npm
85-
**/node_modules
86-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
89+
path: ${{ steps.npm-cache-dir.outputs.dir }}
90+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
8791
restore-keys: |
88-
${{ runner.os }}-build-${{ env.cache-name }}-
89-
${{ runner.os }}-build-
90-
${{ runner.os }}-
92+
${{ runner.os }}-node-
9193
9294
- name: Install deps
9395
run: npm ci --audit=false
@@ -157,19 +159,20 @@ jobs:
157159
with:
158160
node-version-file: ".nvmrc"
159161

162+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
163+
- name: Get npm cache directory
164+
id: npm-cache-dir
165+
shell: bash
166+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
167+
160168
- name: Cache node modules
161169
uses: actions/cache@v4
162-
env:
163-
cache-name: cache-node-modules
170+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
164171
with:
165-
path: |
166-
~/.npm
167-
**/node_modules
168-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
172+
path: ${{ steps.npm-cache-dir.outputs.dir }}
173+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
169174
restore-keys: |
170-
${{ runner.os }}-build-${{ env.cache-name }}-
171-
${{ runner.os }}-build-
172-
${{ runner.os }}-
175+
${{ runner.os }}-node-
173176
174177
- name: Install deps
175178
run: npm ci --audit=false
@@ -220,19 +223,20 @@ jobs:
220223
with:
221224
node-version-file: ".nvmrc"
222225

226+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
227+
- name: Get npm cache directory
228+
id: npm-cache-dir
229+
shell: bash
230+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
231+
223232
- name: Cache node modules
224233
uses: actions/cache@v4
225-
env:
226-
cache-name: cache-node-modules
234+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
227235
with:
228-
path: |
229-
~/.npm
230-
**/node_modules
231-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
236+
path: ${{ steps.npm-cache-dir.outputs.dir }}
237+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
232238
restore-keys: |
233-
${{ runner.os }}-build-${{ env.cache-name }}-
234-
${{ runner.os }}-build-
235-
${{ runner.os }}-
239+
${{ runner.os }}-node-
236240
237241
- name: Install deps
238242
run: npm ci --audit=false

.github/workflows/vercel.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@ jobs:
2020
url: ${{ github.ref_name == 'master' && 'https://stacks-blockchain-api.vercel.app/' || 'https://stacks-blockchain-api-pbcblockstack-blockstack.vercel.app/' }}
2121

2222
steps:
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v4
2424
with:
2525
fetch-depth: 0
2626

2727
- name: Use Node.js
28-
uses: actions/setup-node@v2
28+
uses: actions/setup-node@v4
2929
with:
3030
node-version-file: '.nvmrc'
3131

32+
# https://github.com/actions/cache/blob/main/examples.md#node---npm
33+
- name: Get npm cache directory
34+
id: npm-cache-dir
35+
shell: bash
36+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
37+
3238
- name: Cache node modules
33-
uses: actions/cache@v2
34-
env:
35-
cache-name: cache-node-modules
39+
uses: actions/cache@v4
40+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
3641
with:
37-
path: |
38-
~/.npm
39-
**/node_modules
40-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
42+
path: ${{ steps.npm-cache-dir.outputs.dir }}
43+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
4144
restore-keys: |
42-
${{ runner.os }}-build-${{ env.cache-name }}-
43-
${{ runner.os }}-build-
44-
${{ runner.os }}-
45+
${{ runner.os }}-node-
4546
4647
- name: Install deps
4748
run: npm ci --audit=false

0 commit comments

Comments
 (0)