Fix publishing (#1338)

Automated package publish had gotten broken because we lost all our git
tags/releases. We fixed that, but also:
* made releases come from huppy instead of david
* swtiched from node's `execSync` to our `exec` for more debuggable
output
* cleaned up some of the scripts a little

this diff has a lot of whitespace changes so you're best off reviewing
it with whitespace changes hidden:
https://github.com/tldraw/tldraw/pull/1338/files?diff=split&w=1
This commit is contained in:
alex 2023-05-09 14:25:56 +01:00 committed by GitHub
parent 2a36d6342c
commit a8910e5491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 74 deletions

View file

@ -1,69 +1,66 @@
import { Auto } from '@auto-it/core'
import { execSync } from 'child_process'
import { parse } from 'semver'
import { pathToFileURL } from 'url'
import { exec } from './lib/exec'
import { getLatestVersion, publish, setAllVersions } from './lib/publishing'
const auto = new Auto({
plugins: ['npm'],
baseBranch: 'main',
owner: 'tldraw',
repo: 'tldraw-lite',
verbose: true,
})
async function main() {
const auto = new Auto({
plugins: ['npm'],
baseBranch: 'main',
owner: 'tldraw',
repo: 'tldraw-lite',
verbose: true,
})
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
// module was called directly
const currentBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
const currentBranch = (await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).toString().trim()
if (currentBranch !== 'main') {
throw new Error('Must be on main branch to publish')
}
;(async () => {
await auto.loadConfig()
const bump = await auto.getVersion()
if (!bump) {
console.log('nothing to do')
return
}
await auto.loadConfig()
const bump = await auto.getVersion()
if (!bump) {
console.log('nothing to do')
return
}
const latestVersion = parse(getLatestVersion())!
const latestVersion = parse(getLatestVersion())!
console.log('latestVersion', latestVersion)
console.log('latestVersion', latestVersion)
const [prereleaseTag, prereleaseNumber] = latestVersion.prerelease
if (prereleaseTag && typeof prereleaseNumber !== 'number') {
throw new Error(
`Invalid prerelease format in version ${latestVersion}, expected e.g. -alpha.1`
)
}
const [prereleaseTag, prereleaseNumber] = latestVersion.prerelease
if (prereleaseTag && typeof prereleaseNumber !== 'number') {
throw new Error(`Invalid prerelease format in version ${latestVersion}, expected e.g. -alpha.1`)
}
// if we're in prerelease mode, don't bump the version, only the prerelease number
const nextVersion = prereleaseTag
? `${latestVersion.major}.${latestVersion.minor}.${latestVersion.patch}-${prereleaseTag}.${
Number(prereleaseNumber) + 1
}`
: latestVersion.inc(bump).format()
// if we're in prerelease mode, don't bump the version, only the prerelease number
const nextVersion = prereleaseTag
? `${latestVersion.major}.${latestVersion.minor}.${latestVersion.patch}-${prereleaseTag}.${
Number(prereleaseNumber) + 1
}`
: latestVersion.inc(bump).format()
setAllVersions(nextVersion)
setAllVersions(nextVersion)
// stage the changes
execSync('git add lerna.json bublic/packages/*/package.json', { stdio: 'inherit' })
// stage the changes
await exec('git', ['add', 'lerna.json', 'bublic/packages/*/package.json'])
// this creates a new commit
await auto.changelog({
useVersion: nextVersion,
title: `v${nextVersion}`,
})
// this creates a new commit
await auto.changelog({
useVersion: nextVersion,
title: `v${nextVersion}`,
})
// create and push a new tag
execSync(`git tag -f v${nextVersion}`, { stdio: 'inherit' })
execSync('git push --follow-tags', { stdio: 'inherit' })
// create and push a new tag
await exec('git', ['tag', '-f', `v${nextVersion}`])
await exec('git', ['push', '--follow-tags'])
// create a release on github
await auto.runRelease({ useVersion: nextVersion })
// create a release on github
await auto.runRelease({ useVersion: nextVersion })
// finally, publish the packages [IF THIS STEP FAILS, RUN THE `publish-manual.ts` script locally]
await publish()
})()
// finally, publish the packages [IF THIS STEP FAILS, RUN THE `publish-manual.ts` script locally]
await publish()
}
main()