Tldraw/scripts/publish-new.ts

92 wiersze
2.7 KiB
TypeScript
Czysty Zwykły widok Historia

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'
import { exec } from './lib/exec'
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
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')
const auto = new Auto({
plugins: ['npm'],
baseBranch: 'main',
owner: 'tldraw',
repo: 'tldraw',
verbose: true,
})
2023-04-25 11:01:25 +00:00
// module was called directly
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')
}
await auto.loadConfig()
const bump = await auto.getVersion()
if (!bump) {
nicelog('nothing to do')
return
}
2023-04-25 11:01:25 +00:00
const latestVersion = parse(getLatestVersion())!
2023-04-25 11:01:25 +00:00
nicelog('latestVersion', latestVersion)
2023-04-25 11:01:25 +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
// 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
setAllVersions(nextVersion)
2023-04-25 11:01:25 +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`)
}
}
await exec('git', ['add', 'lerna.json', ...packageJsonFilesToAdd])
2023-04-25 11:01:25 +00:00
// this creates a new commit
await auto.changelog({
useVersion: nextVersion,
title: `v${nextVersion}`,
})
2023-04-25 11:01:25 +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
// create a release on github
await auto.runRelease({ useVersion: nextVersion })
2023-04-25 11:01:25 +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
nicelog('Notifying huppy of release...')
2023-05-15 13:17:19 +00:00
const huppyResponse = await fetch('http://localhost:3000/api/on-release', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ apiKey: huppyToken, tagToRelease: `v${nextVersion}`, canary: false }),
})
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
}
main()