[infra] fix canary dist tag (#3048)

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
This commit is contained in:
David Sheldrick 2024-03-04 09:39:19 +00:00 committed by GitHub
parent 8658e20ab5
commit 9ae808c12c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 30 deletions

View file

@ -103,7 +103,7 @@ function topologicalSortPackages(packages: Record<string, PackageDetails>) {
return sorted return sorted
} }
export async function publish() { export async function publish(distTag?: string) {
const npmToken = process.env.NPM_TOKEN const npmToken = process.env.NPM_TOKEN
if (!npmToken) { if (!npmToken) {
throw new Error('NPM_TOKEN not set') throw new Error('NPM_TOKEN not set')
@ -117,9 +117,9 @@ export async function publish() {
const publishOrder = topologicalSortPackages(packages) const publishOrder = topologicalSortPackages(packages)
for (const packageDetails of publishOrder) { for (const packageDetails of publishOrder) {
const prereleaseTag = parse(packageDetails.version)?.prerelease[0] ?? 'latest' const tag = distTag ?? parse(packageDetails.version)?.prerelease[0] ?? 'latest'
nicelog( nicelog(
`Publishing ${packageDetails.name} with version ${packageDetails.version} under tag @${prereleaseTag}` `Publishing ${packageDetails.name} with version ${packageDetails.version} under tag @${tag}`
) )
await retry( await retry(
@ -128,15 +128,7 @@ export async function publish() {
try { try {
await exec( await exec(
`yarn`, `yarn`,
[ ['npm', 'publish', '--tag', String(tag), '--tolerate-republish', '--access', 'public'],
'npm',
'publish',
'--tag',
String(prereleaseTag),
'--tolerate-republish',
'--access',
'public',
],
{ {
pwd: packageDetails.dir, pwd: packageDetails.dir,
processStdoutLine: (line) => { processStdoutLine: (line) => {

View file

@ -1,39 +1,25 @@
import { exec } from './lib/exec' import { exec } from './lib/exec'
import { nicelog } from './lib/nicelog'
import { getLatestVersion, publish, setAllVersions } from './lib/publishing' import { getLatestVersion, publish, setAllVersions } from './lib/publishing'
async function main() { async function main() {
const sha = (await exec('git', ['rev-parse', 'HEAD'])).trim().slice(0, 12) 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 latestVersion = await getLatestVersion()
const nextVersion = latestVersion.prerelease.length 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 ? // if the package is in prerelease mode, we want to release a canary for the current version rather than bumping
latestVersion latestVersion
: latestVersion?.inc(bump) : latestVersion?.inc('minor')
const versionString = `${nextVersion.major}.${nextVersion.minor}.${nextVersion.patch}-canary.${sha}` const versionString = `${nextVersion.major}.${nextVersion.minor}.${nextVersion.patch}-canary.${sha}`
await setAllVersions(versionString) await setAllVersions(versionString)
} }
// module was called directly // module was called directly
const bumpType = (await exec('npx', ['auto', 'version'])).trim() as
| 'major'
| 'minor'
| 'patch'
| ''
nicelog('bumpType', bumpType) setCanaryVersions()
if (bumpType === '') { publish('canary')
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')
}
} }
main() main()