2023-04-25 11:01:25 +00:00
|
|
|
import { Auto } from '@auto-it/core'
|
2023-05-15 13:17:19 +00:00
|
|
|
import fetch from 'cross-fetch'
|
|
|
|
import { assert } from 'node:console'
|
2023-04-25 11:01:25 +00:00
|
|
|
import { parse } from 'semver'
|
2023-05-09 13:25:56 +00:00
|
|
|
import { exec } from './lib/exec'
|
2023-07-07 15:32:08 +00:00
|
|
|
import { BUBLIC_ROOT } from './lib/file'
|
2023-06-01 18:01:49 +00:00
|
|
|
import { nicelog } from './lib/nicelog'
|
2023-04-25 11:01:25 +00:00
|
|
|
import { getLatestVersion, publish, setAllVersions } from './lib/publishing'
|
2023-06-26 15:46:59 +00:00
|
|
|
import { getAllWorkspacePackages } from './lib/workspace'
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
async function main() {
|
2023-05-15 13:17:19 +00:00
|
|
|
const huppyToken = process.env.HUPPY_TOKEN
|
|
|
|
assert(huppyToken && typeof huppyToken === 'string', 'HUPPY_ACCESS_KEY env var must be set')
|
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
const auto = new Auto({
|
|
|
|
plugins: ['npm'],
|
|
|
|
baseBranch: 'main',
|
|
|
|
owner: 'tldraw',
|
2023-05-12 16:02:32 +00:00
|
|
|
repo: 'tldraw',
|
2023-05-09 13:25:56 +00:00
|
|
|
verbose: true,
|
|
|
|
})
|
2023-04-25 11:01:25 +00:00
|
|
|
|
|
|
|
// module was called directly
|
2023-05-09 13:25:56 +00:00
|
|
|
const currentBranch = (await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).toString().trim()
|
2023-04-25 11:01:25 +00:00
|
|
|
if (currentBranch !== 'main') {
|
|
|
|
throw new Error('Must be on main branch to publish')
|
|
|
|
}
|
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
await auto.loadConfig()
|
|
|
|
const bump = await auto.getVersion()
|
|
|
|
if (!bump) {
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog('nothing to do')
|
2023-05-09 13:25:56 +00:00
|
|
|
return
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
const latestVersion = parse(getLatestVersion())!
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog('latestVersion', latestVersion)
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
const [prereleaseTag, prereleaseNumber] = latestVersion.prerelease
|
|
|
|
if (prereleaseTag && typeof prereleaseNumber !== 'number') {
|
|
|
|
throw new Error(`Invalid prerelease format in version ${latestVersion}, expected e.g. -alpha.1`)
|
|
|
|
}
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// 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()
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
setAllVersions(nextVersion)
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// stage the changes
|
2023-06-26 15:46:59 +00:00
|
|
|
const packageJsonFilesToAdd = []
|
|
|
|
for (const workspace of await getAllWorkspacePackages()) {
|
|
|
|
if (workspace.relativePath.startsWith('packages/')) {
|
|
|
|
packageJsonFilesToAdd.push(`${workspace.relativePath}/package.json`)
|
|
|
|
}
|
|
|
|
}
|
2023-07-07 15:32:08 +00:00
|
|
|
await exec('git', [
|
|
|
|
'add',
|
|
|
|
'lerna.json',
|
|
|
|
...packageJsonFilesToAdd,
|
|
|
|
BUBLIC_ROOT + '/packages/*/src/version.ts',
|
|
|
|
])
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// this creates a new commit
|
|
|
|
await auto.changelog({
|
|
|
|
useVersion: nextVersion,
|
|
|
|
title: `v${nextVersion}`,
|
|
|
|
})
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// create and push a new tag
|
|
|
|
await exec('git', ['tag', '-f', `v${nextVersion}`])
|
|
|
|
await exec('git', ['push', '--follow-tags'])
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// create a release on github
|
|
|
|
await auto.runRelease({ useVersion: nextVersion })
|
2023-04-25 11:01:25 +00:00
|
|
|
|
2023-05-09 13:25:56 +00:00
|
|
|
// finally, publish the packages [IF THIS STEP FAILS, RUN THE `publish-manual.ts` script locally]
|
|
|
|
await publish()
|
2023-05-15 13:17:19 +00:00
|
|
|
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog('Notifying huppy of release...')
|
2023-10-09 10:55:16 +00:00
|
|
|
const huppyResponse = await fetch('https://tldraw-repo-sync.fly.dev/api/on-release', {
|
2023-05-15 13:17:19 +00:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ apiKey: huppyToken, tagToRelease: `v${nextVersion}`, canary: false }),
|
|
|
|
})
|
2023-06-01 18:01:49 +00:00
|
|
|
nicelog(
|
2023-05-15 13:17:19 +00:00
|
|
|
`huppy: [${huppyResponse.status} ${huppyResponse.statusText}] ${await huppyResponse.text()}`
|
|
|
|
)
|
2023-04-25 11:01:25 +00:00
|
|
|
}
|
2023-05-09 13:25:56 +00:00
|
|
|
|
|
|
|
main()
|