Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
148 lines
4.5 KiB
TypeScript
148 lines
4.5 KiB
TypeScript
import assert from 'assert'
|
|
import { Octokit } from '@octokit/rest'
|
|
import minimist from 'minimist'
|
|
import { SemVer, parse } from 'semver'
|
|
import { exec } from './lib/exec'
|
|
import { makeEnv } from './lib/makeEnv'
|
|
import { nicelog } from './lib/nicelog'
|
|
import {
|
|
getLatestTldrawVersionFromNpm,
|
|
publish,
|
|
publishProductionDocsAndExamplesAndBemo,
|
|
setAllVersions,
|
|
triggerBumpVersionsWorkflow,
|
|
} from './lib/publishing'
|
|
import { uploadStaticAssets } from './lib/upload-static-assets'
|
|
|
|
const env = makeEnv(['GH_TOKEN'])
|
|
|
|
type ReleaseType =
|
|
| {
|
|
bump: 'major' | 'minor'
|
|
}
|
|
| {
|
|
bump: 'override'
|
|
version: SemVer
|
|
}
|
|
|
|
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))
|
|
}
|
|
|
|
async function getDraftRelease(version: string, octokit: Octokit) {
|
|
const expectedVersion = `v${version}`
|
|
|
|
// Fetch all releases with pagination
|
|
const releases = await octokit.paginate(octokit.rest.repos.listReleases, {
|
|
owner: 'tldraw',
|
|
repo: 'tldraw',
|
|
per_page: 100, // Maximum per page to reduce API calls
|
|
})
|
|
|
|
const draftRelease = releases.find((release) => release.draft && release.name === expectedVersion)
|
|
|
|
if (!draftRelease) {
|
|
const availableDrafts = releases
|
|
.filter((r) => r.draft)
|
|
.map((r) => r.name)
|
|
.join(', ')
|
|
throw new Error(
|
|
`No draft release found named ${expectedVersion}. Available draft releases: ${availableDrafts || 'none'}`
|
|
)
|
|
}
|
|
|
|
assert(draftRelease.body, `Draft release ${expectedVersion} has no body/release notes`)
|
|
return draftRelease
|
|
}
|
|
|
|
async function getNextVersion(releaseType: ReleaseType): Promise<string> {
|
|
if (releaseType.bump === 'override') {
|
|
return releaseType.version.format()
|
|
}
|
|
|
|
const latestVersion = await getLatestTldrawVersionFromNpm()
|
|
|
|
nicelog('latestVersion', latestVersion)
|
|
|
|
const [prereleaseTag, prereleaseNumber] = latestVersion.prerelease
|
|
if (prereleaseTag && typeof prereleaseNumber !== 'number') {
|
|
throw new Error(`Invalid prerelease format in version ${latestVersion}, expected e.g. -alpha.1`)
|
|
}
|
|
|
|
// 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(releaseType.bump).format()
|
|
|
|
return nextVersion
|
|
}
|
|
|
|
async function main() {
|
|
// // check we're on the main branch on HEAD
|
|
const currentBranch = (await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'])).toString().trim()
|
|
if (currentBranch !== 'production') {
|
|
throw new Error('Must be on production branch to publish')
|
|
}
|
|
|
|
const releaseType = getReleaseType()
|
|
const nextVersion = await getNextVersion(releaseType)
|
|
|
|
const isPrerelease = parse(nextVersion)!.prerelease.length > 0
|
|
assert(!isPrerelease, 'Prerelease versions are no longer supported for new releases')
|
|
|
|
console.log('Releasing version', nextVersion)
|
|
|
|
// Check that a draft release exists early, before doing any work
|
|
const octokit = new Octokit({ auth: env.GH_TOKEN })
|
|
const draftRelease = await getDraftRelease(nextVersion, octokit)
|
|
nicelog('Found draft release:', draftRelease)
|
|
|
|
await setAllVersions(nextVersion, { stageChanges: true })
|
|
|
|
const gitTag = `v${nextVersion}`
|
|
await exec('git', ['commit', '-m', `${gitTag}`])
|
|
|
|
// create new 'release' branch called e.g. v2.0.x or v4.3.x, for making patch releases
|
|
const { major, minor } = parse(nextVersion)!
|
|
const branchName = `v${major}.${minor}.x`
|
|
// create and push a new tag to the release branch
|
|
await exec('git', ['tag', '-a', gitTag, '-m', gitTag, '-f'])
|
|
await exec('git', ['push', 'origin', `HEAD:refs/heads/${branchName}`, '--follow-tags'])
|
|
await publishProductionDocsAndExamplesAndBemo()
|
|
|
|
// convert draft release to published release
|
|
await octokit.rest.repos.updateRelease({
|
|
owner: 'tldraw',
|
|
repo: 'tldraw',
|
|
release_id: draftRelease.id,
|
|
draft: false,
|
|
tag_name: gitTag,
|
|
name: gitTag,
|
|
})
|
|
|
|
// upload static assets
|
|
await uploadStaticAssets(nextVersion)
|
|
|
|
// finally, publish the packages [IF THIS STEP FAILS, RUN THE `publish-manual.ts` script locally]
|
|
await publish()
|
|
|
|
// Trigger version bump on main branch to sync all package versions
|
|
nicelog('Triggering version bump on main branch')
|
|
await triggerBumpVersionsWorkflow(env.GH_TOKEN)
|
|
}
|
|
|
|
main()
|