b9547c2e6b
This PR switches up how PR labels are validated to allow for more freeform label tweaking in the future. Basically **huppy will now only check that your PR is labelled, it doesn't care how it's labelled**. I also updated the PR template with a new labelling scheme that we can tweak over time. So before Huppy bot had to know about the specific set of allowed labels, and now as long as the label exists you're allowed to add it. So to add a new label to the PR template, just create the label and then add an option for it in the .md file. ### 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
114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
import { Auto } from '@auto-it/core'
|
|
import fetch from 'cross-fetch'
|
|
import glob from 'glob'
|
|
import { assert } from 'node:console'
|
|
import { appendFileSync } from 'node:fs'
|
|
import { exec } from './lib/exec'
|
|
import { generateAutoRcFile } from './lib/labels'
|
|
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 latestVersionInBranch = await getLatestVersion()
|
|
const latestVersionOnNpm = (await exec('npm', ['show', 'tldraw', 'version'])).trim()
|
|
|
|
const isLatestVersion = latestVersionInBranch.format() === latestVersionOnNpm
|
|
if (process.env.GITHUB_OUTPUT) {
|
|
appendFileSync(process.env.GITHUB_OUTPUT, `is_latest_version=${isLatestVersion}\n`)
|
|
}
|
|
|
|
const nextVersion = latestVersionInBranch.inc('patch').format()
|
|
// check we're on the main branch on HEAD
|
|
const currentBranch = (await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).toString().trim()
|
|
if (currentBranch !== `v${latestVersionInBranch.major}.${latestVersionInBranch.minor}.x`) {
|
|
throw new Error('Branch name does not match expected format: v{major}.{minor}.x')
|
|
}
|
|
|
|
// we could probably do this a lot earlier in the yml file but 🤷♂️
|
|
await exec('git', ['fetch', 'origin', 'main'])
|
|
const numberOfCommitsSinceBranch = Number(
|
|
(await exec('git', ['rev-list', '--count', `HEAD`, '^origin/main'])).toString().trim()
|
|
)
|
|
|
|
if (numberOfCommitsSinceBranch === 0) {
|
|
// Skip release if there are no commits since this branch was created during the initial release
|
|
// for this <major>.<minor> version.
|
|
nicelog('Initial push, skipping release')
|
|
return
|
|
}
|
|
|
|
nicelog('Releasing version', nextVersion)
|
|
|
|
await setAllVersions(nextVersion)
|
|
|
|
// stage the changes
|
|
const packageJsonFilesToAdd = []
|
|
for (const workspace of await getAllWorkspacePackages()) {
|
|
if (workspace.relativePath.startsWith('packages/')) {
|
|
packageJsonFilesToAdd.push(`${workspace.relativePath}/package.json`)
|
|
}
|
|
}
|
|
const versionFilesToAdd = glob.sync('**/*/version.ts', {
|
|
ignore: ['node_modules/**'],
|
|
follow: false,
|
|
})
|
|
console.log('versionFilesToAdd', versionFilesToAdd)
|
|
await exec('git', [
|
|
'add',
|
|
'--update',
|
|
'lerna.json',
|
|
...packageJsonFilesToAdd,
|
|
...versionFilesToAdd,
|
|
])
|
|
|
|
const auto = new Auto({
|
|
plugins: ['npm'],
|
|
baseBranch: currentBranch,
|
|
owner: 'tldraw',
|
|
repo: 'tldraw',
|
|
verbose: true,
|
|
disableTsNode: true,
|
|
})
|
|
|
|
await generateAutoRcFile()
|
|
await auto.loadConfig()
|
|
|
|
// this creates a new commit
|
|
await auto.changelog({
|
|
useVersion: nextVersion,
|
|
title: `v${nextVersion}`,
|
|
})
|
|
|
|
// 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 })
|
|
|
|
// if we're on the latest version, publish to npm under 'latest' tag.
|
|
// otherwise we don't want to overwrite the latest tag, so we publish under 'revision'.
|
|
// semver rules will still be respected because there's no prerelease tag in the version,
|
|
// so clients will get the updated version if they have a range like ^1.0.0
|
|
await publish(isLatestVersion ? 'latest' : 'revision')
|
|
|
|
if (isLatestVersion) {
|
|
nicelog('Notifying huppy of release...')
|
|
const huppyResponse = await fetch('https://tldraw-repo-sync.fly.dev/api/on-release', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ apiKey: huppyToken, tagToRelease: `v${nextVersion}`, canary: false }),
|
|
})
|
|
nicelog(
|
|
`huppy: [${huppyResponse.status} ${huppyResponse.statusText}] ${await huppyResponse.text()}`
|
|
)
|
|
}
|
|
}
|
|
|
|
main()
|