Skip to content

Commit 47eae51

Browse files
authored
Merge pull request #5563 from NomicFoundation/galargh/github-actions-caching
ci(v3): improve usage of github actions cache
2 parents c0702b8 + 38348a6 commit 47eae51

File tree

4 files changed

+96
-27
lines changed

4 files changed

+96
-27
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/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/v-next-changesets-release.yml

+3-15
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ jobs:
1616
uses: actions/checkout@v4
1717
with:
1818
fetch-depth: 0
19-
- uses: pnpm/action-setup@v4
20-
with:
21-
version: 9
22-
- uses: actions/setup-node@v4
19+
- uses: ./.github/actions/setup-env
2320
with:
2421
node-version: 22
25-
cache: "pnpm"
2622
- name: Install
2723
run: pnpm install --no-frozen-lockfile
2824
- name: Changeset Check
@@ -48,13 +44,9 @@ jobs:
4844
uses: actions/checkout@v4
4945
with:
5046
fetch-depth: 0
51-
- uses: pnpm/action-setup@v4
52-
with:
53-
version: 9
54-
- uses: actions/setup-node@v4
47+
- uses: ./.github/actions/setup-env
5548
with:
5649
node-version: 22
57-
cache: "pnpm"
5850
- name: Install
5951
run: pnpm install --no-frozen-lockfile
6052
- name: Run full check (build, lint and test)
@@ -72,13 +64,9 @@ jobs:
7264
uses: actions/checkout@v4
7365
with:
7466
fetch-depth: 0
75-
- uses: pnpm/action-setup@v4
76-
with:
77-
version: 9
78-
- uses: actions/setup-node@v4
67+
- uses: ./.github/actions/setup-env
7968
with:
8069
node-version: 22
81-
cache: "pnpm"
8270
- name: Install
8371
run: pnpm install --no-frozen-lockfile
8472
- name: Apply and commit changesets

.github/workflows/v-next-ci.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,9 @@ jobs:
6969

7070
steps:
7171
- uses: actions/checkout@v4
72-
- name: Install pnpm
73-
uses: pnpm/action-setup@v4
74-
with:
75-
version: 9
76-
- uses: actions/setup-node@v4
72+
- uses: ./.github/actions/setup-env
7773
with:
7874
node-version: 22
79-
cache: "pnpm"
8075
- name: Install dependencies
8176
run: pnpm install --frozen-lockfile --prefer-offline
8277
- name: Build
@@ -102,14 +97,9 @@ jobs:
10297

10398
steps:
10499
- uses: actions/checkout@v4
105-
- name: Install pnpm
106-
uses: pnpm/action-setup@v4
107-
with:
108-
version: 9
109-
- uses: actions/setup-node@v4
100+
- uses: ./.github/actions/setup-env
110101
with:
111102
node-version: ${{ matrix.node }}
112-
cache: "pnpm"
113103
- name: Install dependencies
114104
run: pnpm install --frozen-lockfile --prefer-offline
115105
- name: Build

0 commit comments

Comments
 (0)