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

[cd] Move release un-draft to a follow-up job (#100571)

Follow-up to #100121. `publishRelease` no longer mints an App token at
all.

Un-drafting the GitHub release must stay authenticated as the release
App: events caused by `GITHUB_TOKEN` do not trigger workflow runs, and
release-published automations depend on the event. Previously that meant
the bot key had to be available to the `publishRelease` job. With this
change a small `undraftRelease` job runs in `bot-autonomous` instead,
after the gated publish succeeded (the tag is already trusted at that
point), so the key never leaves the two `bot-*` environments.

Backports: #100572 (`releases/lts/active`), #100573
(`releases/lts/maintenance`) — their publish scripts read `lerna.json`,
so the script is adapted there.

---------
Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
parent 684cf7ea
......@@ -672,10 +672,62 @@ jobs:
merge-multiple: true
path: crates/wasm
# Un-drafting the GitHub release must stay authenticated as the bot:
# events caused by GITHUB_TOKEN (github-actions[bot]) do not trigger
# workflow runs, and release-published automations depend on the event.
# The key comes from this job's release-* environment secret.
- run: ./scripts/publish-release.js
env:
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
undraftRelease:
name: Un-draft GitHub release
needs:
- deploy-target
- publishRelease
# Only prerelease channels get a draft GitHub release. The un-draft runs
# after the gated publish, so the tag is already trusted.
if: ${{ needs.publishRelease.result == 'success' && needs.deploy-target.outputs.release_environment != 'release-stable' }}
runs-on: ubuntu-latest
environment: bot-autonomous
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version
check-latest: true
package-manager-cache: false
- name: Setup corepack
run: |
npm i -g "corepack@${COREPACK_VERSION}"
corepack enable
- id: get-store-path
run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
timeout-minutes: 5
id: cache-pnpm-store
with:
path: ${{ steps.get-store-path.outputs.STORE_PATH }}
key: pnpm-store-root-v1-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
# Do not use restore-keys since it leads to indefinite growth of the cache.
- name: Install dependencies
# Just need scripts/ but those dependencies are listed in the workspace root.
run: pnpm install --filter .
- name: Create GitHub App token
id: release-app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
......@@ -686,18 +738,9 @@ jobs:
repositories: next.js
permission-contents: write
- run: ./scripts/publish-release.js
- run: node ./scripts/undraft-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
reportPublishFailure:
name: report publish failure to slack
......
......@@ -6,10 +6,6 @@ const execa = require('execa')
const semver = require('semver')
const { Sema } = require('async-sema')
const fs = require('fs/promises')
const {
getGitHubToken,
getGitHubTokenMissingMessage,
} = require('./release-github-auth')
const { readReleaseVersion } = require('./release-version')
const cwd = process.cwd()
......@@ -295,75 +291,6 @@ const publishRetryDelaySeconds = 15
npmDistTag,
...(dryRun ? ['--dry-run'] : []),
])
if (dryRun) {
console.log('Dry run: skipping GitHub release un-draft')
return
}
const githubToken = getGitHubToken()
if (!githubToken) {
throw new Error(getGitHubTokenMissingMessage())
}
if (isPrerelease) {
try {
const ghHeaders = {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${githubToken}`,
'X-GitHub-Api-Version': '2022-11-28',
}
const tag = `v${version}`
let release
let releasesData
// The release might take a minute to show up in
// the list so retry a bit
for (let i = 0; i < 6; i++) {
try {
const releaseUrlRes = await fetch(
`https://api.github.com/repos/vercel/next.js/releases`,
{
headers: ghHeaders,
}
)
releasesData = await releaseUrlRes.json()
release = releasesData.find((release) => release.tag_name === tag)
} catch (err) {
console.log(`Fetching release failed`, err)
}
if (!release) {
console.log(`Retrying in 10s...`)
await new Promise((resolve) => setTimeout(resolve, 10 * 1000))
}
}
if (!release) {
console.log(`Failed to find release`, releasesData)
return
}
const undraftRes = await fetch(release.url, {
headers: ghHeaders,
method: 'PATCH',
body: JSON.stringify({
draft: false,
name: tag,
}),
})
if (undraftRes.ok) {
console.log(`un-drafted ${prereleaseChannel} release successfully`)
} else {
console.log(`Failed to undraft`, await undraftRes.text())
}
} catch (err) {
console.error(`Failed to undraft release`, err)
}
}
})().catch((err) => {
console.error(err)
process.exit(1)
......
#!/usr/bin/env node
// @ts-check
const semver = require('semver')
const {
getGitHubToken,
getGitHubTokenMissingMessage,
} = require('./release-github-auth')
const { readReleaseVersion } = require('./release-version')
;(async function () {
const version = readReleaseVersion()
const parsedVersion = semver.parse(version)
if (parsedVersion === null) {
throw new Error(`Invalid version: ${version}`)
}
const { prerelease } = parsedVersion
const isPrerelease = prerelease.length > 0
if (!isPrerelease) {
console.log('Not a prerelease: nothing to un-draft')
return
}
const prereleaseChannel = prerelease[0]
const githubToken = getGitHubToken()
if (!githubToken) {
throw new Error(getGitHubTokenMissingMessage())
}
try {
const ghHeaders = {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${githubToken}`,
'X-GitHub-Api-Version': '2022-11-28',
}
const tag = `v${version}`
let release
let releasesData
// The release might take a minute to show up in
// the list so retry a bit
for (let i = 0; i < 6; i++) {
try {
const releaseUrlRes = await fetch(
`https://api.github.com/repos/vercel/next.js/releases`,
{
headers: ghHeaders,
}
)
releasesData = await releaseUrlRes.json()
release = releasesData.find((release) => release.tag_name === tag)
} catch (err) {
console.log(`Fetching release failed`, err)
}
if (!release) {
console.log(`Retrying in 10s...`)
await new Promise((resolve) => setTimeout(resolve, 10 * 1000))
}
}
if (!release) {
console.log(`Failed to find release`, releasesData)
return
}
const undraftRes = await fetch(release.url, {
headers: ghHeaders,
method: 'PATCH',
body: JSON.stringify({
draft: false,
name: tag,
}),
})
if (undraftRes.ok) {
console.log(`un-drafted ${prereleaseChannel} release successfully`)
} else {
console.log(`Failed to undraft`, await undraftRes.text())
}
} catch (err) {
console.error(`Failed to undraft release`, err)
}
})().catch((err) => {
console.error(err)
process.exit(1)
})
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