Skip to content

Commit ebfbb9a

Browse files
authored
feat: support node v22 (#195)
1 parent cc6211d commit ebfbb9a

File tree

4 files changed

+105
-49
lines changed

4 files changed

+105
-49
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: 'Setup Node.js'
2+
description: 'Setup Node and install dependencies using cache'
3+
inputs:
4+
node-version:
5+
description: Set a specific node version instead of the default from `.node-version` file.
6+
required: false
7+
save-cache:
8+
description: 'Save cache when needed'
9+
required: false
10+
default: 'false'
11+
12+
runs:
13+
using: 'composite'
14+
15+
steps:
16+
- name: ⚙️ Calculate `CACHE_KEY`
17+
shell: bash
18+
run: |
19+
if [[ -z '${{ inputs.node-version }}' ]]; then
20+
node_major=$(grep -E -o '^[0-9]+' .node-version)
21+
else
22+
node_major=$(echo '${{ inputs.node-version }}' | grep -E -o '^[0-9]+')
23+
fi
24+
echo "CACHE_KEY=node_modules-${{ runner.os }}-v${node_major}-${{
25+
hashFiles('.node-version', 'pnpm-lock.yaml')
26+
}}" >> "$GITHUB_ENV"
27+
28+
- name: ♻️ Restore `node_modules`
29+
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
30+
id: node-modules-restore
31+
with:
32+
path: node_modules
33+
key: ${{ env.CACHE_KEY }}
34+
enableCrossOsArchive: true
35+
36+
- name: Calculate `CACHE_HIT`
37+
shell: bash
38+
run: |
39+
echo 'CACHE_HIT=${{
40+
(steps.node-modules-restore.outputs.cache-hit == 'true') && 'true' || ''
41+
}}' >> "$GITHUB_ENV"
42+
43+
- name: ⚙️ Setup pnpm
44+
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
45+
with:
46+
standalone: true
47+
48+
- name: ⚙️ Setup Node.js ${{ inputs.node-version }}
49+
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
50+
with:
51+
node-version-file: ${{ inputs.node-version == '' && '.node-version' || '' }}
52+
node-version: ${{ inputs.node-version }}
53+
cache: ${{ env.CACHE_HIT != 'true' && 'pnpm' || '' }}
54+
55+
- name: 📥 Install dependencies
56+
if: env.CACHE_HIT != 'true'
57+
shell: bash
58+
run: pnpm install --frozen-lockfile
59+
env:
60+
# Other environment variables
61+
HUSKY: '0' # By default do not run HUSKY install
62+
63+
- name: ♻️ Write `node_modules` cache
64+
if: inputs.save-cache == 'true' && env.CACHE_HIT != 'true'
65+
uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
66+
with:
67+
path: node_modules
68+
key: ${{ env.CACHE_KEY }}
69+
enableCrossOsArchive: true

.github/workflows/build.yml

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ concurrency:
1313
cancel-in-progress: ${{ github.ref_name != 'main' }}
1414

1515
env:
16-
GIT_EMAIL: [email protected]
17-
NODE_VERSION: 20 # needs to be in sync with other versions below
1816
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
1917
DRY_RUN: true
2018

2119
permissions:
2220
contents: read
2321

2422
jobs:
23+
prepare:
24+
runs-on: ubuntu-latest
25+
timeout-minutes: 10
26+
27+
steps:
28+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
show-progress: false
31+
32+
- name: 📥 Setup Node.js
33+
uses: ./.github/actions/setup-node
34+
with:
35+
save-cache: true
2536
test:
26-
name: ${{ matrix.node-version == 20 && format('test ({0})', matrix.os) || format('test ({0}, node-{1})', matrix.os, matrix.node-version) }}
37+
needs:
38+
- prepare
39+
name: ${{ matrix.node-version == 22 && format('test ({0})', matrix.os) || format('test ({0}, node-{1})', matrix.os, matrix.node-version) }}
2740
runs-on: ${{ matrix.os }}
2841

2942
# tests shouldn't need more time
@@ -32,41 +45,32 @@ jobs:
3245
strategy:
3346
matrix:
3447
os: [ubuntu-latest, macos-latest, windows-latest]
35-
node-version: [18, 20]
48+
node-version: [18, 20, 22]
3649

3750
env:
38-
coverage: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 20 }}
39-
NODE_VERSION: ${{ matrix.node-version }}
51+
coverage: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 22 }}
4052

