Implement new package publish process (#2996)

Gonna merge in a sneaky dry run mode to test the args parsing etc
### 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

### Test Plan

1. Add a step-by-step description of how to test your PR here.
2.

- [ ] Unit Tests
- [ ] End to end tests

### Release Notes

- Add a brief release note for your PR here.
This commit is contained in:
David Sheldrick 2024-02-29 12:21:11 +00:00 committed by GitHub
parent 83423cd6d7
commit 6d4b46e6d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 100 additions and 27 deletions

View file

@ -1,37 +1,41 @@
import { Auto } from '@auto-it/core'
import fetch from 'cross-fetch'
import minimist from 'minimist'
import { assert } from 'node:console'
import { parse } from 'semver'
import { SemVer, parse } from 'semver'
import { exec } from './lib/exec'
import { REPO_ROOT } from './lib/file'
import { nicelog } from './lib/nicelog'
import { getLatestVersion, publish, setAllVersions } from './lib/publishing'
import { getAllWorkspacePackages } from './lib/workspace'
async function main() {
const huppyToken = process.env.HUPPY_TOKEN
assert(huppyToken && typeof huppyToken === 'string', 'HUPPY_ACCESS_KEY env var must be set')
type ReleaseType =
| {
bump: 'major' | 'minor'
}
| {
bump: 'override'
version: SemVer
}
const auto = new Auto({
plugins: ['npm'],
baseBranch: 'main',
owner: 'tldraw',
repo: 'tldraw',
verbose: true,
disableTsNode: true,
})
// module was called directly
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')
function getReleaseType(): ReleaseType {
const arg = minimist(process.argv.slice(2))['bump']
if (!arg) {
throw new Error('Must provide a --bump argument')
}
if (arg === 'major' || arg === 'minor') {
return { bump: arg }
}
const parsed = parse(arg)
if (parsed) {
return { bump: 'override', version: parsed }
}
throw new Error('Invalid bump argument ' + JSON.stringify(arg))
}
await auto.loadConfig()
const bump = await auto.getVersion()
if (!bump) {
nicelog('nothing to do')
return
function getNextVersion(releaseType: ReleaseType): string {
if (releaseType.bump === 'override') {
return releaseType.version.format()
}
const latestVersion = parse(getLatestVersion())!
@ -48,7 +52,25 @@ async function main() {
? `${latestVersion.major}.${latestVersion.minor}.${latestVersion.patch}-${prereleaseTag}.${
Number(prereleaseNumber) + 1
}`
: latestVersion.inc(bump).format()
: latestVersion.inc(releaseType.bump).format()
return nextVersion
}
async function main() {
const huppyToken = process.env.HUPPY_TOKEN
assert(huppyToken && typeof huppyToken === 'string', 'HUPPY_ACCESS_KEY env var must be set')
// check we're on the main branch on HEAD
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')
}
const releaseType = getReleaseType()
const nextVersion = getNextVersion(releaseType)
console.log('Releasing version', nextVersion)
setAllVersions(nextVersion)
@ -66,12 +88,26 @@ async function main() {
REPO_ROOT + '/packages/*/src/**/version.ts',
])
const auto = new Auto({
plugins: ['npm'],
baseBranch: 'main',
owner: 'tldraw',
repo: 'tldraw',
verbose: true,
disableTsNode: true,
})
await auto.loadConfig()
// this creates a new commit
await auto.changelog({
useVersion: nextVersion,
title: `v${nextVersion}`,
})
// Gonna test this in a quick and dirty 'dry-run' mode
return
// create and push a new tag
await exec('git', ['tag', '-f', `v${nextVersion}`])
await exec('git', ['push', '--follow-tags'])