Skip to content

Commit 8c779d8

Browse files
authored
Merge pull request #5567 from NomicFoundation/galargh/github-actions-caching-v2
ci(v2): improve usage of github actions cache
2 parents 6f3b65e + a1c1932 commit 8c779d8

29 files changed

+152
-392
lines changed

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

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Setup env
2+
description: Sets up node and pnpm
3+
4+
inputs:
5+
pnpm-version:
6+
description: Version of pnpm to install
7+
required: false
8+
default: "9"
9+
node-version:
10+
description: Version of node to install
11+
required: false
12+
default: "18"
13+
cache-save:
14+
description: Whether to save the pnpm cache
15+
required: false
16+
default: "false"
17+
outputs:
18+
cache-hit:
19+
description: Whether the cache was restored
20+
value: ${{ steps.setup-node.outputs.cache-hit || steps.cache-restore.outputs.cache-hit }}
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- uses: pnpm/action-setup@v4
26+
with:
27+
version: ${{ inputs.pnpm-version }}
28+
- uses: actions/setup-node@v4
29+
id: setup-node
30+
with:
31+
node-version: ${{ inputs.node-version }}
32+
cache: ${{ inputs.cache-save == 'true' && 'pnpm' || '' }}
33+
cache-dependency-path: "**/pnpm-lock.yaml"
34+
- id: pnpm
35+
if: inputs.cache-save == 'false'
36+
run: pnpm store path --silent | xargs -I {} -0 echo "path={}" | tee -a $GITHUB_OUTPUT
37+
shell: bash
38+
- uses: actions/cache/restore@v4
39+
id: cache-restore
40+
if: inputs.cache-save == 'false'
41+
with:
42+
path: ${{ steps.pnpm.outputs.path }}
43+
key: node-cache-${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

.github/workflows/LATEST_DEPENDENCY_VERSIONS.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ jobs:
1414
runs-on: ${{ matrix.system }}
1515
steps:
1616
- uses: actions/checkout@v4
17-
- uses: pnpm/action-setup@v4
18-
with:
19-
version: 9
20-
- uses: actions/setup-node@v4
21-
with:
22-
node-version: 18
23-
cache: "pnpm"
17+
- uses: ./.github/actions/setup-env
2418
- name: Delete pnpm-lock.yaml
2519
run: "rm pnpm-lock.yaml"
2620
- name: Install

.github/workflows/cache.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Cache
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- pre-release-testing-branch
8+
- changeset-release/main
9+
- v-next
10+
paths:
11+
- ".github/workflows/cache.yml"
12+
- "**/pnpm-lock.yaml"
13+
pull_request:
14+
paths:
15+
- ".github/workflows/cache.yml"
16+
- "**/pnpm-lock.yaml"
17+
workflow_dispatch:
18+
19+
concurrency:
20+
group: ${{github.workflow}}-${{github.ref}}
21+
cancel-in-progress: true
22+
23+
defaults:
24+
run:
25+
shell: bash
26+
27+
jobs:
28+
cache:
29+
name: Cache
30+
runs-on: ${{ matrix.runner }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
runner: ["ubuntu-latest", "macos-latest", "windows-latest"]
35+
steps:
36+
- uses: actions/checkout@v4
37+
- id: env
38+
uses: ./.github/actions/setup-env
39+
with:
40+
cache-save: true
41+
- name: Install
42+
if: steps.env.outputs.cache-hit != 'true'
43+
run: |
44+
for lockfile in $(find "$(pwd)" -name pnpm-lock.yaml); do
45+
pushd "$(dirname "$lockfile")"
46+
pnpm install --frozen-lockfile --prefer-offline
47+
popd
48+
done

.github/workflows/check-docs-site.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v4
28-
- uses: pnpm/action-setup@v4
29-
with:
30-
version: 9
31-
- uses: actions/setup-node@v4
32-
with:
33-
node-version: 18
34-
cache: "pnpm"
28+
- uses: ./.github/actions/setup-env
3529
- name: Install
3630
run: pnpm install --frozen-lockfile --prefer-offline
3731
- name: Install Docs

.github/workflows/comment-on-linter-error.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121
with:
2222
ref: "refs/pull/${{ github.event.number }}/merge"
23-
- uses: pnpm/action-setup@v4
24-
with:
25-
version: 9
26-
- uses: actions/setup-node@v4
27-
with:
28-
node-version: 18
29-
cache: "pnpm"
23+
- uses: ./.github/actions/setup-env
3024
- name: Install
3125
run: pnpm install --frozen-lockfile --prefer-offline
3226
- name: Build

.github/workflows/e2e-tests.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ jobs:
2929
IS_WINDOWS: ${{ matrix.os == 'windows-latest' }}
3030
steps:
3131
- uses: actions/checkout@v4
32-
- uses: pnpm/action-setup@v4
33-
with:
34-
version: 9
35-
- uses: actions/setup-node@v4
36-
with:
37-
node-version: 18
32+
- uses: ./.github/actions/setup-env
3833
- name: Run fixture-projects script
3934
run: |
4035
cd e2e

.github/workflows/hardhat-chai-matchers-ci.yml

+3-19
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ jobs:
3131
runs-on: windows-latest
3232
steps:
3333
- uses: actions/checkout@v4
34-
- uses: pnpm/action-setup@v4
35-
with:
36-
version: 9
37-
- uses: actions/setup-node@v4
38-
with:
39-
node-version: 18
40-
cache: "pnpm"
34+
- uses: ./.github/actions/setup-env
4135
- name: Install
4236
run: pnpm install --frozen-lockfile --prefer-offline
4337
- name: Build
@@ -52,13 +46,7 @@ jobs:
5246
runs-on: macos-latest
5347
steps:
5448
- uses: actions/checkout@v4
55-
- uses: pnpm/action-setup@v4
56-
with:
57-
version: 9
58-
- uses: actions/setup-node@v4
59-
with:
60-
node-version: 18
61-
cache: "pnpm"
49+
- uses: ./.github/actions/setup-env
6250
- name: Install
6351
run: pnpm install --frozen-lockfile --prefer-offline
6452
- name: Build
@@ -76,13 +64,9 @@ jobs:
7664
node: [18, 20, 22]
7765
steps:
7866
- uses: actions/checkout@v4
79-
- uses: pnpm/action-setup@v4
80-
with:
81-
version: 9
82-
- uses: actions/setup-node@v4
67+
- uses: ./.github/actions/setup-env
8368
with:
8469
node-version: ${{ matrix.node }}
85-
cache: "pnpm"
8670
- name: Install
8771
run: pnpm install --frozen-lockfile --prefer-offline
8872
- name: Build

.github/workflows/hardhat-core-ci.yml

+3-17
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ jobs:
3939
steps:
4040
- uses: actions/checkout@v4
4141

42-
- uses: pnpm/action-setup@v4
43-
with:
44-
version: 9
45-
- name: Install Node
46-
uses: actions/setup-node@v4
42+
- uses: ./.github/actions/setup-env
4743
with:
4844
node-version: ${{ matrix.node }}
49-
cache: pnpm
5045

5146
- name: Install package
5247
run: pnpm install --frozen-lockfile --prefer-offline
@@ -81,14 +76,9 @@ jobs:
8176
steps:
8277
- uses: actions/checkout@v4
8378

84-
- uses: pnpm/action-setup@v4
85-
with:
86-
version: 9
87-
- name: Install Node
88-
uses: actions/setup-node@v4
79+
- uses: ./.github/actions/setup-env
8980
with:
9081
node-version: ${{ matrix.node }}
91-
cache: pnpm
9282

9383
- name: Install package
9484
run: pnpm install --frozen-lockfile --prefer-offline
@@ -121,13 +111,9 @@ jobs:
121111
node: [18, 20]
122112
steps:
123113
- uses: actions/checkout@v4
124-
- uses: pnpm/action-setup@v4
125-
with:
126-
version: 9
127-
- uses: actions/setup-node@v4
114+
- uses: ./.github/actions/setup-env
128115
with:
129116
node-version: ${{ matrix.node }}
130-
cache: pnpm
131117
- name: Install
132118
run: pnpm install --frozen-lockfile --prefer-offline
133119
- name: Install @types/node

.github/workflows/hardhat-ethers-ci.yml

+3-19
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ jobs:
3333
runs-on: windows-latest
3434
steps:
3535
- uses: actions/checkout@v4
36-
- uses: pnpm/action-setup@v4
37-
with:
38-
version: 9
39-
- uses: actions/setup-node@v4
40-
with:
41-
node-version: 18
42-
cache: "pnpm"
36+
- uses: ./.github/actions/setup-env
4337
- name: Install
4438
run: pnpm install --frozen-lockfile --prefer-offline
4539
- name: Build
@@ -52,13 +46,7 @@ jobs:
5246
runs-on: macos-latest
5347
steps:
5448
- uses: actions/checkout@v4
55-
- uses: pnpm/action-setup@v4
56-
with:
57-
version: 9
58-
- uses: actions/setup-node@v4
59-
with:
60-
node-version: 18
61-
cache: "pnpm"
49+
- uses: ./.github/actions/setup-env
6250
- name: Install
6351
run: pnpm install --frozen-lockfile --prefer-offline
6452
- name: Build
@@ -74,13 +62,9 @@ jobs:
7462
node: [18, 20, 22]
7563
steps:
7664
- uses: actions/checkout@v4
77-
- uses: pnpm/action-setup@v4
78-
with:
79-
version: 9
80-
- uses: actions/setup-node@v4
65+
- uses: ./.github/actions/setup-env
8166
with:
8267
node-version: ${{ matrix.node }}
83-
cache: "pnpm"
8468
- name: Install
8569
run: pnpm install --frozen-lockfile --prefer-offline
8670
- name: Build

.github/workflows/hardhat-foundry-ci.yml

+3-19
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ jobs:
3131
runs-on: windows-latest
3232
steps:
3333
- uses: actions/checkout@v4
34-
- uses: pnpm/action-setup@v4
35-
with:
36-
version: 9
37-
- uses: actions/setup-node@v4
38-
with:
39-
node-version: 18
40-
cache: "pnpm"
34+
- uses: ./.github/actions/setup-env
4135
- name: Install
4236
run: pnpm install --frozen-lockfile --prefer-offline
4337
- name: Build
@@ -52,13 +46,7 @@ jobs:
5246
runs-on: macos-latest
5347
steps:
5448
- uses: actions/checkout@v4
55-
- uses: pnpm/action-setup@v4
56-
with:
57-
version: 9
58-
- uses: actions/setup-node@v4
59-
with:
60-
node-version: 18
61-
cache: "pnpm"
49+
- uses: ./.github/actions/setup-env
6250
- name: Install
6351
run: pnpm install --frozen-lockfile --prefer-offline
6452
- name: Build
@@ -76,13 +64,9 @@ jobs:
7664
node: [18, 20, 22]
7765
steps:
7866
- uses: actions/checkout@v4
79-
- uses: pnpm/action-setup@v4
80-
with:
81-
version: 9
82-
- uses: actions/setup-node@v4
67+
- uses: ./.github/actions/setup-env
8368
with:
8469
node-version: ${{ matrix.node }}
85-
cache: "pnpm"
8670
- name: Install
8771
run: pnpm install --frozen-lockfile --prefer-offline
8872
- name: Build

.github/workflows/hardhat-ledger-ci.yml

+3-19
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ jobs:
3333
runs-on: windows-latest
3434
steps:
3535
- uses: actions/checkout@v4
36-
- uses: pnpm/action-setup@v4
37-
with:
38-
version: 9
39-
- uses: actions/setup-node@v4
40-
with:
41-
node-version: 18
42-
cache: "pnpm"
36+
- uses: ./.github/actions/setup-env
4337
- name: Install
4438
run: pnpm install --frozen-lockfile --prefer-offline
4539
- name: Build
@@ -52,13 +46,7 @@ jobs:
5246
runs-on: macos-latest
5347
steps:
5448
- uses: actions/checkout@v4
55-
- uses: pnpm/action-setup@v4
56-
with:
57-
version: 9
58-
- uses: actions/setup-node@v4
59-
with:
60-
node-version: 18
61-
cache: "pnpm"
49+
- uses: ./.github/actions/setup-env
6250
- name: Install
6351
run: pnpm install --frozen-lockfile --prefer-offline
6452
- name: Build
@@ -74,13 +62,9 @@ jobs:
7462
node: [18, 20, 22]
7563
steps:
7664
- uses: actions/checkout@v4
77-
- uses: pnpm/action-setup@v4
78-
with:
79-
version: 9
80-
- uses: actions/setup-node@v4
65+
- uses: ./.github/actions/setup-env
8166
with:
8267
node-version: ${{ matrix.node }}
83-
cache: "pnpm"
8468
- name: Install
8569
run: pnpm install --frozen-lockfile --prefer-offline
8670
- name: Build

0 commit comments

Comments
 (0)