4153
steps:
4254
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4355
with:
44-
fetch-depth: 2
56+
fetch-depth: 10 # required for coverage
4557
show-progress: false
4658
filter: blob:none # we don't need all blobs
4759

48-
- name: Enable corepack
49-
run: corepack enable
50-
51-
- name: Set up Node.js ${{ env.NODE_VERSION }}
52-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
60+
- name: 📥 Setup Node.js
61+
uses: ./.github/actions/setup-node
5362
with:
54-
node-version: ${{ env.NODE_VERSION }}
55-
cache: pnpm
63+
node-version: ${{ matrix.node-version }}
64+
save-cache: true
5665

5766
- name: Init platform
5867
shell: bash
5968
run: |
6069
git config --global core.autocrlf false
6170
git config --global core.symlinks true
62-
git config --global user.email ${GIT_EMAIL}
63-
git config --global user.name 'Renovate Bot'
6471
echo "Node $(node --version)"
6572
echo "pnpm $(pnpm --version)"
6673
67-
- name: Installing dependencies
68-
run: pnpm install
69-
7074
- name: Build
7175
run: pnpm build
7276

@@ -87,6 +91,8 @@ jobs:
8791
if: env.coverage == 'true'
8892

8993
lint:
94+
needs:
95+
- prepare
9096
runs-on: ubuntu-latest
9197

9298
# lint shouldn't need more than 10 min
@@ -95,31 +101,18 @@ jobs:
95101
steps:
96102
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
97103
with:
98-
fetch-depth: 2
99104
show-progress: false
100-
filter: blob:none # we don't need all blobs
101105

102-
- name: Enable corepack
103-
run: corepack enable
104-
105-
- name: Set up Node.js ${{ env.NODE_VERSION }}
106-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
107-
with:
108-
node-version: ${{ env.NODE_VERSION }}
109-
cache: pnpm
106+
- name: 📥 Setup Node.js
107+
uses: ./.github/actions/setup-node
110108

111109
- name: Init platform
112110
run: |
113111
git config --global core.autocrlf false
114112
git config --global core.symlinks true
115-
git config --global user.email ${GIT_EMAIL}
116-
git config --global user.name 'Renovate Bot'
117113
echo "Node $(node --version)"
118114
echo "pnpm $(pnpm --version)"
119115
120-
- name: Installing dependencies
121-
run: pnpm install
122-
123116
- name: Lint
124117
run: |
125118
pnpm eslint -f gha
@@ -130,7 +123,9 @@ jobs:
130123
run: pnpm type-check
131124

132125
release:
133-
needs: [lint, test]
126+
needs:
127+
- lint
128+
- test
134129
runs-on: ubuntu-latest
135130
# release shouldn't need more than 5 min
136131
timeout-minutes: 15
@@ -147,21 +142,15 @@ jobs:
147142
show-progress: false
148143
filter: blob:none # we don't need all blobs
149144

150-
- name: Enable corepack
151-
run: corepack enable
152-
153-
- name: Set up Node.js ${{ env.NODE_VERSION }}
154-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
155-
with:
156-
node-version: ${{ env.NODE_VERSION }}
157-
cache: pnpm
145+
- name: 📥 Setup Node.js
146+
uses: ./.github/actions/setup-node
158147

159148
- name: Init platform
160149
run: |
161150
git config --global core.autocrlf false
162151
git config --global core.symlinks true
163-
git config --global user.email ${GIT_EMAIL}
164-
git config --global user.name 'Renovate Bot'
152+
git config --global user.name "github-actions[bot]"
153+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
165154
166155
- name: Check dry run
167156
run: |
@@ -173,9 +162,6 @@ jobs:
173162
echo "DRY_RUN=false" >> $GITHUB_ENV
174163
fi
175164
176-
- name: Installing dependencies
177-
run: pnpm install
178-
179165
- name: semantic-release
180166
run: pnpm semantic-release --dry-run ${{github.ref != 'refs/heads/main'}} --ci ${{github.ref == 'refs/heads/main'}}
181167
env:

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.11.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
},
5858
"packageManager": "[email protected]",
5959
"engines": {
60-
"node": "^18.12.0 || >= 20.0.0",
60+
"node": "^18.12.0 || ^20.0.0 || ^22.11.0",
6161
"pnpm": "^8.6.11"
6262
}
6363
}

0 commit comments

Comments
 (0)