diff --git a/docs/releasing.md b/docs/releasing.md index c9cfc74..6875980 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -75,7 +75,7 @@ Releases always ship as `com.firecrawl.yoji` (`RELEASE_APP_ID` in scripts/buildC ## Cutting a release -1. **Merge a sync pull request.** The sync sets each one's package.json `version` to the version its merge releases: the latest `v*` tag with its patch raised by one, unless the private repository asks for a higher one. Its first line names it, "Merging this releases v0.2.1". To merge one without a release, add the `no release` label first. +1. **Merge a sync pull request.** The sync sets each one's package.json `version` to the version its merge releases: the latest `v*` tag with its patch raised by one, unless the private repository asks for a higher one. Its first line names it, "Merging this releases v0.2.1". To merge one without a release, add the `no release` label first. A sync labelled `no release`, by YOJI_SYNC_NO_RELEASE or because an open sync pull request already has the label, keeps main's version instead, so main never names a version with no release, and the next sync that releases still takes the latest tag plus one. 2. **release-notify.yml** tells the maintainer's Mac that main moved, and the Mac runs `pnpm release:tag ` as the maintainer. It checks that the commit is a sync pull request's merge into main, without that label, and that the version in its package.json is above every `v*` tag. It then creates the tag `v0.2.1` through gh, which starts release.yml (a tag a person creates starts workflows; one made with a workflow's own token wouldn't). `--dry-run` prints what it would tag. If the version is taken, it fails and tags nothing: sync again, and the next sync pull request takes the next version. Running it again for a commit it already tagged changes nothing. A maintainer can also run release.yml by hand from the Actions tab: choose the tag, not a branch, under **Use workflow from**. 3. The **build** job checks that the run is on a `v*` tag, that the tag still points at the commit the run started from and that it matches package.json's version. Then it installs and builds the Mac app unsigned, checks its licence files, updater settings, bundle id, version and Electron fuses (`scripts/fuses.mjs`), and keeps it for a week as the `yoji-mac-unsigned` artifact. 4. Beside it, the **windows** and **linux** jobs build the previews the same way, and check their licence files, their updater settings and their Electron fuses. None of the three jobs has a secret or the `release` environment, and each has a read-only token. diff --git a/scripts/ossSync.mjs b/scripts/ossSync.mjs index 70b7559..f96bd3f 100644 --- a/scripts/ossSync.mjs +++ b/scripts/ossSync.mjs @@ -18,7 +18,9 @@ // YOJI_SYNC_HELD_BACK when that names a file, for a maintainer to land by hand. // // It labels the pull request `no release` (ossSyncPull.mjs) unless YOJI_SYNC_NO_RELEASE is false, which the maintainer -// sets when releasing is turned on, so until then a merged sync never releases. +// sets when releasing is turned on, so until then a merged sync never releases. It also labels it when an open sync pull +// request already has the label, so a maintainer's no release choice carries over to the sync that supersedes it. A no +// release sync keeps public main's version in package.json (syncVersion), so main never names a version with no release. // // It pushes and opens the pull request with YOJI_SYNC_TOKEN, a GitHub App installation token that can write only to // firecrawl/yoji. --dry-run, or no token, does everything up to the push and prints the pull request instead. @@ -28,11 +30,11 @@ import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { exportCommitEnv, privateOnly } from './ossPaths.mjs'; -import { noReleaseOn, openSyncPull } from './ossSyncPull.mjs'; +import { labelledSyncOpen, noReleaseOn, openSyncPull } from './ossSyncPull.mjs'; import { denylistAt, droppedExclusions } from './ossSyncGate.mjs'; import { flaggedTitles, leakGate, syncedFrom, syncTitles } from './ossSyncTitles.mjs'; import { heldBackLines, withBaseWorkflows, workflowChanges } from './ossWorkflows.mjs'; -import { compareVersions, nextVersion, parseVersion, versionOf, withVersion } from './releaseVersion.mjs'; +import { compareVersions, nextVersion, parseVersion, syncVersion, versionOf, withVersion } from './releaseVersion.mjs'; const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..'); privateOnly(ROOT, 'oss:sync'); @@ -42,7 +44,7 @@ const args = process.argv.slice(2); const rev = args.find((a) => !a.startsWith('--')) ?? 'HEAD'; const token = process.env.YOJI_SYNC_TOKEN ?? ''; const dry = args.includes('--dry-run') || !token; -const noRelease = noReleaseOn(process.env.YOJI_SYNC_NO_RELEASE); +let noRelease = noReleaseOn(process.env.YOJI_SYNC_NO_RELEASE); if (!token) console.log('oss:sync: YOJI_SYNC_TOKEN is not set, so this is a dry run.'); const git = (cwd, a, env = process.env) => execFileSync('git', a, { cwd, env, encoding: 'utf8', maxBuffer: 1 << 28 }).trim(); @@ -82,9 +84,19 @@ async function sync() { console.log(`oss:sync: held back ${held.length} workflow change${held.length === 1 ? '' : 's'}: ${held.map((c) => `${c.path} (${c.status})`).join(', ')}`); } + if (!noRelease && base && token) { + try { + noRelease = await labelledSyncOpen({ repo: REPO, token }); + } catch (e) { + fail(`${e.message}, so nothing was pushed.`); + } + if (noRelease) console.log(`oss:sync: an open sync pull request on ${REPO} has the "no release" label, so this one keeps it.`); + } const exported = versionOf(show(repo, 'export:package.json')); - const version = nextVersion(exported, releaseTags()); + const tags = releaseTags(); const mainVersion = base ? publishedVersion(repo) : null; + const version = syncVersion({ packageVersion: exported, tags, mainVersion, noRelease }); + const next = nextVersion(exported, tags); // Only the version would change when the export, at main's version, is main: the patch the sync would add releases // nothing new. A version raised in this repo's package.json is a change of its own. const unchanged = mainVersion && compareVersions(exported, mainVersion) <= 0 ? treeWithVersion(repo, mainVersion) : git(top, ['--git-dir', repo, 'rev-parse', 'export^{tree}']); @@ -97,7 +109,7 @@ async function sync() { const last = base ? lastSynced(git(top, ['--git-dir', repo, 'log', '-1', '--format=%B', 'main'])) : null; const lastDenylist = last ? lastGate(last) : null; const title = `Sync from ${short}`; - const body = describe(last, version, held, lastDenylist); + const body = describe(last, version, next, held, lastDenylist); const branch = `sync/${short}`; console.log(`oss:sync: ${dry ? 'would push' : 'pushing'} ${branch} to ${REPO} and open "${title}"${noRelease ? ', labelled "no release"' : ''}:\n\n${body}\n`); if (dry) return; @@ -190,7 +202,7 @@ function lastGate(from) { * first (ossSyncTitles.mjs). A title the leak gate flags, with this commit's denylist or the last sync's, is left out and * counted instead, and a gate that can't answer stops the sync. */ -function describe(from, version, held, lastDenylist) { +function describe(from, version, next, held, lastDenylist) { const titles = syncTitles(top, from, sha); let flagged; try { @@ -201,7 +213,7 @@ function describe(from, version, held, lastDenylist) { const kept = titles.filter((_, i) => !flagged.has(i)); const lines = [ noRelease - ? `The sync labels this \`no release\`, so merging it releases nothing. Remove the label first to release v${version}: the merge then tags it and builds, signs and publishes the release (docs/releasing.md).` + ? `The sync labels this \`no release\`, so merging it releases nothing and package.json stays at v${version}. To release v${next} instead, remove the label and run the sync again: it writes v${next}, and merging that tags it and builds, signs and publishes the release (docs/releasing.md).` : `Merging this releases v${version}: it tags the merge and builds, signs and publishes the release (docs/releasing.md). To merge it without a release, add the label \`no release\` first.`, '', from ? `The private changes to yoji since the last sync:` : 'The latest private changes to yoji (no earlier sync found):', diff --git a/scripts/ossSyncPull.mjs b/scripts/ossSyncPull.mjs index 5686e6f..d38b5c8 100644 --- a/scripts/ossSyncPull.mjs +++ b/scripts/ossSyncPull.mjs @@ -1,11 +1,26 @@ // The sync's pull request on firecrawl/yoji (ossSync.mjs). It opens "Sync from " from the pushed sync branch, // or finds the open one that branch already has, and labels it `no release` while YOJI_SYNC_NO_RELEASE is on (the -// default), so merging a sync releases nothing until a maintainer turns releasing on. +// default) or an open sync pull request already has that label, so merging a sync releases nothing until a maintainer +// turns releasing on, and a maintainer's no release choice carries over to the next sync. import { NO_RELEASE } from './releaseAuto.mjs'; /** Whether sync pull requests get the no release label: on unless value says false, 0, off or no. */ export const noReleaseOn = (value) => !/^(false|0|off|no)$/i.test(String(value ?? '').trim()); +/** + * Whether an open sync pull request on repo (a sync/ branch) has the no release label, so a newer sync keeps a + * maintainer's no release choice. Throws with GitHub's status when the read fails. + */ +export async function labelledSyncOpen({ repo, token, fetch = globalThis.fetch }) { + const res = await fetch(`https://api.github.com/repos/${repo}/pulls?state=open&per_page=100`, { + method: 'GET', + headers: { authorization: `Bearer ${token}`, accept: 'application/vnd.github+json' }, + }); + if (!res.ok) throw new Error(`GitHub didn't list ${repo}'s open pull requests (${res.status})`); + const open = await res.json().catch(() => []); + return open.some((pr) => pr.head?.ref?.startsWith('sync/') && pr.labels?.some((l) => l.name === NO_RELEASE)); +} + /** * Opens the pull request from branch into main of repo, or finds the open one from that branch, then labels it no * release when noRelease is set. Returns its url and number, whether it already existed and whether it was labelled. diff --git a/scripts/ossSyncPull.test.ts b/scripts/ossSyncPull.test.ts index d6d9199..0f983c4 100644 --- a/scripts/ossSyncPull.test.ts +++ b/scripts/ossSyncPull.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { noReleaseOn, openSyncPull } from './ossSyncPull.mjs'; +import { labelledSyncOpen, noReleaseOn, openSyncPull } from './ossSyncPull.mjs'; type Call = { url: string; method: string; body?: unknown }; @@ -49,6 +49,16 @@ describe('the sync pull request', () => { await expect(openSyncPull({ ...sync, noRelease: true, fetch: github([201, created], [403, {}]).fetch })).rejects.toThrow('GitHub refused the no release label on #7 (403)'); }); + it('carries no release over from an open labelled sync pull request, and only from a sync one', async () => { + const pull = (ref: string, labels: string[]) => ({ head: { ref }, labels: labels.map((name) => ({ name })) }); + const gh = github([200, [pull('dependabot/npm', ['no release']), pull('sync/bbbbbbbbbbbb', ['no release'])]]); + expect(await labelledSyncOpen({ repo: sync.repo, token: 't', fetch: gh.fetch })).toBe(true); + expect(gh.calls).toEqual([{ url: 'https://api.github.com/repos/example-org/yoji/pulls?state=open&per_page=100', method: 'GET' }]); + expect(await labelledSyncOpen({ repo: sync.repo, token: 't', fetch: github([200, [pull('sync/bbbbbbbbbbbb', []), pull('feature', ['no release'])]]).fetch })).toBe(false); + expect(await labelledSyncOpen({ repo: sync.repo, token: 't', fetch: github([200, []]).fetch })).toBe(false); + await expect(labelledSyncOpen({ repo: sync.repo, token: 't', fetch: github([403, {}]).fetch })).rejects.toThrow("GitHub didn't list example-org/yoji's open pull requests (403)"); + }); + it('labels unless YOJI_SYNC_NO_RELEASE says false', () => { for (const v of [undefined, '', 'true', '1', 'yes']) expect(noReleaseOn(v), String(v)).toBe(true); for (const v of ['false', 'FALSE', '0', 'off', 'no', ' false ']) expect(noReleaseOn(v), v).toBe(false); diff --git a/scripts/releaseVersion.mjs b/scripts/releaseVersion.mjs index f5fec76..94d1207 100644 --- a/scripts/releaseVersion.mjs +++ b/scripts/releaseVersion.mjs @@ -37,6 +37,16 @@ export function nextVersion(packageVersion, tags) { return compareVersions(packageVersion, bumped) > 0 ? packageVersion : bumped; } +/** + * The version a sync writes into the export's package.json. A sync that releases takes nextVersion. A no release sync + * keeps public main's version, so main never names a version that has no release; the next sync that releases still + * takes the latest tag with its patch raised by one. With no public main yet, it's package.json's version. + */ +export function syncVersion({ packageVersion, tags, mainVersion, noRelease }) { + if (noRelease) return mainVersion ?? packageVersion; + return nextVersion(packageVersion, tags); +} + /** Why a tag for version can't be the next release, given the tags that exist, or null when it can. */ export function tagProblem(version, tags) { if (!parseVersion(version)) return `package.json's version ${version} isn't major.minor.patch`; diff --git a/scripts/releaseVersion.test.ts b/scripts/releaseVersion.test.ts index 324e38d..d105933 100644 --- a/scripts/releaseVersion.test.ts +++ b/scripts/releaseVersion.test.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { describe, expect, it } from 'vitest'; -import { compareVersions, latestReleased, nextVersion, parseVersion, tagProblem, versionOf, withVersion } from './releaseVersion.mjs'; +import { compareVersions, latestReleased, nextVersion, parseVersion, syncVersion, tagProblem, versionOf, withVersion } from './releaseVersion.mjs'; describe('release versions', () => { it('reads only plain major.minor.patch', () => { @@ -33,6 +33,16 @@ describe('release versions', () => { expect(() => nextVersion('0.2', [])).toThrow(/isn't major.minor.patch/); }); + it("keeps public main's version on a no release sync, and the next releasing sync still takes the latest tag plus one", () => { + const tags = ['refs/tags/v0.1.0']; + expect(syncVersion({ packageVersion: '0.1.0', tags, mainVersion: '0.1.0', noRelease: true })).toBe('0.1.0'); + expect(syncVersion({ packageVersion: '0.2.0', tags, mainVersion: '0.1.0', noRelease: true })).toBe('0.1.0'); + expect(syncVersion({ packageVersion: '0.1.0', tags: [], mainVersion: null, noRelease: true })).toBe('0.1.0'); + expect(syncVersion({ packageVersion: '0.1.0', tags, mainVersion: '0.1.0', noRelease: false })).toBe('0.1.1'); + expect(syncVersion({ packageVersion: '0.2.0', tags, mainVersion: '0.1.0', noRelease: false })).toBe('0.2.0'); + expect(tagProblem(syncVersion({ packageVersion: '0.1.0', tags, mainVersion: '0.1.0', noRelease: false }), tags)).toBeNull(); + }); + it('refuses a tag that exists or is not above the latest release', () => { expect(tagProblem('0.1.1', ['v0.1.0'])).toBeNull(); expect(tagProblem('0.1.0', [])).toBeNull();