Skip to content

[release-legacy] fix: set stable dist tag for backport releases instead of latest #79596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions scripts/publish-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const path = require('path')
const execa = require('execa')
const semver = require('semver')
const { Sema } = require('async-sema')
const { execSync } = require('child_process')
const fs = require('fs')
Expand Down Expand Up @@ -32,6 +33,34 @@ const cwd = process.cwd()
}
throw err
}

let tag = isCanary ? 'canary' : isReleaseCandidate ? 'rc' : 'latest'

try {
if (!isCanary && !isReleaseCandidate) {
const version = JSON.parse(
await fs.promises.readFile(path.join(cwd, 'lerna.json'), 'utf-8')
).version

const res = await fetch(
`https://registry.npmjs.org/-/package/next/dist-tags`
)
const tags = await res.json()

if (semver.lt(version, tags.latest)) {
// If the current version is less than the latest, it means this
// is a backport release. Since NPM sets the 'latest' tag by default
// during publishing, when users install `next@latest`, they might
// get the backported version instead of the actual "latest" version.
// Therefore, we explicitly set the tag as 'stable' for backports.
tag = 'stable'
}
}
} catch (error) {
console.log('Failed to fetch Next.js dist tags from the NPM registry.')
throw error
}

console.log(
`Publishing ${isCanary ? 'canary' : isReleaseCandidate ? 'rc' : 'stable'}`
)
Expand All @@ -57,11 +86,7 @@ const cwd = process.cwd()
'--access',
'public',
'--ignore-scripts',
...(isCanary
? ['--tag', 'canary']
: isReleaseCandidate
? ['--tag', 'rc']
: []),
['--tag', tag],
],
{ stdio: 'pipe' }
)
Expand Down
Loading