Skip to content

Commit b8a71d9

Browse files
authored
chore: optimize CI caching (#2183)
1 parent 951c7bd commit b8a71d9

10 files changed

+114
-163
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,10 @@ jobs:
99
- uses: actions/[email protected]
1010

1111
- name: Setup node
12-
uses: actions/setup-node@v3.6.0
12+
uses: actions/setup-node@v4
1313
with:
1414
node-version: 18.14.0
15-
16-
- name: Cache bigger downloads
17-
uses: actions/[email protected]
18-
id: cache
19-
with:
20-
path: ${{ github.workspace }}/.cache
21-
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
22-
restore-keys: |
23-
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
24-
${{ runner.os }}-
15+
cache: 'npm'
2516

2617
# Separate cache for build dir, we reuse it in release publish workflow
2718
- name: Cache build output
@@ -37,7 +28,7 @@ jobs:
3728
- name: Install dependencies
3829
# We only need to install deps if build isn't cached.
3930
if: steps.build-cache.outputs.cache-hit != 'true'
40-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
31+
run: npm ci --prefer-offline --no-audit --progress=false
4132

4233
- name: Confirm build works
4334
if: steps.build-cache.outputs.cache-hit != 'true'
@@ -47,6 +38,8 @@ jobs:
4738
# - this is not for releases, but for quick testing during the dev
4839
# - action artifacts can be downloaded for 90 days, then are removed by github
4940
- name: Attach produced build to Github Action
41+
# only re-upload if we re-built
42+
if: steps.build-cache.outputs.cache-hit != 'true'
5043
uses: actions/upload-artifact@v3
5144
with:
5245
name: ipfs-webui_${{ github.sha }}-${{ runner.os }}-build

.github/workflows/ci.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,20 @@ jobs:
3333
- uses: actions/[email protected]
3434

3535
- name: Setup node
36-
uses: actions/setup-node@v3.6.0
36+
uses: actions/setup-node@v4
3737
with:
3838
node-version: 18.14.0
39+
cache: 'npm'
3940

40-
- name: Download build artifact
41-
uses: actions/download-artifact@v3
41+
- name: Cache build output
42+
uses: actions/[email protected]
43+
id: build-cache
4244
with:
43-
name: ipfs-webui_${{ github.sha }}-${{ runner.os }}-build
4445
path: build
46+
# Build hash should be based on runner.os, src files, and dependencies used.
47+
key: ${{ runner.os }}-build-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', '*.js', '*.ts') }}
48+
restore-keys: |
49+
${{ runner.os }}-build-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', '*.js', '*.ts') }}
4550
4651
- name: Cache bigger downloads
4752
uses: actions/[email protected]
@@ -232,12 +237,13 @@ jobs:
232237
echo ${{ needs.publishPreview.outputs.cid }} > .cid
233238
234239
- name: Setup node
235-
uses: actions/setup-node@v3.6.0
240+
uses: actions/setup-node@v4
236241
with:
237242
node-version: 18.14.0
243+
cache: 'npm'
238244

239245
- name: Install dependencies
240-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
246+
run: npm ci --prefer-offline --no-audit --progress=false
241247

242248
- name: Download CAR artifact
243249
uses: actions/download-artifact@v3

.github/workflows/eslint.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,13 @@ jobs:
99
- uses: actions/[email protected]
1010

1111
- name: Setup node
12-
uses: actions/setup-node@v3.6.0
12+
uses: actions/setup-node@v4
1313
with:
1414
node-version: 18.14.0
15-
16-
- name: Cache bigger downloads
17-
uses: actions/[email protected]
18-
id: cache
19-
with:
20-
path: ${{ github.workspace }}/.cache
21-
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
22-
restore-keys: |
23-
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
24-
${{ runner.os }}-
15+
cache: 'npm'
2516

2617
- name: Install dependencies
27-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
18+
run: npm ci --prefer-offline --no-audit --progress=false
2819

2920
- name: ESLint
3021
run: npm run eslint

.github/workflows/node-test.yml

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
if: github.ref == 'refs/heads/main'
2020
uses: RubbaBoy/BYOB@24f464284c1fd32028524b59607d417a2e36fee7
2121
with:
22-
ICON: https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg
23-
NAME: "node-${{ inputs.gh-node-version }}"
24-
LABEL: "${{ inputs.gh-node-version }}"
25-
STATUS: "Building..."
26-
COLOR: grey
27-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
icon: https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg
23+
name: "node-${{ inputs.gh-node-version }}"
24+
label: "${{ inputs.gh-node-version }}"
25+
status: "Building..."
26+
color: grey
27+
github_token: ${{ secrets.GITHUB_TOKEN }}
2828

2929
test-node:
3030
needs: [reset-badge]
@@ -40,9 +40,10 @@ jobs:
4040
- uses: actions/[email protected]
4141

4242
- name: Use Node.js ${{ inputs.gh-node-version }}
43-
uses: actions/setup-node@v3.6.0
43+
uses: actions/setup-node@v4
4444
with:
4545
node-version: ${{ inputs.gh-node-version }}
46+
cache: 'npm'
4647

4748
- name: Remove .npmrc to allow non-strict engines
4849
run: |
@@ -53,22 +54,12 @@ jobs:
5354
run: |
5455
echo "version=$(node --version)" >> $GITHUB_OUTPUT
5556
56-
- name: Cache bigger downloads
57-
uses: actions/[email protected]
58-
id: cache
59-
with:
60-
path: ${{ github.workspace }}/.cache
61-
key: ${{ runner.os }}-${{ inputs.gh-node-version }}-${{ hashFiles('package.json', 'package-lock.json') }}
62-
restore-keys: |
63-
${{ runner.os }}-${{ inputs.gh-node-version }}-${{ hashFiles('package.json', 'package-lock.json') }}
64-
${{ runner.os }}-${{ inputs.gh-node-version }}
65-
6657
- name: Install node-pre-gyp
6758
run: |
68-
npm install node-pre-gyp --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
59+
npm install node-pre-gyp --prefer-offline --no-audit --progress=false
6960
7061
- name: Install dependencies
71-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
62+
run: npm install --progress=false
7263

7364
- name: Confirm build works with Node.js ${{ inputs.gh-node-version }} on ${{ matrix.os }}
7465
run: npm run build
@@ -82,20 +73,20 @@ jobs:
8273
if: ${{ needs.test-node.result == 'success' && github.ref == 'refs/heads/main' }}
8374
uses: RubbaBoy/BYOB@24f464284c1fd32028524b59607d417a2e36fee7
8475
with:
85-
ICON: https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg
86-
NAME: "node-${{ inputs.gh-node-version }}"
87-
LABEL: "${{ needs.test-node.outputs.node-version }}"
88-
STATUS: ${{needs.test-node.result}}
89-
COLOR: green
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
icon: https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg
77+
name: "node-${{ inputs.gh-node-version }}"
78+
label: "${{ needs.test-node.outputs.node-version }}"
79+
status: ${{needs.test-node.result}}
80+
color: green
81+
github_token: ${{ secrets.GITHUB_TOKEN }}
9182

9283
- name: Create failure badge
9384
if: ${{ needs.test-node.result != 'success' && github.ref == 'refs/heads/main' }}
9485
uses: RubbaBoy/BYOB@24f464284c1fd32028524b59607d417a2e36fee7
9586
with:
96-
ICON: https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg
97-
NAME: "node-${{ inputs.gh-node-version }}"
98-
LABEL: "${{ needs.test-node.outputs.node-version }}"
99-
STATUS: ${{needs.test-node.result}}
100-
COLOR: red
101-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
icon: https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original.svg
88+
name: "node-${{ inputs.gh-node-version }}"
89+
label: "${{ needs.test-node.outputs.node-version }}"
90+
status: ${{needs.test-node.result}}
91+
color: red
92+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/node-versions.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test build on different node versions on all platforms
1+
name: Test nodejs support for build on major platforms
22

33
on:
44
schedule:
@@ -8,26 +8,20 @@ on:
88

99
jobs:
1010

11-
test-node-12:
12-
uses: ./.github/workflows/node-test.yml
13-
secrets: inherit
14-
with:
15-
gh-node-version: '12.x'
16-
17-
test-node-14:
11+
test-node-18:
1812
uses: ./.github/workflows/node-test.yml
1913
secrets: inherit
2014
with:
21-
gh-node-version: '14.x'
15+
gh-node-version: '18.x'
2216

23-
test-node-16:
17+
test-node-20:
2418
uses: ./.github/workflows/node-test.yml
2519
secrets: inherit
2620
with:
27-
gh-node-version: '16.x'
21+
gh-node-version: '20.x'
2822

29-
test-node-18:
23+
test-node-21:
3024
uses: ./.github/workflows/node-test.yml
3125
secrets: inherit
3226
with:
33-
gh-node-version: '18.x'
27+
gh-node-version: '21.x'

.github/workflows/test-e2e.yml

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@ jobs:
99
- uses: actions/[email protected]
1010

1111
- name: Setup node
12-
uses: actions/setup-node@v3.6.0
12+
uses: actions/setup-node@v4
1313
with:
1414
node-version: 18.14.0
15+
cache: 'npm'
1516

16-
- name: Cache bigger downloads
17+
- name: Cache test-build output
1718
uses: actions/[email protected]
18-
id: cache
19+
id: test-build-cache
1920
with:
20-
path: ${{ github.workspace }}/.cache
21-
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
21+
path: build
22+
key: test-build-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', '*.js', '*.ts') }}
2223
restore-keys: |
23-
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
24-
${{ runner.os }}-
25-
26-
- name: Install dependencies
27-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
24+
test-build-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', '*.js', '*.ts') }}
2825
29-
- name: Cache test-build output
26+
- name: Cache node_modules
3027
uses: actions/[email protected]
31-
id: test-build-cache
28+
id: test-npm-cache
3229
with:
33-
path: build
34-
key: test-build-${{ runner.os }}-${{ github.sha }}
30+
path: node_modules
31+
key: test-npm-${{ runner.os }}-${{ github.sha }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', 'patches/**', '*.js', '*.ts') }}
3532
restore-keys: |
36-
test-build-${{ runner.os }}-${{ github.sha }}
33+
test-npm-${{ runner.os }}-${{ github.sha }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', 'patches/**', '*.js', '*.ts') }}
34+
35+
- name: Install dependencies
36+
if: steps.test-npm-cache.outputs.cache-hit != 'true'
37+
run: npm ci --prefer-offline --no-audit --progress=false
3738

3839
# This is required to ensure that our code is instrumented with coverage details
3940
- name: Run test build
@@ -53,39 +54,43 @@ jobs:
5354
- uses: actions/[email protected]
5455

5556
- name: Setup node
56-
uses: actions/setup-node@v3.6.0
57+
uses: actions/setup-node@v4
5758
with:
5859
node-version: 18.14.0
60+
cache: 'npm'
5961

60-
- name: Cache bigger downloads
62+
- name: Cache test-build output
6163
uses: actions/[email protected]
62-
id: cache
64+
id: test-build-cache
6365
with:
64-
path: ${{ github.workspace }}/.cache
65-
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
66+
path: build
67+
key: test-build-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', '*.js', '*.ts') }}
6668
restore-keys: |
67-
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
68-
${{ runner.os }}-
69+
test-build-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', '*.js', '*.ts') }}
6970
70-
- name: Install dependencies
71-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
72-
73-
- name: Install playwright browsers
74-
run: npx playwright install --with-deps
75-
76-
- name: Cache test-build output
71+
# We don't want to re-install dependencies for every sharded run
72+
- name: Cache node_modules
7773
uses: actions/[email protected]
78-
id: test-build-cache
74+
id: test-npm-cache
7975
with:
80-
path: build
81-
key: test-build-${{ runner.os }}-${{ github.sha }}
76+
path: node_modules
77+
key: test-npm-${{ runner.os }}-${{ github.sha }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', 'patches/**', '*.js', '*.ts') }}
8278
restore-keys: |
83-
test-build-${{ runner.os }}-${{ github.sha }}
79+
test-npm-${{ runner.os }}-${{ github.sha }}-${{ hashFiles('package.json', 'package-lock.json', 'public', 'src/**', 'patches/**', '*.js', '*.ts') }}
80+
- name: Install dependencies
81+
if: steps.test-npm-cache.outputs.cache-hit != 'true'
82+
run: npm ci --prefer-offline --no-audit --progress=false
8483

85-
# This is required to ensure that our code is instrumented with coverage details
86-
- name: Run test build
87-
if: steps.test-build-cache.outputs.cache-hit != 'true'
88-
run: npm run test:build
84+
# Cache playwright binaries
85+
- uses: actions/cache@v3
86+
id: playwright-cache
87+
with:
88+
path: |
89+
~/.cache/ms-playwright
90+
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
91+
- run: npm ci
92+
- run: npx playwright install --with-deps
93+
if: steps.playwright-cache.outputs.cache-hit != 'true'
8994

9095
- name: Cache nyc_output dir
9196
uses: actions/[email protected]
@@ -104,6 +109,14 @@ jobs:
104109
if: github.ref == 'refs/heads/main' # run non-duplicated tests on non-PRs
105110
run: npm run test:e2e -- --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
106111

112+
- name: Store Artifacts from Failed Tests
113+
if: failure()
114+
uses: actions/upload-artifact@v3
115+
with:
116+
name: test-results
117+
path: test-results/
118+
retention-days: 7
119+
107120
e2e-coverage: # since we run coverage in shards and some files may not contain coverage, we cache the .nyc_output directory
108121
name: 'e2e-coverage'
109122
runs-on: ubuntu-latest
@@ -112,23 +125,10 @@ jobs:
112125
- uses: actions/[email protected]
113126

114127
- name: Setup node
115-
uses: actions/setup-node@v3.6.0
128+
uses: actions/setup-node@v4
116129
with:
117130
node-version: 18.14.0
118-
119-
- name: Cache bigger downloads
120-
uses: actions/[email protected]
121-
id: cache
122-
with:
123-
path: ${{ github.workspace }}/.cache
124-
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
125-
restore-keys: |
126-
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
127-
${{ runner.os }}-
128-
129-
130-
- name: Install dependencies
131-
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm
131+
cache: 'npm'
132132

133133
- name: Cache nyc_output dir
134134
uses: actions/[email protected]

0 commit comments

Comments
 (0)