From efaddcda60988453b33247414714fe1b48138d99 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sat, 10 Jun 2023 14:05:27 -0700 Subject: [PATCH] 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. --- .../actions/next-stats-action/src/index.js | 17 +++++++------- .../src/prepare/action-info.js | 4 ++++ .../src/prepare/repo-setup.js | 22 +++++++------------ scripts/publish-native.js | 18 --------------- scripts/publish-release.js | 1 + 5 files changed, 22 insertions(+), 40 deletions(-) diff --git a/.github/actions/next-stats-action/src/index.js b/.github/actions/next-stats-action/src/index.js index 56a80d5b40b56..2230ae71ae170 100644 --- a/.github/actions/next-stats-action/src/index.js +++ b/.github/actions/next-stats-action/src/index.js @@ -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 diff --git a/.github/actions/next-stats-action/src/prepare/action-info.js b/.github/actions/next-stats-action/src/prepare/action-info.js index 83aa1deea8005..1dbfc3f785919 100644 --- a/.github/actions/next-stats-action/src/prepare/action-info.js +++ b/.github/actions/next-stats-action/src/prepare/action-info.js @@ -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) diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 1da820c0c8275..5edf6865d387a 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -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`) diff --git a/scripts/publish-native.js b/scripts/publish-native.js index 1536484744750..c3c77bc157a1f 100755 --- a/scripts/publish-native.js +++ b/scripts/publish-native.js @@ -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) diff --git a/scripts/publish-release.js b/scripts/publish-release.js index 42da412bf183f..dc815bb06c4f3 100755 --- a/scripts/publish-release.js +++ b/scripts/publish-release.js @@ -51,6 +51,7 @@ const cwd = process.cwd() `${path.join(packagesDir, pkg)}`, '--access', 'public', + '--ignore-scripts', ...(isCanary ? ['--tag', 'canary'] : []), ], { stdio: 'inherit' }