Unverified Commit 534d9c14 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[16.2.x] Release pipeline updates (#95160)

Co-authored-by: 's avatarSteven <steven@ceriously.com>
parent 98941fc4
......@@ -3,9 +3,13 @@ name: build-and-deploy
on:
push:
# Don't run when tags or graphite base branches are pushed
# Don't run when graphite base branches are pushed
branches-ignore:
- 'graphite-base/**'
# Run on release tags so publishing is driven by the tag push rather than
# the release-commit branch push (see the deploy-target step).
tags:
- 'v*'
# we need the preview tarball for deploy tests
pull_request:
types: [opened, synchronize]
......@@ -13,8 +17,11 @@ on:
concurrency:
# Limit concurrent runs to 1 per PR,
# but allow concurrent runs on push if they potentially use different source code
group: ${{ github.event_name == 'pull_request' && format('{0}-pr-{1}', github.workflow, github.ref_name) || format('{0}-sha-{1}', github.workflow, github.sha) }}
# but allow concurrent runs on push if they potentially use different source code.
# The push group includes github.ref so that the branch push and tag push of
# the same release commit (same sha) don't share a group -- otherwise the
# skipped branch run could cancel the production tag run.
group: ${{ github.event_name == 'pull_request' && format('{0}-pr-{1}', github.workflow, github.ref_name) || format('{0}-{1}-{2}', github.workflow, github.ref, github.sha) }}
cancel-in-progress: true
env:
......@@ -66,26 +73,34 @@ jobs:
if [[ "$RELEASE_VERSION" == v* ]];
then
echo "value=production" >> $GITHUB_OUTPUT
if [[ "$RELEASE_VERSION" == *-canary.* ]];
if [[ "$GIT_REF" != refs/tags/* ]];
then
RELEASE_ENVIRONMENT="release-canary"
elif [[ "$RELEASE_VERSION" == *-beta.* ]];
then
RELEASE_ENVIRONMENT="release-beta"
elif [[ "$RELEASE_VERSION" == *-rc.* ]];
then
RELEASE_ENVIRONMENT="release-release-candidate"
elif [[ "$RELEASE_VERSION" != *-* ]];
then
RELEASE_ENVIRONMENT="release-stable"
fi
if [[ -z "$RELEASE_ENVIRONMENT" ]];
then
echo "::error::Missing release environment for $RELEASE_VERSION"
exit 1
# The release commit reached a branch (e.g. its push to canary).
# Publishing is driven by the tag push for that same commit, so
# skip here to avoid a duplicate production build on the same sha.
echo "value=skipped" >> $GITHUB_OUTPUT
else
echo "value=production" >> $GITHUB_OUTPUT
if [[ "$RELEASE_VERSION" == *-canary.* ]];
then
RELEASE_ENVIRONMENT="release-canary"
elif [[ "$RELEASE_VERSION" == *-beta.* ]];
then
RELEASE_ENVIRONMENT="release-beta"
elif [[ "$RELEASE_VERSION" == *-rc.* ]];
then
RELEASE_ENVIRONMENT="release-release-candidate"
elif [[ "$RELEASE_VERSION" != *-* ]];
then
RELEASE_ENVIRONMENT="release-stable"
fi
if [[ -z "$RELEASE_ENVIRONMENT" ]];
then
echo "::error::Missing release environment for $RELEASE_VERSION"
exit 1
fi
echo "release_environment=$RELEASE_ENVIRONMENT" >> $GITHUB_OUTPUT
fi
echo "release_environment=$RELEASE_ENVIRONMENT" >> $GITHUB_OUTPUT
elif [ ''"${GIT_REF}"'' == 'refs/heads/next-16-2' ]
then
echo "value=staging" >> $GITHUB_OUTPUT
......@@ -100,8 +115,10 @@ jobs:
fi
env:
GIT_REF: ${{ github.ref }}
- name: Print deploy target
run: echo "Deploy target is '${{ steps.deploy-target.outputs.value }}'"
- name: Print deploy plan
run: |
echo "Deploy target is '${{ steps.deploy-target.outputs.value }}'"
echo "Release environment is '${{ steps.deploy-target.outputs.release_environment }}'"
build:
if: ${{ needs.deploy-target.outputs.value != 'skipped' }}
......@@ -637,10 +654,18 @@ jobs:
repositories: next.js
permission-contents: write
- run: ./scripts/publish-native.js
- run: ./scripts/publish-release.js
env:
RELEASE_GITHUB_TOKEN: ${{ steps.release-app-token.outputs.token }}
BAIL_ON_NATIVE_WASM_PUBLISH_FAILURE: ${{ vars.BAIL_ON_NATIVE_WASM_PUBLISH_FAILURE }}
- name: Upload pnpm publish summary
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pnpm-publish-summary
path: pnpm-publish-summary.json
if-no-files-found: ignore
publish-turbopack-npm-packages:
# Matches the commit message written by turbopack/xtask/src/publish.rs:377
......
......@@ -96,7 +96,7 @@ jobs:
run: echo "LATEST_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Check if new commits since last tag
if: ${{ github.event.inputs.releaseType != 'stable' && github.event.inputs.force != true }}
if: ${{ github.event.inputs.releaseType != 'stable' && inputs.force != true }}
run: |
if [ "$LATEST_TAG_COMMIT" = "$LATEST_COMMIT" ]; then
echo "No new commits. Exiting..."
......
......@@ -33,6 +33,6 @@ The type definitions are generated using the TypeScript [`tsc`](https://www.type
If you are actively working on Rust code or you need to test out the most recent Rust code that hasn't been published as a canary yet, you can [install Rust](https://www.rust-lang.org/tools/install) and run `pnpm swc-build-native`.
If you want to test out the wasm build locally, you will need to [install wasm-pack](https://rustwasm.github.io/wasm-pack/installer/). Run `pnpm --filter=@next/swc build-wasm --target <wasm_target>` to build and `node ./scripts/setup-wasm.mjs` to copy it into your `node_modules`. Run next with `NODE_OPTIONS='--no-addons'` to force it to use the wasm binary.
If you want to test out the wasm build locally, you will need to [install wasm-pack](https://wasm-bindgen.github.io/wasm-pack/installer/). Run `pnpm --filter=@next/swc build-wasm --target <wasm_target>` to build and `node ./scripts/setup-wasm.mjs` to copy it into your `node_modules`. Run next with `NODE_OPTIONS='--no-addons'` to force it to use the wasm binary.
If you need to clean the project for any reason, use `pnpm clean`.
......@@ -86,7 +86,6 @@
"types": "lerna run types --stream",
"types:test-lib": "tsc --project test/lib/tsconfig.json",
"check-precompiled": "./scripts/check-pre-compiled.sh",
"prepublishOnly": "turbo run build",
"lint-staged": "lint-staged",
"next-with-deps": "./scripts/next-with-deps.sh",
"next": "cross-env NEXT_PRIVATE_LOCAL_DEV=1 NEXT_TELEMETRY_DISABLED=1 NODE_OPTIONS=\"--trace-deprecation --enable-source-maps\" next",
......
......@@ -24,7 +24,6 @@
"dev": "ncc build ./index.ts -w -o dist/",
"prebuild": "node ../../scripts/rm.mjs dist",
"build": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"prepublishOnly": "cd ../../ && turbo run build",
"lint-fix": "pnpm prettier -w --plugin prettier-plugin-tailwindcss 'templates/*-tw/{ts,js}/{app,pages}/**/*.{js,ts,tsx}'"
},
"devDependencies": {
......
......@@ -39,8 +39,7 @@
"scripts": {
"dev": "pnpm build",
"build": "swc -d dist src && pnpm types",
"types": "tsc --skipLibCheck --declaration --emitDeclarationOnly --esModuleInterop --declarationDir dist --rootDir src",
"prepublishOnly": "cd ../../ && turbo run build"
"types": "tsc --skipLibCheck --declaration --emitDeclarationOnly --esModuleInterop --declarationDir dist --rootDir src"
},
"exports": {
".": {
......
......@@ -22,7 +22,6 @@
"scripts": {
"dev": "pnpm build",
"build": "swc -d dist src && pnpm types",
"types": "tsc src/index.ts --skipLibCheck --declaration --emitDeclarationOnly --esModuleInterop --declarationDir dist",
"prepublishOnly": "cd ../../ && turbo run build"
"types": "tsc src/index.ts --skipLibCheck --declaration --emitDeclarationOnly --esModuleInterop --declarationDir dist"
}
}
......@@ -15,7 +15,6 @@
"license": "MIT",
"scripts": {
"build": "node ../../scripts/rm.mjs dist && pnpm ncc-fontkit && tsc -d -p tsconfig.build.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "pnpm ncc-fontkit && tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json",
"ncc-fontkit": "ncc build ./fontkit.js --minify -o dist/fontkit"
......
......@@ -29,7 +29,6 @@
],
"scripts": {
"build": "pnpm tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "pnpm tsc -d -w -p tsconfig.json",
"test": "jest",
"test:upgrade-fixture": "./scripts/test-upgrade-fixture.sh"
......
......@@ -25,8 +25,7 @@
"prebuild:source": "node ../../scripts/rm.mjs dist",
"types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"build:source": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"build": "pnpm build:source && pnpm types",
"prepublishOnly": "cd ../../ && turbo run build"
"build": "pnpm build:source && pnpm types"
},
"devDependencies": {
"@vercel/ncc": "0.34.0",
......
......@@ -13,7 +13,6 @@
"license": "MIT",
"scripts": {
"build": "node ../../scripts/rm.mjs dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json"
},
......
......@@ -10,8 +10,7 @@
},
"scripts": {
"build": "microbundle -i src/index.js -o dist/polyfill-module.js -f iife --no-sourcemap --external none --no-pkg-main",
"dev": "pnpm build",
"prepublishOnly": "cd ../../ && turbo run build"
"dev": "pnpm build"
},
"devDependencies": {
"microbundle": "0.15.0"
......
......@@ -10,8 +10,7 @@
},
"scripts": {
"build": "microbundle -i src/index.js -o dist/polyfill-nomodule.js -f iife --no-sourcemap --external none --no-pkg-main",
"dev": "pnpm build",
"prepublishOnly": "cd ../../ && turbo run build"
"dev": "pnpm build"
},
"devDependencies": {
"core-js": "3.38.1",
......
......@@ -27,8 +27,7 @@
"release": "ncc build ./src/index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"build": "pnpm release && pnpm types",
"test": "jest",
"test:watch": "jest --watch",
"prepublishOnly": "cd ../../ && turbo run build"
"test:watch": "jest --watch"
},
"devDependencies": {
"@types/jest": "^29.5.0",
......
......@@ -80,7 +80,6 @@
"scripts": {
"dev": "cross-env NEXT_SERVER_NO_MANGLE=1 taskr",
"build": "taskr release",
"prepublishOnly": "cd ../../ && turbo run build",
"types": "tsc --project tsconfig.build.json --declaration --emitDeclarationOnly --stripInternal --declarationDir dist",
"typescript": "tsec --noEmit",
"ncc-compiled": "taskr ncc",
......
......@@ -13,7 +13,6 @@
"license": "MIT",
"scripts": {
"build": "node ../../scripts/rm.mjs dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json"
},
"peerDependencies": {
......
......@@ -18,7 +18,6 @@
"license": "MIT",
"scripts": {
"build": "node ../../scripts/rm.mjs dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json"
},
......
#!/usr/bin/env node
const path = require('path')
const execa = require('execa')
const { Sema } = require('async-sema')
const { readFile, readdir, writeFile, cp } = require('fs/promises')
const cwd = process.cwd()
;(async function () {
try {
const publishSema = new Sema(2)
let version = require('@next/swc/package.json').version
// Copy binaries to package folders, update version, and publish
let nativePackagesDir = path.join(cwd, 'crates/next-napi-bindings/npm')
let platforms = (await readdir(nativePackagesDir)).filter(
(name) => !name.startsWith('.')
)
await Promise.all(
platforms.map(async (platform) => {
await publishSema.acquire()
let output = ''
try {
let binaryName = `next-swc.${platform}.node`
await cp(
path.join(cwd, 'packages/next-swc/native', binaryName),
path.join(nativePackagesDir, platform, binaryName)
)
let pkg = JSON.parse(
await readFile(
path.join(nativePackagesDir, platform, 'package.json')
)
)
pkg.version = version
await writeFile(
path.join(nativePackagesDir, platform, 'package.json'),
JSON.stringify(pkg, null, 2)
)
const child = execa(
`npm`,
[
`publish`,
`${path.join(nativePackagesDir, platform)}`,
`--access`,
`public`,
...(version.includes('canary') ? ['--tag', 'canary'] : []),
],
{ stdio: 'inherit' }
)
const handleData = (type) => (chunk) => {
process[type].write(chunk)
output += chunk.toString()
}
child.stdout?.on('data', handleData('stdout'))
child.stderr?.on('data', handleData('stderr'))
await child
} catch (err) {
// don't block publishing other versions on single platform error
console.error(`Failed to publish`, platform, err)
if (
output.includes(
'cannot publish over the previously published versions'
)
) {
console.error('Ignoring already published error', platform, err)
} else {
// throw err
}
} finally {
publishSema.release()
}
})
)
// Update name/version of wasm packages and publish
const pkgDirectory = 'crates/wasm'
let wasmDir = path.join(cwd, pkgDirectory)
await Promise.all(
['web', 'nodejs'].map(async (wasmTarget) => {
await publishSema.acquire()
let wasmPkg = JSON.parse(
await readFile(path.join(wasmDir, `pkg-${wasmTarget}/package.json`))
)
wasmPkg.name = `@next/swc-wasm-${wasmTarget}`
wasmPkg.version = version
wasmPkg.repository = {
type: 'git',
url: 'https://github.com/vercel/next.js',
directory: pkgDirectory,
}
await writeFile(
path.join(wasmDir, `pkg-${wasmTarget}/package.json`),
JSON.stringify(wasmPkg, null, 2)
)
try {
await execa(
`npm`,
[
'publish',
`${path.join(wasmDir, `pkg-${wasmTarget}`)}`,
'--access',
'public',
...(version.includes('canary') ? ['--tag', 'canary'] : []),
],
{ stdio: 'inherit' }
)
} catch (err) {
// don't block publishing other versions on single platform error
console.error(`Failed to publish`, wasmTarget, err)
if (
err.message &&
err.message.includes(
'You cannot publish over the previously published versions'
)
) {
console.error('Ignoring already published error', wasmTarget)
} else {
// throw err
}
} finally {
publishSema.release()
}
})
)
// Update optional dependencies versions
let nextPkg = JSON.parse(
await readFile(path.join(cwd, 'packages/next/package.json'))
)
for (let platform of platforms) {
let optionalDependencies = nextPkg.optionalDependencies || {}
optionalDependencies['@next/swc-' + platform] = version
nextPkg.optionalDependencies = optionalDependencies
}
await writeFile(
path.join(path.join(cwd, 'packages/next/package.json')),
JSON.stringify(nextPkg, null, 2)
)
} catch (err) {
console.error(err)
process.exit(1)
}
})()
This diff is collapsed.
......@@ -19,6 +19,7 @@ async function main() {
const isCanary = releaseType === 'canary'
const isReleaseCandidate = releaseType === 'release-candidate'
const isBeta = releaseType === 'beta'
const dryRun = args.includes('--dry-run')
if (
releaseType !== 'stable' &&
......@@ -42,26 +43,32 @@ async function main() {
const githubToken = getGitHubToken()
if (!githubToken) {
console.log(getGitHubTokenMissingMessage())
return
}
const configStorePath = resolveFrom(
path.join(process.cwd(), 'node_modules/release'),
'configstore'
)
const ConfigStore = require(configStorePath)
if (dryRun) {
console.log(
'Dry run: keeping commits locally, skipping git push and GitHub release creation'
)
} else {
if (!githubToken) {
console.log(getGitHubTokenMissingMessage())
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)
const config = new ConfigStore('release')
config.set('token', githubToken)
await configureGitHubAuth(githubToken)
await verifyGitHubApiAccess(
githubToken,
'/repos/vercel/next.js/releases?per_page=1',
'release lookup'
)
await configureGitHubAuth(githubToken)
await verifyGitHubApiAccess(
githubToken,
'/repos/vercel/next.js/releases?per_page=1',
'release lookup'
)
}
console.log(`Running pnpm release-${isCanary ? 'canary' : 'stable'}...`)
const preleaseType =
......@@ -87,24 +94,36 @@ async function main() {
lernaArgs.push('--force-publish', '-y', '--no-push')
if (dryRun) {
// So the dry-run can be exercised outside
// of the release branches lerna.json restricts in real publishes.
lernaArgs.push('--allow-branch', '**')
}
const child = execa('pnpm', lernaArgs, {
stdio: 'inherit',
})
await child
await createGitHubReleaseCommit(githubToken)
if (isCanary || isReleaseCandidate || isBeta) {
const releaseChild = execa(
'pnpm',
['release', '--pre', '--skip-questions', '--show-url'],
{
stdio: 'inherit',
}
if (dryRun) {
console.log(
'Dry run: skipping GitHub-signed release commit and GitHub release creation'
)
await releaseChild
} else {
await createGitHubReleaseCommit(githubToken)
if (isCanary || isReleaseCandidate || isBeta) {
const releaseChild = execa(
'pnpm',
['release', '--pre', '--skip-questions', '--show-url'],
{
stdio: 'inherit',
}
)
await releaseChild
}
}
console.log('Release process is finished')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment