Skip to content

Commit 534d45a

Browse files
B4nanclaude
andcommitted
chore: add cached pnpm-install composite action
Adopts the caching pattern from apify/apify-cli#1068: a reusable composite action at .github/actions/pnpm-install that handles pnpm setup, pnpm store caching (keyed by year-month + lockfile hash), and the install. Workflows now delegate their install step to `uses: ./.github/actions/pnpm-install` instead of inlining each piece. setup-node remains in workflows (without the cache: pnpm parameter, since caching is handled inside the composite). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2d544d8 commit 534d45a

3 files changed

Lines changed: 52 additions & 20 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "pnpm install"
2+
description: "Run pnpm install with cache enabled"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Set up swap space
7+
if: runner.os == 'Linux'
8+
uses: pierotofy/set-swap-space@v1.0
9+
with:
10+
swap-size-gb: 10
11+
12+
- uses: pnpm/action-setup@v4.1.0
13+
name: Install pnpm
14+
with:
15+
run_install: false
16+
17+
- name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
18+
id: pnpm-config
19+
shell: bash
20+
run: |
21+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
22+
23+
- name: Cache rotation keys
24+
id: cache-rotation
25+
shell: bash
26+
run: |
27+
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
28+
29+
- uses: actions/cache@v4
30+
name: Setup pnpm cache
31+
with:
32+
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
33+
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
34+
restore-keys: |
35+
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
36+
37+
- name: Install dependencies
38+
shell: bash
39+
run: |
40+
pnpm install --frozen-lockfile --prefer-offline --loglevel error
41+
env:
42+
HUSKY: "0"

.github/workflows/publish_to_npm.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ jobs:
2222
ref: ${{ inputs.ref }}
2323
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
2424
fetch-depth: 0 # we need to pull everything to allow lerna to detect what packages changed
25-
- uses: pnpm/action-setup@v4
2625
- name: Use Node.js 24
2726
uses: actions/setup-node@v6
2827
with:
2928
node-version: 24
3029
registry-url: 'https://registry.npmjs.org'
31-
cache: 'pnpm'
32-
- name: Install dependencies
33-
run: pnpm install --frozen-lockfile
30+
- name: Install pnpm and dependencies
31+
uses: ./.github/actions/pnpm-install
3432
- name: Build module
3533
run: pnpm build
3634
- name: Publish to NPM

.github/workflows/test_and_release.yaml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v6
22-
- uses: pnpm/action-setup@v4
2322
- name: Use Node.js ${{ matrix.node-version }}
2423
uses: actions/setup-node@v6
2524
with:
2625
node-version: ${{ matrix.node-version }}
27-
cache: 'pnpm'
28-
- name: Install Dependencies
29-
run: pnpm install --frozen-lockfile
26+
- name: Install pnpm and dependencies
27+
uses: ./.github/actions/pnpm-install
3028
- name: Run Tests
3129
run: pnpm test
3230

@@ -36,14 +34,12 @@ jobs:
3634

3735
steps:
3836
- uses: actions/checkout@v6
39-
- uses: pnpm/action-setup@v4
4037
- name: Use Node.js 24
4138
uses: actions/setup-node@v6
4239
with:
4340
node-version: 24
44-
cache: 'pnpm'
45-
- name: Install Dependencies
46-
run: pnpm install --frozen-lockfile
41+
- name: Install pnpm and dependencies
42+
uses: ./.github/actions/pnpm-install
4743
- run: pnpm build
4844

4945
- name: Check build consistency
@@ -59,14 +55,12 @@ jobs:
5955

6056
steps:
6157
- uses: actions/checkout@v6
62-
- uses: pnpm/action-setup@v4
6358
- name: Use Node.js 24
6459
uses: actions/setup-node@v6
6560
with:
6661
node-version: 24
67-
cache: 'pnpm'
68-
- name: Install Dependencies
69-
run: pnpm install --frozen-lockfile
62+
- name: Install pnpm and dependencies
63+
uses: ./.github/actions/pnpm-install
7064
- run: pnpm lint
7165

7266
publish:
@@ -78,13 +72,11 @@ jobs:
7872
- uses: actions/checkout@v6
7973
with:
8074
fetch-depth: 0 # we need to pull everything to allow lerna to detect what packages changed
81-
- uses: pnpm/action-setup@v4
8275
- uses: actions/setup-node@v6
8376
with:
8477
node-version: 24
85-
cache: 'pnpm'
86-
- name: Install Dependencies
87-
run: pnpm install --frozen-lockfile
78+
- name: Install pnpm and dependencies
79+
uses: ./.github/actions/pnpm-install
8880
- name: Check for changes
8981
id: changed_packages
9082
run: |

0 commit comments

Comments
 (0)