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

[cd] Publish preview release with `@preview` NPM dist-tag (#94619)

parent db6f8645
...@@ -2,17 +2,82 @@ ...@@ -2,17 +2,82 @@
const path = require('path') const path = require('path')
const execa = require('execa') const execa = require('execa')
const semver = require('semver')
const { Sema } = require('async-sema') const { Sema } = require('async-sema')
const { execSync } = require('child_process')
const fs = require('fs')
const { readFile, readdir, writeFile, cp } = require('fs/promises') const { readFile, readdir, writeFile, cp } = require('fs/promises')
const cwd = process.cwd() const cwd = process.cwd()
;(async function () { ;(async function () {
let isCanary = true
let isReleaseCandidate = false
let isBeta = false
let isPreview = false
try {
const tagOutput = execSync(
`node ${path.join(__dirname, 'check-is-release.js')}`
).toString()
console.log(tagOutput)
if (tagOutput.trim().startsWith('v')) {
isCanary = tagOutput.includes('-canary')
}
isReleaseCandidate = tagOutput.includes('-rc')
isBeta = tagOutput.includes('-beta')
isPreview = tagOutput.includes('-preview')
} catch (err) {
console.log(err)
if (err.message && err.message.includes('no tag exactly matches')) {
console.log('Nothing to publish, exiting...')
return
}
throw err
}
try { try {
const publishSema = new Sema(2) const publishSema = new Sema(2)
let version = require('@next/swc/package.json').version let version = require('@next/swc/package.json').version
let tag = isCanary
? 'canary'
: isReleaseCandidate
? 'rc'
: isBeta
? 'beta'
: isPreview
? 'preview'
: 'latest'
try {
if (!isCanary && !isReleaseCandidate && !isBeta && !isPreview) {
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 'backport' for backports.
tag = 'backport'
}
}
} catch (error) {
console.log('Failed to fetch Next.js dist tags from the NPM registry.')
throw error
}
// Copy binaries to package folders, update version, and publish // Copy binaries to package folders, update version, and publish
let nativePackagesDir = path.join(cwd, 'crates/next-napi-bindings/npm') let nativePackagesDir = path.join(cwd, 'crates/next-napi-bindings/npm')
let platforms = (await readdir(nativePackagesDir)).filter( let platforms = (await readdir(nativePackagesDir)).filter(
...@@ -47,7 +112,8 @@ const cwd = process.cwd() ...@@ -47,7 +112,8 @@ const cwd = process.cwd()
`${path.join(nativePackagesDir, platform)}`, `${path.join(nativePackagesDir, platform)}`,
`--access`, `--access`,
`public`, `public`,
...(version.includes('canary') ? ['--tag', 'canary'] : []), '--tag',
tag,
], ],
{ stdio: 'inherit' } { stdio: 'inherit' }
) )
......
...@@ -18,6 +18,7 @@ const cwd = process.cwd() ...@@ -18,6 +18,7 @@ const cwd = process.cwd()
let isCanary = true let isCanary = true
let isReleaseCandidate = false let isReleaseCandidate = false
let isBeta = false let isBeta = false
let isPreview = false
try { try {
const tagOutput = execSync( const tagOutput = execSync(
...@@ -30,6 +31,7 @@ const cwd = process.cwd() ...@@ -30,6 +31,7 @@ const cwd = process.cwd()
} }
isReleaseCandidate = tagOutput.includes('-rc') isReleaseCandidate = tagOutput.includes('-rc')
isBeta = tagOutput.includes('-beta') isBeta = tagOutput.includes('-beta')
isPreview = tagOutput.includes('-preview')
} catch (err) { } catch (err) {
console.log(err) console.log(err)
...@@ -46,10 +48,12 @@ const cwd = process.cwd() ...@@ -46,10 +48,12 @@ const cwd = process.cwd()
? 'rc' ? 'rc'
: isBeta : isBeta
? 'beta' ? 'beta'
: 'latest' : isPreview
? 'preview'
: 'latest'
try { try {
if (!isCanary && !isReleaseCandidate && !isBeta) { if (!isCanary && !isReleaseCandidate && !isBeta && !isPreview) {
const version = JSON.parse( const version = JSON.parse(
await fs.promises.readFile(path.join(cwd, 'lerna.json'), 'utf-8') await fs.promises.readFile(path.join(cwd, 'lerna.json'), 'utf-8')
).version ).version
......
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