From 9ae808c12c85bf6ec35cc89f4dbb5de85198a82c Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Mon, 4 Mar 2024 09:39:19 +0000 Subject: [PATCH] [infra] fix canary dist tag (#3048) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some of the tooling changes we made last week made it so that canary releases were being published with the `latest` dist tag. This should prevent that from happening, and I also fixed all the current packages to set `latest` back to 2.0.0 ### Change Type - [ ] `patch` — Bug fix - [ ] `minor` — New feature - [ ] `major` — Breaking change - [ ] `dependencies` — Changes to package dependencies[^1] - [ ] `documentation` — Changes to the documentation only[^2] - [ ] `tests` — Changes to any test code only[^2] - [x] `internal` — Any other changes that don't affect the published package[^2] - [ ] I don't know [^1]: publishes a `patch` release, for devDependencies use `internal` [^2]: will not publish a new version --- scripts/lib/publishing.ts | 16 ++++------------ scripts/publish-canary.ts | 22 ++++------------------ 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/scripts/lib/publishing.ts b/scripts/lib/publishing.ts index d0f4027a1..6dbb3b186 100644 --- a/scripts/lib/publishing.ts +++ b/scripts/lib/publishing.ts @@ -103,7 +103,7 @@ function topologicalSortPackages(packages: Record) { return sorted } -export async function publish() { +export async function publish(distTag?: string) { const npmToken = process.env.NPM_TOKEN if (!npmToken) { throw new Error('NPM_TOKEN not set') @@ -117,9 +117,9 @@ export async function publish() { const publishOrder = topologicalSortPackages(packages) for (const packageDetails of publishOrder) { - const prereleaseTag = parse(packageDetails.version)?.prerelease[0] ?? 'latest' + const tag = distTag ?? parse(packageDetails.version)?.prerelease[0] ?? 'latest' nicelog( - `Publishing ${packageDetails.name} with version ${packageDetails.version} under tag @${prereleaseTag}` + `Publishing ${packageDetails.name} with version ${packageDetails.version} under tag @${tag}` ) await retry( @@ -128,15 +128,7 @@ export async function publish() { try { await exec( `yarn`, - [ - 'npm', - 'publish', - '--tag', - String(prereleaseTag), - '--tolerate-republish', - '--access', - 'public', - ], + ['npm', 'publish', '--tag', String(tag), '--tolerate-republish', '--access', 'public'], { pwd: packageDetails.dir, processStdoutLine: (line) => { diff --git a/scripts/publish-canary.ts b/scripts/publish-canary.ts index 21b370bcc..845801200 100644 --- a/scripts/publish-canary.ts +++ b/scripts/publish-canary.ts @@ -1,39 +1,25 @@ import { exec } from './lib/exec' -import { nicelog } from './lib/nicelog' import { getLatestVersion, publish, setAllVersions } from './lib/publishing' async function main() { const sha = (await exec('git', ['rev-parse', 'HEAD'])).trim().slice(0, 12) - async function setCanaryVersions(bump: 'major' | 'minor' | 'patch') { + async function setCanaryVersions() { const latestVersion = await getLatestVersion() const nextVersion = latestVersion.prerelease.length ? // if the package is in prerelease mode, we want to release a canary for the current version rather than bumping latestVersion - : latestVersion?.inc(bump) + : latestVersion?.inc('minor') const versionString = `${nextVersion.major}.${nextVersion.minor}.${nextVersion.patch}-canary.${sha}` await setAllVersions(versionString) } // module was called directly - const bumpType = (await exec('npx', ['auto', 'version'])).trim() as - | 'major' - | 'minor' - | 'patch' - | '' - nicelog('bumpType', bumpType) - if (bumpType === '') { - nicelog('nothing to do') - } else if (['major', 'minor', 'patch'].includes(bumpType)) { - nicelog('setting canary versions') - setCanaryVersions(bumpType) - publish() - } else { - throw new Error('Invalid bump type provided') - } + setCanaryVersions() + publish('canary') } main()