Skip to content

Commit 29852df

Browse files
authored
ci: release canary versions every week (#7860)
* build: support `--canary` flag for canary releases Also adds `--skip-git` and `--skip-prompts` flags as they would be useful in ecosystem-ci * ci: add a workflow to do canary releases every Monday * build: allow manually releasing patch canary versions * chore: don't bother updating the README As far as I know, only Knighly modifies the README for nightly builds: <https://www.npmjs.com/package/@knightly/vue> Nuxt, React, and TypeScript all keep the README as-is for edge releases. So I think we can avoid the complexity here. * refactor: checkCIStatus -> getCIResult * chore: keep the canary major in sync with the repo major * fix: fix version rewriting * fix: `@vue/compat` is also a core package The directory name format of `@vue/compat` is different from other core packages, so it needs to be handled separately. Missing it didn't cause any problems because the `isCorePackage` function is only used to test dependency names, and `@vue/compat` isn't used as a dependency anywhere. But it's good to fix it anyway.
1 parent 98f1934 commit 29852df

File tree

2 files changed

+181
-60
lines changed

2 files changed

+181
-60
lines changed

.github/workflows/canary.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: canary release
2+
on:
3+
# Runs every Monday at 1 AM UTC (9:00 AM in Singapore)
4+
schedule:
5+
- cron: 0 1 * * MON
6+
workflow_dispatch:
7+
8+
jobs:
9+
canary:
10+
# prevents this action from running on forks
11+
if: github.repository == 'vuejs/core'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install pnpm
17+
uses: pnpm/action-setup@v2
18+
19+
- name: Set node version to 18
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
registry-url: 'https://registry.npmjs.org'
24+
cache: 'pnpm'
25+
26+
- run: pnpm install
27+
28+
- run: pnpm release --canary
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

scripts/release.js

Lines changed: 151 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,41 @@ const preId = args.preid || semver.prerelease(currentVersion)?.[0]
1717
const isDryRun = args.dry
1818
let skipTests = args.skipTests
1919
const skipBuild = args.skipBuild
20+
const isCanary = args.canary
21+
const skipPrompts = args.skipPrompts || args.canary
22+
const skipGit = args.skipGit || args.canary
23+
2024
const packages = fs
2125
.readdirSync(path.resolve(__dirname, '../packages'))
2226
.filter(p => !p.endsWith('.ts') && !p.startsWith('.'))
2327

28+
const isCorePackage = pkgName => {
29+
if (!pkgName) return
30+
31+
if (pkgName === 'vue' || pkgName === '@vue/compat') {
32+
return true
33+
}
34+
35+
return (
36+
pkgName.startsWith('@vue') &&
37+
packages.includes(pkgName.replace(/^@vue\//, ''))
38+
)
39+
}
40+
41+
const renamePackageToCanary = pkgName => {
42+
if (pkgName === 'vue') {
43+
return '@vue/canary'
44+
}
45+
46+
if (isCorePackage(pkgName)) {
47+
return `${pkgName}-canary`
48+
}
49+
50+
return pkgName
51+
}
52+
53+
const keepThePackageName = pkgName => pkgName
54+
2455
const skippedPackages = []
2556

2657
const versionIncrements = [
@@ -42,6 +73,40 @@ const step = msg => console.log(chalk.cyan(msg))
4273
async function main() {
4374
let targetVersion = args._[0]
4475

76+
if (isCanary) {
77+
// The canary version string format is `3.yyyyMMdd.0`.
78+
// Use UTC date so that it's consistent across CI and maintainers' machines
79+
const date = new Date()
80+
const yyyy = date.getUTCFullYear()
81+
const MM = (date.getUTCMonth() + 1).toString().padStart(2, '0')
82+
const dd = date.getUTCDate().toString().padStart(2, '0')
83+
84+
const major = semver.major(currentVersion)
85+
const minor = `${yyyy}${MM}${dd}`
86+
const patch = 0
87+
let canaryVersion = `${major}.${minor}.${patch}`
88+
89+
// check the registry to avoid version collision
90+
// in case we need to publish more than one canary versions in a day
91+
try {
92+
const pkgName = renamePackageToCanary('vue')
93+
const { stdout } = await run(
94+
'pnpm',
95+
['view', `${pkgName}@~${canaryVersion}`, 'version', '--json'],
96+
{ stdio: 'pipe' }
97+
)
98+
const versions = JSON.parse(stdout)
99+
const latestSameDayPatch = /** @type {string} */ (
100+
semver.maxSatisfying(versions, `~${canaryVersion}`)
101+
)
102+
canaryVersion = /** @type {string} */ (
103+
semver.inc(latestSameDayPatch, 'patch')
104+
)
105+
} catch (e) {}
106+
107+
targetVersion = canaryVersion
108+
}
109+
45110
if (!targetVersion) {
46111
// no explicit version, offer suggestions
47112
// @ts-ignore
@@ -70,40 +135,39 @@ async function main() {
70135
throw new Error(`invalid target version: ${targetVersion}`)
71136
}
72137

73-
// @ts-ignore
74-
const { yes: confirmRelease } = await prompt({
75-
type: 'confirm',
76-
name: 'yes',
77-
message: `Releasing v${targetVersion}. Confirm?`
78-
})
79-
80-
if (!confirmRelease) {
81-
return
82-
}
83-
84-
step('Checking CI status for HEAD...')
85-
let isCIPassed = true
86-
try {
87-
const { stdout: sha } = await execa('git', ['rev-parse', 'HEAD'])
88-
const res = await fetch(
89-
`https://api.github.com/repos/vuejs/core/actions/runs?head_sha=${sha}` +
90-
`&status=success&exclude_pull_requests=true`
138+
if (skipPrompts) {
139+
step(
140+
isCanary
141+
? `Releasing canary version v${targetVersion}...`
142+
: `Releasing v${targetVersion}...`
91143
)
92-
const data = await res.json()
93-
isCIPassed = data.workflow_runs.length > 0
94-
} catch (e) {
95-
isCIPassed = false
96-
}
97-
98-
if (isCIPassed) {
144+
} else {
99145
// @ts-ignore
100-
const { yes: promptSkipTests } = await prompt({
146+
const { yes: confirmRelease } = await prompt({
101147
type: 'confirm',
102148
name: 'yes',
103-
message: `CI for this commit passed. Skip local tests?`
149+
message: `Releasing v${targetVersion}. Confirm?`
104150
})
105-
if (promptSkipTests) {
106-
skipTests = true
151+
152+
if (!confirmRelease) {
153+
return
154+
}
155+
}
156+
157+
if (!skipTests) {
158+
step('Checking CI status for HEAD...')
159+
let isCIPassed = await getCIResult()
160+
skipTests ||= isCIPassed
161+
162+
if (isCIPassed && !skipPrompts) {
163+
// @ts-ignore
164+
const { yes: promptSkipTests } = await prompt({
165+
type: 'confirm',
166+
name: 'yes',
167+
message: `CI for this commit passed. Skip local tests?`
168+
})
169+
170+
skipTests = promptSkipTests
107171
}
108172
}
109173

@@ -120,7 +184,10 @@ async function main() {
120184

121185
// update all package versions and inter-dependencies
122186
step('\nUpdating cross dependencies...')
123-
updateVersions(targetVersion)
187+
updateVersions(
188+
targetVersion,
189+
isCanary ? renamePackageToCanary : keepThePackageName
190+
)
124191

125192
// build all packages with types
126193
step('\nBuilding all packages...')
@@ -137,29 +204,36 @@ async function main() {
137204
await run(`pnpm`, ['run', 'changelog'])
138205

139206
// update pnpm-lock.yaml
140-
step('\nUpdating lockfile...')
141-
await run(`pnpm`, ['install', '--prefer-offline'])
142-
143-
const { stdout } = await run('git', ['diff'], { stdio: 'pipe' })
144-
if (stdout) {
145-
step('\nCommitting changes...')
146-
await runIfNotDry('git', ['add', '-A'])
147-
await runIfNotDry('git', ['commit', '-m', `release: v${targetVersion}`])
148-
} else {
149-
console.log('No changes to commit.')
207+
// skipped during canary release because the package names changed and installing with `workspace:*` would fail
208+
if (!isCanary) {
209+
step('\nUpdating lockfile...')
210+
await run(`pnpm`, ['install', '--prefer-offline'])
211+
}
212+
213+
if (!skipGit) {
214+
const { stdout } = await run('git', ['diff'], { stdio: 'pipe' })
215+
if (stdout) {
216+
step('\nCommitting changes...')
217+
await runIfNotDry('git', ['add', '-A'])
218+
await runIfNotDry('git', ['commit', '-m', `release: v${targetVersion}`])
219+
} else {
220+
console.log('No changes to commit.')
221+
}
150222
}
151223

152224
// publish packages
153225
step('\nPublishing packages...')
154226
for (const pkg of packages) {
155-
await publishPackage(pkg, targetVersion, runIfNotDry)
227+
await publishPackage(pkg, targetVersion)
156228
}
157229

158230
// push to GitHub
159-
step('\nPushing to GitHub...')
160-
await runIfNotDry('git', ['tag', `v${targetVersion}`])
161-
await runIfNotDry('git', ['push', 'origin', `refs/tags/v${targetVersion}`])
162-
await runIfNotDry('git', ['push'])
231+
if (!skipGit) {
232+
step('\nPushing to GitHub...')
233+
await runIfNotDry('git', ['tag', `v${targetVersion}`])
234+
await runIfNotDry('git', ['push', 'origin', `refs/tags/v${targetVersion}`])
235+
await runIfNotDry('git', ['push'])
236+
}
163237

164238
if (isDryRun) {
165239
console.log(`\nDry run finished - run git diff to see package changes.`)
@@ -177,42 +251,58 @@ async function main() {
177251
console.log()
178252
}
179253

180-
function updateVersions(version) {
254+
async function getCIResult() {
255+
try {
256+
const { stdout: sha } = await execa('git', ['rev-parse', 'HEAD'])
257+
const res = await fetch(
258+
`https://api.github.com/repos/vuejs/core/actions/runs?head_sha=${sha}` +
259+
`&status=success&exclude_pull_requests=true`
260+
)
261+
const data = await res.json()
262+
return data.workflow_runs.length > 0
263+
} catch (e) {
264+
return false
265+
}
266+
}
267+
268+
function updateVersions(version, getNewPackageName = keepThePackageName) {
181269
// 1. update root package.json
182-
updatePackage(path.resolve(__dirname, '..'), version)
270+
updatePackage(path.resolve(__dirname, '..'), version, getNewPackageName)
183271
// 2. update all packages
184-
packages.forEach(p => updatePackage(getPkgRoot(p), version))
272+
packages.forEach(p =>
273+
updatePackage(getPkgRoot(p), version, getNewPackageName)
274+
)
185275
}
186276

187-
function updatePackage(pkgRoot, version) {
277+
function updatePackage(pkgRoot, version, getNewPackageName) {
188278
const pkgPath = path.resolve(pkgRoot, 'package.json')
189279
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
280+
pkg.name = getNewPackageName(pkg.name)
190281
pkg.version = version
191-
updateDeps(pkg, 'dependencies', version)
192-
updateDeps(pkg, 'peerDependencies', version)
282+
updateDeps(pkg, 'dependencies', version, getNewPackageName)
283+
updateDeps(pkg, 'peerDependencies', version, getNewPackageName)
193284
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
194285
}
195286

196-
function updateDeps(pkg, depType, version) {
287+
function updateDeps(pkg, depType, version, getNewPackageName) {
197288
const deps = pkg[depType]
198289
if (!deps) return
199290
Object.keys(deps).forEach(dep => {
200291
if (deps[dep] === 'workspace:*') {
201292
return
202293
}
203-
if (
204-
dep === 'vue' ||
205-
(dep.startsWith('@vue') && packages.includes(dep.replace(/^@vue\//, '')))
206-
) {
294+
if (isCorePackage(dep)) {
295+
const newName = getNewPackageName(dep)
296+
const newVersion = newName === dep ? version : `npm:${newName}@${version}`
207297
console.log(
208-
chalk.yellow(`${pkg.name} -> ${depType} -> ${dep}@${version}`)
298+
chalk.yellow(`${pkg.name} -> ${depType} -> ${dep}@${newVersion}`)
209299
)
210-
deps[dep] = version
300+
deps[dep] = newVersion
211301
}
212302
})
213303
}
214304

215-
async function publishPackage(pkgName, version, runIfNotDry) {
305+
async function publishPackage(pkgName, version) {
216306
if (skippedPackages.includes(pkgName)) {
217307
return
218308
}
@@ -246,7 +336,8 @@ async function publishPackage(pkgName, version, runIfNotDry) {
246336
version,
247337
...(releaseTag ? ['--tag', releaseTag] : []),
248338
'--access',
249-
'public'
339+
'public',
340+
...(skipGit ? ['--no-commit-hooks', '--no-git-tag-version'] : [])
250341
],
251342
{
252343
cwd: pkgRoot,

0 commit comments

Comments
 (0)