2023-03-24 00:28:49 +01:00
|
|
|
const path = require('path')
|
|
|
|
const execa = require('execa')
|
|
|
|
const resolveFrom = require('resolve-from')
|
|
|
|
const ansiEscapes = require('ansi-escapes')
|
2023-04-01 04:00:12 +02:00
|
|
|
const fetch = require('node-fetch')
|
2023-03-24 00:28:49 +01:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const args = process.argv
|
|
|
|
const releaseType = args[args.indexOf('--release-type') + 1]
|
|
|
|
const semverType = args[args.indexOf('--semver-type') + 1]
|
2023-03-24 06:30:08 +01:00
|
|
|
const isCanary = releaseType !== 'stable'
|
2023-03-24 00:28:49 +01:00
|
|
|
|
|
|
|
if (releaseType !== 'stable' && releaseType !== 'canary') {
|
|
|
|
console.log(`Invalid release type ${releaseType}, must be stable or canary`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (!isCanary && !['patch', 'minor', 'stable'].includes(semverType)) {
|
|
|
|
console.log(
|
|
|
|
`Invalid semver type ${semverType}, must be one of ${semverType.join(
|
|
|
|
', '
|
|
|
|
)}`
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const githubToken = process.env.START_RELEASE_TOKEN
|
|
|
|
|
|
|
|
if (!githubToken) {
|
|
|
|
console.log(`Missing START_RELEASE_TOKEN`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const configStorePath = resolveFrom(
|
|
|
|
path.join(process.cwd(), 'node_modules/release'),
|
|
|
|
'configstore'
|
|
|
|
)
|
|
|
|
const ConfigStore = require(configStorePath)
|
|
|
|
|
|
|
|
const config = new ConfigStore('release')
|
|
|
|
config.set('token', githubToken)
|
|
|
|
|
|
|
|
await execa(
|
2023-03-24 07:07:52 +01:00
|
|
|
`git remote set-url origin https://ijjk:${githubToken}@github.com/vercel/next.js.git`,
|
2023-03-24 00:28:49 +01:00
|
|
|
{ stdio: 'inherit', shell: true }
|
|
|
|
)
|
|
|
|
await execa(`git config user.name "JJ Kasper"`, {
|
|
|
|
stdio: 'inherit',
|
|
|
|
shell: true,
|
|
|
|
})
|
|
|
|
await execa(`git config user.email "jj@jjsweb.site"`, {
|
|
|
|
stdio: 'inherit',
|
|
|
|
shell: true,
|
|
|
|
})
|
|
|
|
|
2023-03-25 20:59:51 +01:00
|
|
|
const child = execa(`pnpm release-${isCanary ? 'canary' : 'stable'}`, {
|
2023-03-24 00:28:49 +01:00
|
|
|
stdio: 'pipe',
|
|
|
|
shell: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
child.stdout.pipe(process.stdout)
|
|
|
|
child.stderr.pipe(process.stderr)
|
|
|
|
|
|
|
|
if (isCanary) {
|
|
|
|
child.stdin.write('y\n')
|
|
|
|
} else {
|
|
|
|
if (semverType === 'minor') {
|
|
|
|
child.stdin.write(ansiEscapes.cursorDown(1))
|
|
|
|
}
|
|
|
|
if (semverType === 'major') {
|
|
|
|
child.stdin.write(ansiEscapes.cursorDown(1))
|
|
|
|
child.stdin.write(ansiEscapes.cursorDown(1))
|
|
|
|
}
|
|
|
|
child.stdin.write('\n')
|
|
|
|
}
|
|
|
|
await child
|
2023-04-01 04:00:12 +02:00
|
|
|
|
|
|
|
if (isCanary) {
|
|
|
|
try {
|
|
|
|
const ghHeaders = {
|
|
|
|
Accept: 'application/vnd.github+json',
|
|
|
|
Authorization: `Bearer ${githubToken}`,
|
|
|
|
'X-GitHub-Api-Version': '2022-11-28',
|
|
|
|
}
|
|
|
|
const { version } = require('../lerna.json')
|
|
|
|
const releaseUrlRes = await fetch(
|
|
|
|
`https://api.github.com/repos/vercel/next.js/releases/tag/${version}`,
|
|
|
|
{
|
|
|
|
headers: ghHeaders,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const { url } = await releaseUrlRes.json()
|
|
|
|
const undraftRes = await fetch(url, {
|
|
|
|
headers: ghHeaders,
|
|
|
|
method: 'PATCH',
|
|
|
|
body: JSON.stringify({
|
|
|
|
draft: false,
|
|
|
|
name: version,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
if (undraftRes.ok) {
|
|
|
|
console.log('undrafted canary release successfuly')
|
|
|
|
} else {
|
|
|
|
console.log(`Failed to undraft`, await undraftRes.text())
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error(`Failed to undraft release`, err)
|
|
|
|
}
|
|
|
|
}
|
2023-03-24 00:28:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|