Skip to content

Commit 4cc6f4c

Browse files
authored
ci: main workflow improvements (#9784)
Speed up and refactor main workflow: - Take advantage of re-usable node/pnpm setup action - Remove explicit fetch-depth - Clean up timeout-minutes
1 parent cb691e0 commit 4cc6f4c

File tree

2 files changed

+84
-134
lines changed

2 files changed

+84
-134
lines changed

.github/actions/setup/action.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
name: Setup node and pnpm
2-
description: Configure the Node.js and pnpm versions
2+
description: |
3+
Configures Node, pnpm, cache, performs pnpm install
34
45
inputs:
56
node-version:
6-
description: 'The Node.js version to use'
7+
description: Node.js version
78
required: true
8-
default: 22.6.2
9+
default: 22.6.0
910
pnpm-version:
10-
description: 'The pnpm version to use'
11+
description: Pnpm version
1112
required: true
1213
default: 9.7.1
14+
pnpm-run-install:
15+
description: Whether to run pnpm install
16+
required: false
17+
default: true
18+
pnpm-restore-cache:
19+
description: Whether to restore cache
20+
required: false
21+
default: true
22+
pnpm-install-cache-key:
23+
description: The cache key for the pnpm install cache
24+
default: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
25+
26+
outputs:
27+
pnpm-store-path:
28+
description: The resolved pnpm store path
29+
pnpm-install-cache-key:
30+
description: The cache key used for pnpm install cache
1331

1432
runs:
1533
using: composite
@@ -30,19 +48,29 @@ runs:
3048
version: ${{ inputs.pnpm-version }}
3149
run_install: false
3250

33-
- name: Get pnpm store directory
51+
- name: Get pnpm store path
3452
shell: bash
3553
run: |
36-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
54+
STORE_PATH=$(pnpm store path --silent)
55+
echo "STORE_PATH=$STORE_PATH" >> $GITHUB_ENV
56+
echo "Pnpm store path resolved to: $STORE_PATH"
3757
38-
- name: Setup pnpm cache
58+
- name: Restore pnpm install cache
59+
if: ${{ inputs.pnpm-restore-cache == 'true' }}
3960
uses: actions/cache@v4
4061
with:
4162
path: ${{ env.STORE_PATH }}
42-
key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
63+
key: ${{ inputs.pnpm-install-cache-key }}
4364
restore-keys: |
65+
pnpm-store-${{ inputs.pnpm-version }}-
4466
pnpm-store-
45-
pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
4667
47-
- shell: bash
68+
- name: Run pnpm install
69+
if: ${{ inputs.pnpm-run-install == 'true' }}
70+
shell: bash
4871
run: pnpm install
72+
73+
# Set the cache key output
74+
- run: |
75+
echo "pnpm-install-cache-key=${{ inputs.pnpm-install-cache-key }}" >> $GITHUB_ENV
76+
shell: bash

.github/workflows/main.yml

Lines changed: 46 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ jobs:
3636
run: sudo ethtool -K eth0 tx off rx off
3737

3838
- uses: actions/checkout@v4
39-
with:
40-
fetch-depth: 25
4139
- uses: dorny/paths-filter@v3
4240
id: filter
4341
with:
@@ -69,40 +67,14 @@ jobs:
6967
runs-on: ubuntu-latest
7068
steps:
7169
- uses: actions/checkout@v4
72-
with:
73-
fetch-depth: 0
74-
75-
# https://github.com/actions/virtual-environments/issues/1187
76-
- name: tune linux network
77-
run: sudo ethtool -K eth0 tx off rx off
7870

79-
- name: Setup Node@${{ env.NODE_VERSION }}
80-
uses: actions/setup-node@v4
71+
- name: Node setup
72+
uses: ./.github/actions/setup
8173
with:
8274
node-version: ${{ env.NODE_VERSION }}
75+
pnpm-version: ${{ env.PNPM_VERSION }}
76+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
8377

84-
- name: Install pnpm
85-
uses: pnpm/action-setup@v4
86-
with:
87-
version: ${{ env.PNPM_VERSION }}
88-
run_install: false
89-
90-
- name: Get pnpm store directory
91-
shell: bash
92-
run: |
93-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
94-
95-
- name: Setup pnpm cache
96-
uses: actions/cache@v4
97-
timeout-minutes: 720
98-
with:
99-
path: ${{ env.STORE_PATH }}
100-
key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
101-
restore-keys: |
102-
pnpm-store-
103-
pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
104-
105-
- run: pnpm install
10678
- name: Lint staged
10779
run: |
10880
git diff --name-only --diff-filter=d origin/${GITHUB_BASE_REF}...${GITHUB_SHA}
@@ -115,47 +87,20 @@ jobs:
11587

11688
steps:
11789
- uses: actions/checkout@v4
118-
with:
119-
fetch-depth: 25
12090

121-
# https://github.com/actions/virtual-environments/issues/1187
122-
- name: tune linux network
123-
run: sudo ethtool -K eth0 tx off rx off
124-
125-
- name: Setup Node@${{ env.NODE_VERSION }}
126-
uses: actions/setup-node@v4
91+
- name: Node setup
92+
uses: ./.github/actions/setup
12793
with:
12894
node-version: ${{ env.NODE_VERSION }}
95+
pnpm-version: ${{ env.PNPM_VERSION }}
96+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
12997

130-
- name: Install pnpm
131-
uses: pnpm/action-setup@v4
132-
with:
133-
version: ${{ env.PNPM_VERSION }}
134-
run_install: false
135-
136-
- name: Get pnpm store directory
137-
shell: bash
138-
run: |
139-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
140-
141-
- name: Setup pnpm cache
142-
uses: actions/cache@v4
143-
timeout-minutes: 720
144-
with:
145-
path: ${{ env.STORE_PATH }}
146-
key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
147-
restore-keys: |
148-
pnpm-store-
149-
pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
150-
151-
- run: pnpm install
15298
- run: pnpm run build:all
15399
env:
154100
DO_NOT_TRACK: 1 # Disable Turbopack telemetry
155101

156102
- name: Cache build
157103
uses: actions/cache@v4
158-
timeout-minutes: 10
159104
with:
160105
path: ./*
161106
key: ${{ github.sha }}-${{ github.run_number }}
@@ -165,24 +110,19 @@ jobs:
165110
needs: [changes, build]
166111
if: ${{ needs.changes.outputs.needs_tests == 'true' }}
167112
steps:
168-
# https://github.com/actions/virtual-environments/issues/1187
169-
- name: tune linux network
170-
run: sudo ethtool -K eth0 tx off rx off
113+
- uses: actions/checkout@v4
171114

172-
- name: Setup Node@${{ env.NODE_VERSION }}
173-
uses: actions/setup-node@v4
115+
- name: Node setup
116+
uses: ./.github/actions/setup
174117
with:
175118
node-version: ${{ env.NODE_VERSION }}
176-
177-
- name: Install pnpm
178-
uses: pnpm/action-setup@v4
179-
with:
180-
version: ${{ env.PNPM_VERSION }}
181-
run_install: false
119+
pnpm-version: ${{ env.PNPM_VERSION }}
120+
pnpm-run-install: false
121+
pnpm-restore-cache: false # Full build is restored below
122+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
182123

183124
- name: Restore build
184125
uses: actions/cache@v4
185-
timeout-minutes: 10
186126
with:
187127
path: ./*
188128
key: ${{ github.sha }}-${{ github.run_number }}
@@ -231,24 +171,21 @@ jobs:
231171

232172
steps:
233173
- uses: actions/checkout@v4
234-
with:
235-
fetch-depth: 25
236-
# https://github.com/actions/virtual-environments/issues/1187
237-
- name: tune linux network
238-
run: sudo ethtool -K eth0 tx off rx off
239174

240-
- name: Setup Node@${{ env.NODE_VERSION }}
241-
uses: actions/setup-node@v4
175+
- name: Node setup
176+
uses: ./.github/actions/setup
242177
with:
243178
node-version: ${{ env.NODE_VERSION }}
179+
pnpm-version: ${{ env.PNPM_VERSION }}
180+
pnpm-run-install: false
181+
pnpm-restore-cache: false # Full build is restored below
182+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
244183

245-
- name: Install pnpm
246-
uses: pnpm/action-setup@v4
184+
- name: Restore build
185+
uses: actions/cache@v4
247186
with:
248-
version: ${{ env.PNPM_VERSION }}
249-
run_install: false
250-
251-
- run: pnpm install
187+
path: ./*
188+
key: ${{ github.sha }}-${{ github.run_number }}
252189

253190
- name: Start LocalStack
254191
run: pnpm docker:start
@@ -341,24 +278,19 @@ jobs:
341278
env:
342279
SUITE_NAME: ${{ matrix.suite }}
343280
steps:
344-
# https://github.com/actions/virtual-environments/issues/1187
345-
- name: tune linux network
346-
run: sudo ethtool -K eth0 tx off rx off
281+
- uses: actions/checkout@v4
347282

348-
- name: Setup Node@${{ env.NODE_VERSION }}
349-
uses: actions/setup-node@v4
283+
- name: Node setup
284+
uses: ./.github/actions/setup
350285
with:
351286
node-version: ${{ env.NODE_VERSION }}
352-
353-
- name: Install pnpm
354-
uses: pnpm/action-setup@v4
355-
with:
356-
version: ${{ env.PNPM_VERSION }}
357-
run_install: false
287+
pnpm-version: ${{ env.PNPM_VERSION }}
288+
pnpm-run-install: false
289+
pnpm-restore-cache: false # Full build is restored below
290+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
358291

359292
- name: Restore build
360293
uses: actions/cache@v4
361-
timeout-minutes: 10
362294
with:
363295
path: ./*
364296
key: ${{ github.sha }}-${{ github.run_number }}
@@ -449,24 +381,19 @@ jobs:
449381
POSTGRES_DB: payloadtests
450382

451383
steps:
452-
# https://github.com/actions/virtual-environments/issues/1187
453-
- name: tune linux network
454-
run: sudo ethtool -K eth0 tx off rx off
384+
- uses: actions/checkout@v4
455385

456-
- name: Setup Node@${{ env.NODE_VERSION }}
457-
uses: actions/setup-node@v4
386+
- name: Node setup
387+
uses: ./.github/actions/setup
458388
with:
459389
node-version: ${{ env.NODE_VERSION }}
460-
461-
- name: Install pnpm
462-
uses: pnpm/action-setup@v4
463-
with:
464-
version: ${{ env.PNPM_VERSION }}
465-
run_install: false
390+
pnpm-version: ${{ env.PNPM_VERSION }}
391+
pnpm-run-install: false
392+
pnpm-restore-cache: false # Full build is restored below
393+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
466394

467395
- name: Restore build
468396
uses: actions/cache@v4
469-
timeout-minutes: 10
470397
with:
471398
path: ./*
472399
key: ${{ github.sha }}-${{ github.run_number }}
@@ -506,24 +433,19 @@ jobs:
506433
needs: [changes, build]
507434
if: ${{ needs.changes.outputs.needs_tests == 'true' }}
508435
steps:
509-
# https://github.com/actions/virtual-environments/issues/1187
510-
- name: tune linux network
511-
run: sudo ethtool -K eth0 tx off rx off
436+
- uses: actions/checkout@v4
512437

513-
- name: Setup Node@${{ env.NODE_VERSION }}
514-
uses: actions/setup-node@v4
438+
- name: Node setup
439+
uses: ./.github/actions/setup
515440
with:
516441
node-version: ${{ env.NODE_VERSION }}
517-
518-
- name: Install pnpm
519-
uses: pnpm/action-setup@v4
520-
with:
521-
version: ${{ env.PNPM_VERSION }}
522-
run_install: false
442+
pnpm-version: ${{ env.PNPM_VERSION }}
443+
pnpm-run-install: false
444+
pnpm-restore-cache: false # Full build is restored below
445+
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
523446

524447
- name: Restore build
525448
uses: actions/cache@v4
526-
timeout-minutes: 10
527449
with:
528450
path: ./*
529451
key: ${{ github.sha }}-${{ github.run_number }}

0 commit comments

Comments
 (0)