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:
parent
83423cd6d7
commit
6d4b46e6d6
4 changed files with 100 additions and 27 deletions
32
.github/workflows/publish-new.yml
vendored
32
.github/workflows/publish-new.yml
vendored
|
@ -1,8 +1,23 @@
|
|||
name: Publish new version of public packages
|
||||
name: Publish new version of public packages from main HEAD
|
||||
# This bumps the version, updates the changelogs, publishes a GitHub release, and publishes the packages to npm.
|
||||
|
||||
# Package publishing is manually triggered on github actions dashboard
|
||||
on: workflow_dispatch
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
bump_type:
|
||||
type: choice
|
||||
description: Version Bump Type
|
||||
required: true
|
||||
default: 'minor'
|
||||
options:
|
||||
- minor
|
||||
- major
|
||||
- override
|
||||
version_override:
|
||||
type: string
|
||||
description: Version Override
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
|
@ -12,6 +27,13 @@ jobs:
|
|||
runs-on: ubuntu-latest-16-cores-open
|
||||
|
||||
steps:
|
||||
- name: Check inputs
|
||||
run: |
|
||||
if [ ${{ inputs.bump_type }} != 'override' ] && [ ${{ inputs.version_override }} != '' ]; then
|
||||
yarn tsx ./scripts/publish-new.ts --bump ${{ inputs.version_override }}
|
||||
else
|
||||
yarn tsx ./scripts/publish-new.ts --bump ${{ inputs.bump_type }}
|
||||
fi
|
||||
- name: Generate GH token
|
||||
id: generate_token
|
||||
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
|
||||
|
@ -35,7 +57,11 @@ jobs:
|
|||
run: |
|
||||
git config --global user.name 'huppy-bot[bot]'
|
||||
git config --global user.email '128400622+huppy-bot[bot]@users.noreply.github.com'
|
||||
yarn tsx ./scripts/publish-new.ts
|
||||
if [ ${{ inputs.bump_type }} == 'override' ]; then
|
||||
yarn tsx ./scripts/publish-new.ts --bump ${{ inputs.version_override }}
|
||||
else
|
||||
yarn tsx ./scripts/publish-new.ts --bump ${{ inputs.bump_type }}
|
||||
fi
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
|
|
@ -54,7 +54,9 @@
|
|||
"lint": "yarn run -T tsx lint.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/minimist": "^1.2.5",
|
||||
"ignore": "^5.2.4",
|
||||
"minimist": "^1.2.8",
|
||||
"tar": "^6.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
||||
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')
|
||||
type ReleaseType =
|
||||
| {
|
||||
bump: 'major' | 'minor'
|
||||
}
|
||||
| {
|
||||
bump: 'override'
|
||||
version: SemVer
|
||||
}
|
||||
|
||||
await auto.loadConfig()
|
||||
const bump = await auto.getVersion()
|
||||
if (!bump) {
|
||||
nicelog('nothing to do')
|
||||
return
|
||||
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))
|
||||
}
|
||||
|
||||
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'])
|
||||
|
|
11
yarn.lock
11
yarn.lock
|
@ -7327,6 +7327,7 @@ __metadata:
|
|||
"@aws-sdk/client-s3": "npm:^3.440.0"
|
||||
"@aws-sdk/lib-storage": "npm:^3.440.0"
|
||||
"@types/is-ci": "npm:^3.0.0"
|
||||
"@types/minimist": "npm:^1.2.5"
|
||||
"@types/node": "npm:~20.11"
|
||||
"@types/tar": "npm:^6.1.7"
|
||||
"@typescript-eslint/utils": "npm:^5.59.0"
|
||||
|
@ -7340,6 +7341,7 @@ __metadata:
|
|||
is-ci: "npm:^3.0.1"
|
||||
kleur: "npm:^4.1.5"
|
||||
lazyrepo: "npm:0.0.0-alpha.27"
|
||||
minimist: "npm:^1.2.8"
|
||||
prettier: "npm:^3.0.3"
|
||||
recast: "npm:^0.22.0"
|
||||
rimraf: "npm:^4.4.0"
|
||||
|
@ -8018,6 +8020,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/minimist@npm:^1.2.5":
|
||||
version: 1.2.5
|
||||
resolution: "@types/minimist@npm:1.2.5"
|
||||
checksum: 477047b606005058ab0263c4f58097136268007f320003c348794f74adedc3166ffc47c80ec3e94687787f2ab7f4e72c468223946e79892cf0fd9e25e9970a90
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/ms@npm:*":
|
||||
version: 0.7.34
|
||||
resolution: "@types/ms@npm:0.7.34"
|
||||
|
@ -18852,7 +18861,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"minimist@npm:^1.1.0, minimist@npm:^1.2.0, minimist@npm:^1.2.3, minimist@npm:^1.2.5, minimist@npm:^1.2.6":
|
||||
"minimist@npm:^1.1.0, minimist@npm:^1.2.0, minimist@npm:^1.2.3, minimist@npm:^1.2.5, minimist@npm:^1.2.6, minimist@npm:^1.2.8":
|
||||
version: 1.2.8
|
||||
resolution: "minimist@npm:1.2.8"
|
||||
checksum: 908491b6cc15a6c440ba5b22780a0ba89b9810e1aea684e253e43c4e3b8d56ec1dcdd7ea96dde119c29df59c936cde16062159eae4225c691e19c70b432b6e6f
|
||||
|
|
Loading…
Reference in a new issue