Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
131 lines
3.6 KiB
JavaScript
131 lines
3.6 KiB
JavaScript
// @ts-check
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const execa = require('execa')
|
|
|
|
async function main() {
|
|
const args = process.argv
|
|
const branchName = args[args.indexOf('--branch-name') + 1]
|
|
const tagName = args[args.indexOf('--tag-name') + 1]
|
|
|
|
if (!branchName) {
|
|
throw new Error('branchName value is missing!')
|
|
}
|
|
|
|
if (!tagName || !tagName.startsWith('v')) {
|
|
throw new Error('tagName value is invalid "' + tagName + '"')
|
|
}
|
|
|
|
const githubToken = process.env.RELEASE_BOT_GITHUB_TOKEN
|
|
|
|
if (!githubToken) {
|
|
console.log(`Missing RELEASE_BOT_GITHUB_TOKEN`)
|
|
return
|
|
}
|
|
|
|
await execa(
|
|
`git remote set-url origin https://nextjs-bot:${githubToken}@github.com/vercel/next.js.git`,
|
|
{ stdio: 'inherit', shell: true }
|
|
)
|
|
await execa(`git config user.name "nextjs-bot"`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
await execa(`git config user.email "it+nextjs-bot@vercel.com"`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
await execa(`git checkout -b "${branchName}"`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
await execa(`git fetch origin ${tagName} --tags`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
await execa(`git reset --hard ${tagName}`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
const lernaPath = path.join(__dirname, '..', 'lerna.json')
|
|
const existingLerna = JSON.parse(
|
|
await fs.promises.readFile(lernaPath, 'utf8')
|
|
)
|
|
existingLerna.command.publish.allowBranch.push(branchName)
|
|
|
|
await fs.promises.writeFile(lernaPath, JSON.stringify(existingLerna, null, 2))
|
|
|
|
const buildAndDeployPath = path.join(
|
|
__dirname,
|
|
'..',
|
|
'.github',
|
|
'workflows',
|
|
'build_and_deploy.yml'
|
|
)
|
|
const buildAndDeploy = await fs.promises.readFile(buildAndDeployPath, 'utf8')
|
|
await fs.promises.writeFile(
|
|
buildAndDeployPath,
|
|
buildAndDeploy.replace(/refs\/heads\/canary/g, `refs/heads/${branchName}`)
|
|
)
|
|
|
|
const buildAndTestPath = path.join(
|
|
__dirname,
|
|
'..',
|
|
'.github',
|
|
'workflows',
|
|
'build_and_test.yml'
|
|
)
|
|
let buildAndTest = await fs.promises.readFile(buildAndTestPath, 'utf8')
|
|
buildAndTest = buildAndTest
|
|
.replace(`['canary']`, `['${branchName}']`)
|
|
.replace(/[\s]{1,}('test-new-tests-.+',)/g, '')
|
|
|
|
buildAndTest = buildAndTest.replace(
|
|
/(^[ \t]*)# test-new-tests-if\n(^[ \t]*)if:.*\n(^[ \t]*)# test-new-tests-end-if/gm,
|
|
(_, indent1, indent2, indent3) =>
|
|
`${indent1}# test-new-tests-if\n${indent2}if: false\n${indent3}# test-new-tests-end-if`
|
|
)
|
|
|
|
await fs.promises.writeFile(buildAndTestPath, buildAndTest)
|
|
|
|
await execa(`git add .`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
await execa(`git commit -m "setup release branch"`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
await execa(`git push origin "${branchName}"`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
})
|
|
|
|
console.log(`Waiting 5s before updating branch rules`)
|
|
await new Promise((resolve) => setTimeout(resolve, 5_000))
|
|
|
|
const updateEnvironmentRes = await fetch(
|
|
'https://api.github.com/repos/vercel/next.js/environments/release-stable/deployment-branch-policies',
|
|
{
|
|
method: 'POST',
|
|
headers: {
|
|
Accept: 'application/vnd.github+json',
|
|
Authorization: `Bearer ${githubToken}`,
|
|
'X-GitHub-Api-Version': '2022-11-28',
|
|
},
|
|
body: JSON.stringify({ name: branchName }),
|
|
}
|
|
)
|
|
|
|
if (!updateEnvironmentRes.ok) {
|
|
console.error(
|
|
{ status: updateEnvironmentRes.status },
|
|
await updateEnvironmentRes.text()
|
|
)
|
|
throw new Error(`Failed to update environment branch rules`)
|
|
}
|
|
console.log(`Successfully updated deployment environment branch rules`)
|
|
}
|
|
|
|
main()
|