Skip to content

Commit a1f0278

Browse files
authored
ci: add react version matrix to ci workflows (#7105)
1 parent 3528836 commit a1f0278

File tree

4 files changed

+96
-17
lines changed

4 files changed

+96
-17
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ jobs:
5555

5656
test:
5757
runs-on: ubuntu-latest
58+
strategy:
59+
fail-fast: false
60+
matrix:
61+
react-version: ['react-18', 'react-19']
5862
steps:
5963
- name: Checkout repository
6064
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
@@ -72,6 +76,8 @@ jobs:
7276
${{ runner.os }}-turbo-
7377
- name: Install dependencies
7478
run: npm ci
79+
- if: ${{ matrix.react-version == 'react-19' }}
80+
run: node script/setup-react-19.mts
7581
- name: Build
7682
run: npm run build
7783
- name: Run tests defined in vitest
@@ -81,6 +87,10 @@ jobs:
8187

8288
type-check:
8389
runs-on: ubuntu-latest
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
react-version: ['react-18', 'react-19']
8494
steps:
8595
- name: Checkout repository
8696
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
@@ -98,13 +108,19 @@ jobs:
98108
${{ runner.os }}-turbo-
99109
- name: Install dependencies
100110
run: npm ci
111+
- if: ${{ matrix.react-version == 'react-19' }}
112+
run: node script/setup-react-19.mts
101113
- name: Build project
102114
run: npm run build
103115
- name: Type check
104116
run: npm run type-check
105117

106118
examples:
107119
runs-on: ubuntu-latest
120+
strategy:
121+
fail-fast: false
122+
matrix:
123+
react-version: ['react-18', 'react-19']
108124
steps:
109125
- name: Checkout repository
110126
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
@@ -122,6 +138,8 @@ jobs:
122138
${{ runner.os }}-turbo-
123139
- name: Install dependencies
124140
run: npm ci
141+
- if: ${{ matrix.react-version == 'react-19' }}
142+
run: node script/setup-react-19.mts
125143
- name: Build
126144
run: npx turbo build
127145

package-lock.json

Lines changed: 30 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@prettier/sync": "0.5.5",
5959
"@primer/stylelint-config": "13.3.0",
6060
"@size-limit/preset-big-lib": "11.2.0",
61+
"@types/semver": "^7.7.1",
6162
"@vitest/browser": "^4.0.3",
6263
"@vitest/browser-playwright": "^4.0.3",
6364
"@vitest/eslint-plugin": "^1.3.24",
@@ -76,6 +77,7 @@
7677
"eslint-plugin-ssr-friendly": "1.3.0",
7778
"eslint-plugin-storybook": "^9.1.5",
7879
"eslint-plugin-testing-library": "^7.7.0",
80+
"fast-glob": "^3.3.3",
7981
"globals": "^16.2.0",
8082
"markdownlint-cli2": "^0.17.2",
8183
"markdownlint-cli2-formatter-pretty": "^0.0.8",

script/setup-react-19.mts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {execSync} from 'node:child_process'
2+
import fs from 'node:fs'
3+
import glob from 'fast-glob'
4+
import semver from 'semver'
5+
6+
const versions = new Map([
7+
['@types/react', '^19.2.2'],
8+
['@types/react-dom', '^19.2.2'],
9+
['@types/react-is', '^19.2.0'],
10+
['react', '^19.2.0'],
11+
['react-dom', '^19.2.0'],
12+
['react-is', '^19.2.0'],
13+
])
14+
15+
const packageJsonPaths = glob.sync('{examples,packages}/**/package.json', {
16+
ignore: ['**/node_modules/**', '**/dist/**', '**/lib/**', '**/lib-esm/**', '**/.next/**', '**/storybook-static/**'],
17+
})
18+
19+
const dependencyTypes = new Set(['dependencies', 'devDependencies', 'peerDependencies'])
20+
21+
for (const packageJsonPath of packageJsonPaths) {
22+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
23+
24+
for (const dependencyType of dependencyTypes) {
25+
const dependencies = packageJson[dependencyType]
26+
27+
if (!dependencies) {
28+
continue
29+
}
30+
31+
for (const [pkg, targetRange] of versions) {
32+
const range = dependencies[pkg]
33+
if (!range) {
34+
continue
35+
}
36+
37+
if (!semver.subset(targetRange, range)) {
38+
dependencies[pkg] = targetRange
39+
}
40+
}
41+
}
42+
43+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8')
44+
}
45+
46+
execSync('npm install', {stdio: 'inherit'})

0 commit comments

Comments
 (0)