[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
pull/3053/head
David Sheldrick 2024-03-04 09:39:19 +00:00 zatwierdzone przez GitHub
rodzic 8658e20ab5
commit 9ae808c12c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 8 dodań i 30 usunięć

Wyświetl plik

@ -103,7 +103,7 @@ function topologicalSortPackages(packages: Record<string, PackageDetails>) {
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) => {

Wyświetl plik

@ -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()