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) {
statsConfig.mainRepo = actionInfo.prRepo
}
// clone main repository/ref
if (!actionInfo.skipClone) {
await cloneRepo(statsConfig.mainRepo, mainRepoDir, statsConfig.mainBranch)
}
/* eslint-disable-next-line */
actionInfo.commitId = await getCommitId(diffRepoDir)
let mainNextSwcVersion
if (!actionInfo.skipClone) {
let mainRef = statsConfig.mainBranch
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)
mainRef = lastStableTag
mainNextSwcVersion = lastStableTag
if (!lastStableTag) throw new Error('failed to get last stable tag')
console.log('using latestStable', lastStableTag)
await checkoutRef(lastStableTag, mainRepoDir)
/* eslint-disable-next-line */
actionInfo.lastStableTag = lastStableTag
......@@ -90,12 +88,15 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
/* eslint-disable-next-line */
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')
await mergeBranch(statsConfig.mainBranch, mainRepoDir, diffRepoDir)
}
}
let mainRepoPkgPaths
let diffRepoPkgPaths
......
......@@ -61,6 +61,10 @@ module.exports = function actionInfo() {
(GITHUB_REF || '').includes('canary'),
}
if (info.isRelease) {
info.prRef = 'canary'
}
// get comment
if (GITHUB_EVENT_PATH) {
const event = require(GITHUB_EVENT_PATH)
......
......@@ -3,7 +3,6 @@ const fs = require('fs-extra')
const exec = require('../util/exec')
const { remove } = require('fs-extra')
const logger = require('../util/logger')
const semver = require('semver')
const execa = require('execa')
module.exports = (actionInfo) => {
......@@ -14,21 +13,16 @@ module.exports = (actionInfo) => {
`git clone ${actionInfo.gitRoot}${repoPath} --single-branch --branch ${branch} --depth=${depth} ${dest}`
)
},
async getLastStable(repoDir = '', ref) {
const { stdout } = await exec(`cd ${repoDir} && git tag -l`)
const tags = stdout.trim().split('\n')
let lastStableTag
async getLastStable(repoDir = '') {
const { stdout } = await exec(`cd ${repoDir} && git describe`)
const tag = stdout.trim()
for (let i = tags.length - 1; i >= 0; i--) {
const curTag = tags[i]
// stable doesn't include `-canary` or `-beta`
if (!curTag.includes('-') && !ref.includes(curTag)) {
if (!lastStableTag || semver.gt(curTag, lastStableTag)) {
lastStableTag = curTag
}
}
if (!tag || !tag.startsWith('v')) {
throw new Error(`Failed to get tag info ${stdout}`)
}
return lastStableTag
const tagParts = tag.split('-canary')[0].split('.')
// last stable tag will always be 1 patch less than canary
return `${tagParts[0]}.${tagParts[1]}.${Number(tagParts[2]) - 1}`
},
async getCommitId(repoDir = '') {
const { stdout } = await exec(`cd ${repoDir} && git rev-parse HEAD`)
......
......@@ -70,16 +70,6 @@ const cwd = process.cwd()
} finally {
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()
path.join(path.join(cwd, 'packages/next/package.json')),
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) {
console.error(err)
process.exit(1)
......
......@@ -51,6 +51,7 @@ const cwd = process.cwd()
`${path.join(packagesDir, pkg)}`,
'--access',
'public',
'--ignore-scripts',
...(isCanary ? ['--tag', 'canary'] : []),
],
{ 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