-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecosystem-ci.ts
199 lines (192 loc) · 6.41 KB
/
ecosystem-ci.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import fs from 'fs'
import path from 'path'
import process from 'process'
import { cac } from 'cac'
import {
setupEnvironment,
setupRsbuildRepo,
buildRsbuild,
bisectRsbuild,
parseRsbuildMajor,
parseMajorVersion,
ignorePrecoded,
} from './utils'
import { CommandOptions, RunOptions } from './types'
const cli = cac()
cli
.command('[...suites]', 'build rsbuild and run selected suites')
.option('--verify', 'verify checkouts by running tests', { default: false })
.option('--repo <repo>', 'rsbuild repository to use', {
default: 'web-infra-dev/rsbuild',
})
.option('--branch <branch>', 'rsbuild branch to use', { default: 'main' })
.option('--tag <tag>', 'rsbuild tag to use')
.option('--commit <commit>', 'rsbuild commit sha to use')
.option('--release <version>', 'rsbuild release to use from npm registry')
.option('--suite-precoded', 'use precoded suite options under tests dir')
.option('--suite-branch <branch>', 'suite branch to use')
.option('--suite-tag <tag>', 'suite tag to use')
.option('--suite-commit <commit>', 'suite commit sha to use')
.action(async (suites, options: CommandOptions) => {
const { root, rsbuildPath, workspace } = await setupEnvironment()
const suitesToRun = getSuitesToRun(suites, root)
let rsbuildMajor
if (!options.release) {
await setupRsbuildRepo(options)
await buildRsbuild({ verify: options.verify })
rsbuildMajor = parseRsbuildMajor(rsbuildPath)
} else {
rsbuildMajor = parseMajorVersion(options.release)
}
const runOptions: RunOptions = {
root,
rsbuildPath,
rsbuildMajor,
workspace,
release: options.release,
verify: options.verify,
skipGit: false,
suiteBranch: ignorePrecoded(options.suiteBranch),
suiteTag: ignorePrecoded(options.suiteTag),
suiteCommit: ignorePrecoded(options.suiteCommit),
}
for (const suite of suitesToRun) {
await run(suite, runOptions)
}
})
cli
.command('build-rsbuild', 'build rsbuild only')
.option('--verify', 'verify rsbuild checkout by running tests', {
default: false,
})
.option('--repo <repo>', 'rsbuild repository to use', {
default: 'web-infra-dev/rsbuild',
})
.option('--branch <branch>', 'rsbuild branch to use', { default: 'main' })
.option('--tag <tag>', 'rsbuild tag to use')
.option('--commit <commit>', 'rsbuild commit sha to use')
.action(async (options: CommandOptions) => {
await setupEnvironment()
await setupRsbuildRepo(options)
await buildRsbuild({ verify: options.verify })
})
cli
.command('run-suites [...suites]', 'run single suite with pre-built rsbuild')
.option(
'--verify',
'verify checkout by running tests before using local rsbuild',
{ default: false },
)
.option('--repo <repo>', 'rsbuild repository to use', {
default: 'web-infra-dev/rsbuild',
})
.option('--release <version>', 'rsbuild release to use from npm registry')
.option('--suite-precoded', 'use precoded suite options under tests dir')
.option('--suite-branch <branch>', 'suite branch to use')
.option('--suite-tag <tag>', 'suite tag to use')
.option('--suite-commit <commit>', 'suite commit sha to use')
.action(async (suites, options: CommandOptions) => {
const { root, rsbuildPath, workspace } = await setupEnvironment()
const suitesToRun = getSuitesToRun(suites, root)
const runOptions: RunOptions = {
...options,
root,
rsbuildPath,
rsbuildMajor: parseRsbuildMajor(rsbuildPath),
workspace,
suiteBranch: ignorePrecoded(options.suiteBranch),
suiteTag: ignorePrecoded(options.suiteTag),
suiteCommit: ignorePrecoded(options.suiteCommit),
}
for (const suite of suitesToRun) {
await run(suite, runOptions)
}
})
cli
.command(
'bisect [...suites]',
'use git bisect to find a commit in rsbuild that broke suites',
)
.option('--good <ref>', 'last known good ref, e.g. a previous tag. REQUIRED!')
.option('--verify', 'verify checkouts by running tests', { default: false })
.option('--repo <repo>', 'rsbuild repository to use', {
default: 'web-infra-dev/rsbuild',
})
.option('--branch <branch>', 'rsbuild branch to use', { default: 'main' })
.option('--tag <tag>', 'rsbuild tag to use')
.option('--commit <commit>', 'rsbuild commit sha to use')
.option('--suite-precoded', 'use precoded suite options under tests dir')
.option('--suite-branch <branch>', 'suite branch to use')
.option('--suite-tag <tag>', 'suite tag to use')
.option('--suite-commit <commit>', 'suite commit sha to use')
.action(async (suites, options: CommandOptions & { good: string }) => {
if (!options.good) {
console.log(
'you have to specify a known good version with `--good <commit|tag>`',
)
process.exit(1)
}
const { root, rsbuildPath, workspace } = await setupEnvironment()
const suitesToRun = getSuitesToRun(suites, root)
let isFirstRun = true
const { verify } = options
const runSuite = async () => {
try {
await buildRsbuild({ verify: isFirstRun && verify })
for (const suite of suitesToRun) {
await run(suite, {
verify: !!(isFirstRun && verify),
skipGit: !isFirstRun,
root,
rsbuildPath,
rsbuildMajor: parseRsbuildMajor(rsbuildPath),
workspace,
suiteBranch: ignorePrecoded(options.suiteBranch),
suiteTag: ignorePrecoded(options.suiteTag),
suiteCommit: ignorePrecoded(options.suiteCommit),
})
}
isFirstRun = false
return null
} catch (e) {
return e
}
}
await setupRsbuildRepo({ ...options, shallow: false })
const initialError = await runSuite()
if (initialError) {
await bisectRsbuild(options.good, runSuite)
} else {
console.log(`no errors for starting commit, cannot bisect`)
}
})
cli.help()
cli.parse()
async function run(suite: string, options: RunOptions) {
const { test } = await import(`./tests/${suite}.ts`)
await test({
...options,
workspace: path.resolve(options.workspace, suite),
})
}
function getSuitesToRun(suites: string[], root: string) {
let suitesToRun: string[] = suites
const availableSuites: string[] = fs
.readdirSync(path.join(root, 'tests'))
.filter((f: string) => !f.startsWith('_') && f.endsWith('.ts'))
.map((f: string) => f.slice(0, -3))
availableSuites.sort()
if (suitesToRun.length === 0) {
suitesToRun = availableSuites
} else {
const invalidSuites = suitesToRun.filter(
(x) => !x.startsWith('_') && !availableSuites.includes(x),
)
if (invalidSuites.length) {
console.log(`invalid suite(s): ${invalidSuites.join(', ')}`)
console.log(`available suites: ${availableSuites.join(', ')}`)
process.exit(1)
}
}
return suitesToRun
}