Unverified Commit efaddcda authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix race condition with publish (#51105)

We publish multiple packages in parallel which can cause issues with the
prepublish only script running as turbo clearing/restoring dist caches
can causing files to be missing if a publish is in progress. We also
don't need to run these as all packages are already built prior to
publishing. This also includes fixes for release stats.
parent 2ede8356
...@@ -64,22 +64,20 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) { ...@@ -64,22 +64,20 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
statsConfig.mainRepo = actionInfo.prRepo statsConfig.mainRepo = actionInfo.prRepo
} }
// clone main repository/ref
if (!actionInfo.skipClone) {
await cloneRepo(statsConfig.mainRepo, mainRepoDir, statsConfig.mainBranch)
}
/* eslint-disable-next-line */ /* eslint-disable-next-line */
actionInfo.commitId = await getCommitId(diffRepoDir) actionInfo.commitId = await getCommitId(diffRepoDir)
let mainNextSwcVersion let mainNextSwcVersion
if (!actionInfo.skipClone) { if (!actionInfo.skipClone) {
let mainRef = statsConfig.mainBranch
if (actionInfo.isRelease) { if (actionInfo.isRelease) {
logger('Release detected, resetting mainRepo to last stable tag') logger('Release detected, using last stable tag')
const lastStableTag = await getLastStable(mainRepoDir, actionInfo.prRef) const lastStableTag = await getLastStable(mainRepoDir, actionInfo.prRef)
mainRef = lastStableTag
mainNextSwcVersion = lastStableTag mainNextSwcVersion = lastStableTag
if (!lastStableTag) throw new Error('failed to get last stable tag') if (!lastStableTag) throw new Error('failed to get last stable tag')
console.log('using latestStable', lastStableTag) console.log('using latestStable', lastStableTag)
await checkoutRef(lastStableTag, mainRepoDir)
/* eslint-disable-next-line */ /* eslint-disable-next-line */
actionInfo.lastStableTag = lastStableTag actionInfo.lastStableTag = lastStableTag
...@@ -90,12 +88,15 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) { ...@@ -90,12 +88,15 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
/* eslint-disable-next-line */ /* eslint-disable-next-line */
actionInfo.commentEndpoint = `https://api.github.com/repos/${statsConfig.mainRepo}/commits/${actionInfo.commitId}/comments` actionInfo.commentEndpoint = `https://api.github.com/repos/${statsConfig.mainRepo}/commits/${actionInfo.commitId}/comments`
} }
} else if (statsConfig.autoMergeMain) { }
await cloneRepo(statsConfig.mainRepo, mainRepoDir, mainRef)
if (!actionInfo.isRelease && statsConfig.autoMergeMain) {
logger('Attempting auto merge of main branch') logger('Attempting auto merge of main branch')
await mergeBranch(statsConfig.mainBranch, mainRepoDir, diffRepoDir) await mergeBranch(statsConfig.mainBranch, mainRepoDir, diffRepoDir)
} }
} }
let mainRepoPkgPaths let mainRepoPkgPaths
let diffRepoPkgPaths let diffRepoPkgPaths
......
...@@ -61,6 +61,10 @@ module.exports = function actionInfo() { ...@@ -61,6 +61,10 @@ module.exports = function actionInfo() {
(GITHUB_REF || '').includes('canary'), (GITHUB_REF || '').includes('canary'),
} }
if (info.isRelease) {
info.prRef = 'canary'
}
// get comment // get comment
if (GITHUB_EVENT_PATH) { if (GITHUB_EVENT_PATH) {
const event = require(GITHUB_EVENT_PATH) const event = require(GITHUB_EVENT_PATH)
......
...@@ -3,7 +3,6 @@ const fs = require('fs-extra') ...@@ -3,7 +3,6 @@ const fs = require('fs-extra')
const exec = require('../util/exec') const exec = require('../util/exec')
const { remove } = require('fs-extra') const { remove } = require('fs-extra')
const logger = require('../util/logger') const logger = require('../util/logger')
const semver = require('semver')
const execa = require('execa') const execa = require('execa')
module.exports = (actionInfo) => { module.exports = (actionInfo) => {
...@@ -14,21 +13,16 @@ module.exports = (actionInfo) => { ...@@ -14,21 +13,16 @@ module.exports = (actionInfo) => {
`git clone ${actionInfo.gitRoot}${repoPath} --single-branch --branch ${branch} --depth=${depth} ${dest}` `git clone ${actionInfo.gitRoot}${repoPath} --single-branch --branch ${branch} --depth=${depth} ${dest}`
) )
}, },
async getLastStable(repoDir = '', ref) { async getLastStable(repoDir = '') {
const { stdout } = await exec(`cd ${repoDir} && git tag -l`) const { stdout } = await exec(`cd ${repoDir} && git describe`)
const tags = stdout.trim().split('\n') const tag = stdout.trim()
let lastStableTag
for (let i = tags.length - 1; i >= 0; i--) { if (!tag || !tag.startsWith('v')) {
const curTag = tags[i] throw new Error(`Failed to get tag info ${stdout}`)
// stable doesn't include `-canary` or `-beta`
if (!curTag.includes('-') && !ref.includes(curTag)) {
if (!lastStableTag || semver.gt(curTag, lastStableTag)) {
lastStableTag = curTag
} }
} const tagParts = tag.split('-canary')[0].split('.')
} // last stable tag will always be 1 patch less than canary
return lastStableTag return `${tagParts[0]}.${tagParts[1]}.${Number(tagParts[2]) - 1}`
}, },
async getCommitId(repoDir = '') { async getCommitId(repoDir = '') {
const { stdout } = await exec(`cd ${repoDir} && git rev-parse HEAD`) const { stdout } = await exec(`cd ${repoDir} && git rev-parse HEAD`)
......
...@@ -70,16 +70,6 @@ const cwd = process.cwd() ...@@ -70,16 +70,6 @@ const cwd = process.cwd()
} finally { } finally {
publishSema.release() publishSema.release()
} }
// lerna publish in next step will fail if git status is not clean
await execa(
`git`,
[
'update-index',
'--skip-worktree',
`${path.join(nativePackagesDir, platform, 'package.json')}`,
],
{ stdio: 'inherit' }
)
}) })
) )
...@@ -152,14 +142,6 @@ const cwd = process.cwd() ...@@ -152,14 +142,6 @@ const cwd = process.cwd()
path.join(path.join(cwd, 'packages/next/package.json')), path.join(path.join(cwd, 'packages/next/package.json')),
JSON.stringify(nextPkg, null, 2) JSON.stringify(nextPkg, null, 2)
) )
// lerna publish in next step will fail if git status is not clean
await execa(
'git',
['update-index', '--skip-worktree', 'packages/next/package.json'],
{
stdio: 'inherit',
}
)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
process.exit(1) process.exit(1)
......
...@@ -51,6 +51,7 @@ const cwd = process.cwd() ...@@ -51,6 +51,7 @@ const cwd = process.cwd()
`${path.join(packagesDir, pkg)}`, `${path.join(packagesDir, pkg)}`,
'--access', '--access',
'public', 'public',
'--ignore-scripts',
...(isCanary ? ['--tag', 'canary'] : []), ...(isCanary ? ['--tag', 'canary'] : []),
], ],
{ stdio: 'inherit' } { stdio: 'inherit' }
......
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