Skip to content

Commit dde9681

Browse files
authored
ci: use .tool-versions file in setup (#13093)
Parse `.tool-versions` file in the composite node setup action. This will make it the source of truth and easier to bump node/pnpm versions in the future.
1 parent c876ddf commit dde9681

File tree

6 files changed

+48
-66
lines changed

6 files changed

+48
-66
lines changed

.github/actions/setup/action.yml

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,17 @@ description: |
44
55
inputs:
66
node-version:
7-
description: Node.js version
8-
required: true
9-
default: 23.11.0
7+
description: Node.js version override
108
pnpm-version:
11-
description: Pnpm version
12-
required: true
13-
default: 9.7.1
9+
description: Pnpm version override
1410
pnpm-run-install:
1511
description: Whether to run pnpm install
16-
required: false
1712
default: true
1813
pnpm-restore-cache:
1914
description: Whether to restore cache
20-
required: false
2115
default: true
2216
pnpm-install-cache-key:
23-
description: The cache key for the pnpm install cache
24-
default: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
17+
description: The cache key override for the pnpm install cache
2518

2619
outputs:
2720
pnpm-store-path:
@@ -37,15 +30,44 @@ runs:
3730
shell: bash
3831
run: sudo ethtool -K eth0 tx off rx off
3932

33+
- name: Get versions from .tool-versions or use overrides
34+
shell: bash
35+
run: |
36+
# if node-version input is provided, use it; otherwise, read from .tool-versions
37+
if [ "${{ inputs.node-version }}" ]; then
38+
echo "Node version override provided: ${{ inputs.node-version }}"
39+
echo "NODE_VERSION=${{ inputs.node-version }}" >> $GITHUB_ENV
40+
elif [ -f .tool-versions ]; then
41+
NODE_VERSION=$(grep '^nodejs ' .tool-versions | awk '{print $2}')
42+
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV
43+
echo "Node version resolved to: $NODE_VERSION"
44+
else
45+
echo "No .tool-versions file found and no node-version input provided. Invalid configuration."
46+
exit 1
47+
fi
48+
49+
# if pnpm-version input is provided, use it; otherwise, read from .tool-versions
50+
if [ "${{ inputs.pnpm-version }}" ]; then
51+
echo "Pnpm version override provided: ${{ inputs.pnpm-version }}"
52+
echo "PNPM_VERSION=${{ inputs.pnpm-version }}" >> $GITHUB_ENV
53+
elif [ -f .tool-versions ]; then
54+
PNPM_VERSION=$(grep '^pnpm ' .tool-versions | awk '{print $2}')
55+
echo "PNPM_VERSION=$PNPM_VERSION" >> $GITHUB_ENV
56+
echo "Pnpm version resolved to: $PNPM_VERSION"
57+
else
58+
echo "No .tool-versions file found and no pnpm-version input provided. Invalid configuration."
59+
exit 1
60+
fi
61+
4062
- name: Setup Node@${{ inputs.node-version }}
4163
uses: actions/setup-node@v4
4264
with:
43-
node-version: ${{ inputs.node-version }}
65+
node-version: ${{ env.NODE_VERSION }}
4466

4567
- name: Install pnpm
4668
uses: pnpm/action-setup@v4
4769
with:
48-
version: ${{ inputs.pnpm-version }}
70+
version: ${{ env.PNPM_VERSION }}
4971
run_install: false
5072

5173
- name: Get pnpm store path
@@ -55,14 +77,25 @@ runs:
5577
echo "STORE_PATH=$STORE_PATH" >> $GITHUB_ENV
5678
echo "Pnpm store path resolved to: $STORE_PATH"
5779
80+
- name: Compute Cache Key
81+
shell: bash
82+
run: |
83+
if [ -n "${{ inputs.pnpm-install-cache-key }}" ]; then
84+
PNPM_INSTALL_CACHE_KEY="${{ inputs.pnpm-install-cache-key }}"
85+
else
86+
PNPM_INSTALL_CACHE_KEY="pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}"
87+
fi
88+
echo "Computed PNPM_INSTALL_CACHE_KEY: $PNPM_INSTALL_CACHE_KEY"
89+
echo "PNPM_INSTALL_CACHE_KEY=$PNPM_INSTALL_CACHE_KEY" >> $GITHUB_ENV
90+
5891
- name: Restore pnpm install cache
5992
if: ${{ inputs.pnpm-restore-cache == 'true' }}
6093
uses: actions/cache@v4
6194
with:
6295
path: ${{ env.STORE_PATH }}
63-
key: ${{ inputs.pnpm-install-cache-key }}
96+
key: ${{ env.PNPM_INSTALL_CACHE_KEY }}
6497
restore-keys: |
65-
pnpm-store-${{ inputs.pnpm-version }}-
98+
pnpm-store-${{ env.PNPM_VERSION }}-
6699
pnpm-store-
67100
68101
- name: Run pnpm install
@@ -72,5 +105,5 @@ runs:
72105

73106
# Set the cache key output
74107
- run: |
75-
echo "pnpm-install-cache-key=${{ inputs.pnpm-install-cache-key }}" >> $GITHUB_ENV
108+
echo "pnpm-install-cache-key=${{ env.PNPM_INSTALL_CACHE_KEY }}" >> $GITHUB_OUTPUT
76109
shell: bash

.github/workflows/audit-dependencies.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ on:
1616
default: false
1717

1818
env:
19-
NODE_VERSION: 23.11.0
20-
PNPM_VERSION: 9.7.1
2119
DO_NOT_TRACK: 1 # Disable Turbopack telemetry
2220
NEXT_TELEMETRY_DISABLED: 1 # Disable Next telemetry
2321

@@ -29,9 +27,6 @@ jobs:
2927
uses: actions/checkout@v4
3028
- name: Setup
3129
uses: ./.github/actions/setup
32-
with:
33-
node-version: ${{ env.NODE_VERSION }}
34-
pnpm-version: ${{ env.PNPM_VERSION }}
3530

3631
- name: Run audit dependencies script
3732
id: audit_dependencies

.github/workflows/main.yml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ concurrency:
1717
cancel-in-progress: true
1818

1919
env:
20-
NODE_VERSION: 23.11.0
21-
PNPM_VERSION: 9.7.1
2220
DO_NOT_TRACK: 1 # Disable Turbopack telemetry
2321
NEXT_TELEMETRY_DISABLED: 1 # Disable Next telemetry
2422

@@ -71,10 +69,6 @@ jobs:
7169

7270
- name: Node setup
7371
uses: ./.github/actions/setup
74-
with:
75-
node-version: ${{ env.NODE_VERSION }}
76-
pnpm-version: ${{ env.PNPM_VERSION }}
77-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
7872

7973
- name: Lint
8074
run: pnpm lint -- --quiet
@@ -89,10 +83,6 @@ jobs:
8983

9084
- name: Node setup
9185
uses: ./.github/actions/setup
92-
with:
93-
node-version: ${{ env.NODE_VERSION }}
94-
pnpm-version: ${{ env.PNPM_VERSION }}
95-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
9686

9787
- run: pnpm run build:all
9888
env:
@@ -114,11 +104,8 @@ jobs:
114104
- name: Node setup
115105
uses: ./.github/actions/setup
116106
with:
117-
node-version: ${{ env.NODE_VERSION }}
118-
pnpm-version: ${{ env.PNPM_VERSION }}
119107
pnpm-run-install: false
120108
pnpm-restore-cache: false # Full build is restored below
121-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
122109

123110
- name: Restore build
124111
uses: actions/cache@v4
@@ -141,11 +128,8 @@ jobs:
141128
- name: Node setup
142129
uses: ./.github/actions/setup
143130
with:
144-
node-version: ${{ env.NODE_VERSION }}
145-
pnpm-version: ${{ env.PNPM_VERSION }}
146131
pnpm-run-install: false
147132
pnpm-restore-cache: false # Full build is restored below
148-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
149133

150134
- name: Restore build
151135
uses: actions/cache@v4
@@ -205,11 +189,8 @@ jobs:
205189
- name: Node setup
206190
uses: ./.github/actions/setup
207191
with:
208-
node-version: ${{ env.NODE_VERSION }}
209-
pnpm-version: ${{ env.PNPM_VERSION }}
210192
pnpm-run-install: false
211193
pnpm-restore-cache: false # Full build is restored below
212-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
213194

214195
- name: Restore build
215196
uses: actions/cache@v4
@@ -330,11 +311,8 @@ jobs:
330311
- name: Node setup
331312
uses: ./.github/actions/setup
332313
with:
333-
node-version: ${{ env.NODE_VERSION }}
334-
pnpm-version: ${{ env.PNPM_VERSION }}
335314
pnpm-run-install: false
336315
pnpm-restore-cache: false # Full build is restored below
337-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
338316

339317
- name: Restore build
340318
uses: actions/cache@v4
@@ -467,11 +445,8 @@ jobs:
467445
- name: Node setup
468446
uses: ./.github/actions/setup
469447
with:
470-
node-version: ${{ env.NODE_VERSION }}
471-
pnpm-version: ${{ env.PNPM_VERSION }}
472448
pnpm-run-install: false
473449
pnpm-restore-cache: false # Full build is restored below
474-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
475450

476451
- name: Restore build
477452
uses: actions/cache@v4
@@ -573,11 +548,8 @@ jobs:
573548
- name: Node setup
574549
uses: ./.github/actions/setup
575550
with:
576-
node-version: ${{ env.NODE_VERSION }}
577-
pnpm-version: ${{ env.PNPM_VERSION }}
578551
pnpm-run-install: false
579552
pnpm-restore-cache: false # Full build is restored below
580-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
581553

582554
- name: Restore build
583555
uses: actions/cache@v4
@@ -673,11 +645,8 @@ jobs:
673645
- name: Node setup
674646
uses: ./.github/actions/setup
675647
with:
676-
node-version: ${{ env.NODE_VERSION }}
677-
pnpm-version: ${{ env.PNPM_VERSION }}
678648
pnpm-run-install: false
679649
pnpm-restore-cache: false # Full build is restored below
680-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
681650

682651
- name: Restore build
683652
uses: actions/cache@v4
@@ -735,11 +704,8 @@ jobs:
735704
- name: Node setup
736705
uses: ./.github/actions/setup
737706
with:
738-
node-version: ${{ env.NODE_VERSION }}
739-
pnpm-version: ${{ env.PNPM_VERSION }}
740707
pnpm-run-install: false
741708
pnpm-restore-cache: false # Full build is restored below
742-
pnpm-install-cache-key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
743709

744710
- name: Restore build
745711
uses: actions/cache@v4

.github/workflows/post-release-templates.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77
workflow_dispatch:
88

99
env:
10-
NODE_VERSION: 23.11.0
11-
PNPM_VERSION: 9.7.1
1210
DO_NOT_TRACK: 1 # Disable Turbopack telemetry
1311
NEXT_TELEMETRY_DISABLED: 1 # Disable Next telemetry
1412

@@ -60,9 +58,6 @@ jobs:
6058

6159
- name: Setup
6260
uses: ./.github/actions/setup
63-
with:
64-
node-version: ${{ env.NODE_VERSION }}
65-
pnpm-version: ${{ env.PNPM_VERSION }}
6661

6762
- name: Start PostgreSQL
6863
uses: CasperWA/postgresql-action@v1.2

.github/workflows/post-release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ on:
1212
default: ''
1313

1414
env:
15-
NODE_VERSION: 23.11.0
16-
PNPM_VERSION: 9.7.1
1715
DO_NOT_TRACK: 1 # Disable Turbopack telemetry
1816
NEXT_TELEMETRY_DISABLED: 1 # Disable Next telemetry
1917

.github/workflows/publish-prerelease.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77
workflow_dispatch:
88

99
env:
10-
NODE_VERSION: 23.11.0
11-
PNPM_VERSION: 9.7.1
1210
DO_NOT_TRACK: 1 # Disable Turbopack telemetry
1311
NEXT_TELEMETRY_DISABLED: 1 # Disable Next telemetry
1412

@@ -23,9 +21,6 @@ jobs:
2321
uses: actions/checkout@v4
2422
- name: Setup
2523
uses: ./.github/actions/setup
26-
with:
27-
node-version: ${{ env.NODE_VERSION }}
28-
pnpm-version: ${{ env.PNPM_VERSION }}
2924
- name: Load npm token
3025
run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
3126
env:

0 commit comments

Comments
 (0)