Skip to content

Commit

Permalink
Fix race condition with publish (#51105)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ijjk committed Jun 10, 2023
1 parent 2ede835 commit efaddcd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 40 deletions.
17 changes: 9 additions & 8 deletions .github/actions/next-stats-action/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions .github/actions/next-stats-action/src/prepare/action-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 8 additions & 14 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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`)
Expand Down
18 changes: 0 additions & 18 deletions scripts/publish-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
)
})
)

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions scripts/publish-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const cwd = process.cwd()
`${path.join(packagesDir, pkg)}`,
'--access',
'public',
'--ignore-scripts',
...(isCanary ? ['--tag', 'canary'] : []),
],
{ stdio: 'inherit' }
Expand Down

0 comments on commit efaddcd

Please sign in to comment.