From bbbe0c22db9421fbea07ce494c6f9da9f4bed0b5 Mon Sep 17 00:00:00 2001 From: Rudy Fraser Date: Tue, 10 Nov 2026 16:30:21 -0500 Subject: [PATCH] test(merge): align upstream tests with fork behaviour and migrate test imports --- __tests__/lib/feed-manip-community.test.ts | 28 +- __tests__/lib/space-feed-routing.test.ts | 10 +- __tests__/lib/string.test.ts | 4 +- docs/release-model.md | 71 ---- .../appConfig.test.js | 8 +- scripts/release/check-github.mjs | 253 -------------- scripts/release/check-github.test.js | 326 ------------------ scripts/release/cli.mjs | 114 ------ scripts/release/common.sh | 75 ---- scripts/release/create.sh | 41 --- scripts/release/model.mjs | 293 ---------------- scripts/release/plan.mjs | 287 --------------- scripts/release/prepare.mjs | 214 ------------ scripts/release/prepare.test.js | 116 ------- scripts/release/run.sh | 64 ---- scripts/release/validate.cjs | 39 --- .../__tests__/AssemblyEmbed.test.tsx | 9 +- .../dialogs/NewskieDialog/utils.test.ts | 18 +- .../streamplace/__tests__/visible.test.ts | 2 +- .../api/__tests__/assembly-publish.test.ts | 10 +- src/lib/api/__tests__/assembly.test.ts | 146 ++++---- src/lib/api/__tests__/community-feed.test.ts | 38 +- .../__tests__/community-notifications.test.ts | 50 ++- src/lib/api/__tests__/community.test.ts | 22 +- src/lib/api/__tests__/event-publish.test.ts | 34 +- src/lib/api/__tests__/post-routing.test.ts | 36 +- src/lib/api/__tests__/space-post-poll.test.ts | 2 +- src/lib/api/__tests__/space-post.test.ts | 20 +- src/lib/api/__tests__/space-write.test.ts | 77 +++-- src/lib/api/feed/__tests__/utils.test.ts | 34 +- src/lib/api/feed/custom.test.ts | 51 +-- src/lib/api/feed/merge.test.ts | 6 +- src/lib/api/resolve.external.test.ts | 21 +- src/lib/api/resolve.ts | 1 + .../hooks/__tests__/useSetPostTitle.test.tsx | 4 +- src/lib/hooks/useOTAUpdates.test.ts | 9 +- .../__tests__/adult-content-labels.test.ts | 28 +- .../__tests__/notifications-test.ts | 8 +- src/lib/strings/embed-player.test.ts | 4 +- .../__tests__/FeaturedAppCard.test.tsx | 2 +- .../useAtmosphereExploreQuery.test.tsx | 11 +- .../__tests__/appview-fallback-probe.test.ts | 26 +- src/state/__tests__/appview-fallback.test.ts | 26 +- .../cache/__tests__/post-shadow-space.test.ts | 6 +- .../__tests__/profile-enrichment.test.tsx | 14 +- .../space-engagement-routing.test.ts | 38 +- .../__tests__/fetch-page.test.ts | 12 +- .../__tests__/space-subjects.test.ts | 8 +- .../drafts/state/__tests__/api-event.test.ts | 13 +- .../drafts/state/__tests__/api-poll.test.ts | 13 +- .../state/__tests__/composer-poll.test.ts | 2 +- 51 files changed, 407 insertions(+), 2337 deletions(-) delete mode 100644 docs/release-model.md delete mode 100644 scripts/release/check-github.mjs delete mode 100644 scripts/release/check-github.test.js delete mode 100644 scripts/release/cli.mjs delete mode 100644 scripts/release/common.sh delete mode 100644 scripts/release/create.sh delete mode 100644 scripts/release/model.mjs delete mode 100644 scripts/release/plan.mjs delete mode 100644 scripts/release/prepare.mjs delete mode 100644 scripts/release/prepare.test.js delete mode 100644 scripts/release/run.sh delete mode 100644 scripts/release/validate.cjs diff --git a/__tests__/lib/feed-manip-community.test.ts b/__tests__/lib/feed-manip-community.test.ts index 221fadbda..6f034c855 100644 --- a/__tests__/lib/feed-manip-community.test.ts +++ b/__tests__/lib/feed-manip-community.test.ts @@ -1,9 +1,5 @@ -import { - type AppBskyActorDefs, - type AppBskyFeedDefs, - type AppBskyFeedPost, -} from '@atproto/api' +import {type app} from '#/lexicons' import {FeedTuner, FeedViewPostsSlice} from '#/lib/api/feed-manip' // The repo-wide manual mock stubs CID.parse away, which makes every @@ -26,7 +22,7 @@ const SPACE_URI = function author( did: string, opts?: {following?: boolean}, -): AppBskyActorDefs.ProfileViewBasic { +): app.bsky.actor.defs.ProfileViewBasic { return { $type: 'app.bsky.actor.defs#profileViewBasic', did, @@ -43,9 +39,9 @@ function communityPost(opts: { reply?: {rootUri: string; parentUri: string} threadMuted?: boolean recordType?: string -}): AppBskyFeedDefs.PostView { +}): app.bsky.feed.defs.PostView { const did = opts.authorDid ?? MEMBER_DID - const record: AppBskyFeedPost.Record = { + const record: app.bsky.feed.post.Main = { $type: (opts.recordType ?? 'app.bsky.feed.post') as 'app.bsky.feed.post', text: `post ${opts.rkey}`, createdAt: '2026-07-17T12:00:00.000Z', @@ -112,7 +108,7 @@ describe('FeedTuner with merged community posts', () => { it('keeps a reposted community post as a repost slice', () => { const post = communityPost({rkey: 'reposted', authorDid: 'did:plc:other'}) - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ { post, reason: { @@ -136,7 +132,7 @@ describe('FeedTuner with merged community posts', () => { it('drops a reposted community post when reposts are hidden', () => { const post = communityPost({rkey: 'reposted', authorDid: 'did:plc:other'}) - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ { post, reason: { @@ -156,7 +152,7 @@ describe('FeedTuner with merged community posts', () => { }) it('keeps a top-level community post', () => { - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ {post: communityPost({rkey: 'aaa'})}, ] const slices = followingTuner().tune(feed) @@ -170,7 +166,7 @@ describe('FeedTuner with merged community posts', () => { rkey: 'reply', reply: {rootUri: root.uri, parentUri: root.uri}, }) - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ { post: reply, reply: {root, parent: root}, @@ -188,7 +184,7 @@ describe('FeedTuner with merged community posts', () => { rkey: 'reply', reply: {rootUri, parentUri: rootUri}, }) - const feed: AppBskyFeedDefs.FeedViewPost[] = [{post: reply}] + const feed: app.bsky.feed.defs.FeedViewPost[] = [{post: reply}] const slices = followingTuner().tune(feed) expect(slices).toHaveLength(0) }) @@ -199,7 +195,7 @@ describe('FeedTuner with merged community posts', () => { rkey: 'reply', reply: {rootUri: root.uri, parentUri: root.uri}, }) - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ {post: reply, reply: {root, parent: root}}, {post: root}, ] @@ -208,7 +204,7 @@ describe('FeedTuner with merged community posts', () => { }) it('drops a thread-muted community post', () => { - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ {post: communityPost({rkey: 'muted', threadMuted: true})}, ] const slices = followingTuner().tune(feed) @@ -218,7 +214,7 @@ describe('FeedTuner with merged community posts', () => { it('drops items whose record $type is not app.bsky.feed.post', () => { // Encodes the appview invariant: buildCommunityPostView must normalize // record $type, or merged items silently vanish from feeds. - const feed: AppBskyFeedDefs.FeedViewPost[] = [ + const feed: app.bsky.feed.defs.FeedViewPost[] = [ {post: communityPost({rkey: 'raw', recordType: COLLECTION})}, ] const slices = followingTuner().tune(feed) diff --git a/__tests__/lib/space-feed-routing.test.ts b/__tests__/lib/space-feed-routing.test.ts index 945977790..db0d47966 100644 --- a/__tests__/lib/space-feed-routing.test.ts +++ b/__tests__/lib/space-feed-routing.test.ts @@ -6,8 +6,8 @@ jest.mock('@atproto/api', () => ({ jsonToLex: (value: unknown) => value, })) -import {type AtpAgent} from '@atproto/api' +import {type Client} from '@atproto/lex' import {CustomFeedAPI} from '#/lib/api/feed/custom' import {toPostView, toSpaceFeedPage} from '#/lib/api/space-views' @@ -31,7 +31,7 @@ type FakeAgent = { com: {atproto: {repo: {getRecord: jest.Mock}}} } -function agent({did}: {did?: string}): FakeAgent { +function client({did}: {did?: string}): FakeAgent { const getFeed = jest.fn() const fetchHandler = jest.fn((path: string) => { if (path.includes('community.blacksky.feed.getSpaceFeed')) { @@ -79,7 +79,7 @@ const asAgent = (a: FakeAgent) => a as unknown as AtpAgent describe('space-backed feed routing', () => { it('reads a space feed through the private endpoint and never the standard one', async () => { - const a = agent({did: 'did:plc:alice'}) + const a = client({did: 'did:plc:alice'}) const api = new CustomFeedAPI({agent: asAgent(a), feedParams: {feed: FEED}}) const page = await api.fetch({cursor: undefined, limit: 30}) @@ -93,7 +93,7 @@ describe('space-backed feed routing', () => { }) it('peekLatest uses the same endpoint, so polling agrees with pagination', async () => { - const a = agent({did: 'did:plc:alice'}) + const a = client({did: 'did:plc:alice'}) const api = new CustomFeedAPI({agent: asAgent(a), feedParams: {feed: FEED}}) await api.peekLatest() @@ -103,7 +103,7 @@ describe('space-backed feed routing', () => { }) it('refuses logged out rather than falling back to the public appview', async () => { - const a = agent({}) + const a = client({}) const api = new CustomFeedAPI({agent: asAgent(a), feedParams: {feed: FEED}}) await expect(api.fetch({cursor: undefined, limit: 30})).rejects.toThrow( diff --git a/__tests__/lib/string.test.ts b/__tests__/lib/string.test.ts index 7388e236f..d0ba93b99 100644 --- a/__tests__/lib/string.test.ts +++ b/__tests__/lib/string.test.ts @@ -517,7 +517,7 @@ describe('parseEmbedPlayerFromUrl', () => { { type: 'youtube_video', source: 'youtube', - playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', + playerUri: 'https://blacksky.community/iframe/youtube.html?videoId=videoId&start=0', }, { type: 'youtube_video', @@ -540,7 +540,7 @@ describe('parseEmbedPlayerFromUrl', () => { { type: 'youtube_video', source: 'youtube', - playerUri: 'https://bsky.app/iframe/youtube.html?videoId=videoId&start=0', + playerUri: 'https://blacksky.community/iframe/youtube.html?videoId=videoId&start=0', }, { type: 'youtube_video', diff --git a/docs/release-model.md b/docs/release-model.md deleted file mode 100644 index 03c72fbcc..000000000 --- a/docs/release-model.md +++ /dev/null @@ -1,71 +0,0 @@ -# Release model - -`RELEASE-x.y.z.md` holds the release version, build metadata, and cumulative -public changelog. - -## Names - -All names come from one strict `x.y.z` version: - -- Branch: `release-x.y.z` -- Native tag: `x.y.z` -- Document: `RELEASE-x.y.z.md` -- GitHub Release: `Release x.y.z` -- OTA tag: `ota-x.y.z-N` - -## Prepared document - -Only `releaseVersion` is required before builds: - -```md ---- -releaseVersion: 1.131.1 ---- - -# Release 1.131.1 - - - -## Initial release - -- Added something - - -``` - -## Finalized document - -Finalization adds the source commit and build numbers read from the native -artifacts. All fields are required: - -```yaml -releaseVersion: 1.131.1 -sourceTag: 1.131.1 -sourceSha: 0123456789abcdef0123456789abcdef01234567 -iosBuildNumber: 1662 -androidVersionCode: 1110 -``` - -`sourceTag` must match `releaseVersion`. `sourceSha` must be a full Git object ID. -Build numbers must be positive integers. Collecting build results and finalizing -the document are not implemented in the preparation workflow yet. - -## Changelog - -GitHub Release notes come from between the public changelog markers. Each OTA -adds a numbered section (`OTA 1`, `OTA 2`, etc.) with no gaps in the sequence. - -## Build inputs - -The iOS, Android, and web workflows accept `sourceRef`, defaulting to the event's -SHA, and expose the checked-out commit as `source-sha`. Native submission jobs -check out that same commit. Web image tags and revision labels use it too. - -Native workflows accept `submit`, defaulting to `true`. The preparation plan sets -it to `false`. Build and submission recovery is separate work. - -## Implementation - -- [Preparation workflow and checks](release-preparation/README.md) -- `scripts/release/model.mjs`: document creation, validation, and changelog parsing. -- `scripts/release/cli.mjs`: command-line access to the document helpers. diff --git a/plugins/starterPackAppClipExtension/appConfig.test.js b/plugins/starterPackAppClipExtension/appConfig.test.js index fc2f364ef..08ca4a0c1 100644 --- a/plugins/starterPackAppClipExtension/appConfig.test.js +++ b/plugins/starterPackAppClipExtension/appConfig.test.js @@ -19,7 +19,7 @@ it.each([ ['TestFlight', 'testflight'], ['production', 'production'], ])( - 'supports tablets and sets parent device families for %s', + 'stays phone-only and sets parent device families for %s', (_name, environment) => { if (environment === undefined) { delete process.env.EXPO_PUBLIC_ENV @@ -27,14 +27,14 @@ it.each([ process.env.EXPO_PUBLIC_ENV = environment } - const config = createAppConfig({name: 'Bluesky', slug: 'bluesky'}).expo + const config = createAppConfig({name: 'Blacksky', slug: 'blacksky'}).expo - expect(config.ios.supportsTablet).toBe(true) + expect(config.ios.supportsTablet).toBe(false) expect( IOSConfig.DeviceFamily.formatDeviceFamilies( IOSConfig.DeviceFamily.getDeviceFamilies(config), ), - ).toBe('"1,2"') + ).toBe('"1"') expect(config.ios.infoPlist.UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationPortrait', ]) diff --git a/scripts/release/check-github.mjs b/scripts/release/check-github.mjs deleted file mode 100644 index aac72bead..000000000 --- a/scripts/release/check-github.mjs +++ /dev/null @@ -1,253 +0,0 @@ -import {readFileSync, writeFileSync} from 'node:fs' -import {join, resolve} from 'node:path' -import {pathToFileURL} from 'node:url' - -import {renderReport} from './prepare.mjs' - -/** GET-only GitHub reader. Missing resources are established by successful lists. */ -export function githubReader(repository, token) { - if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository) || !token) { - throw new Error('A repository (owner/name) and GH_TOKEN are required.') - } - return async path => { - const response = await fetch( - `https://api.github.com/repos/${repository}${path ? `/${path}` : ''}`, - { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - Accept: 'application/vnd.github+json', - 'X-GitHub-Api-Version': '2022-11-28', - }, - signal: AbortSignal.timeout(30000), - }, - ) - if (!response.ok) - throw new Error( - `GitHub GET ${path}: HTTP ${response.status}. No absence or reuse can be assumed.`, - ) - return response.json() - } -} - -/** Compare actual remote resources, accepting only an exact, single-file preparation commit. */ -export async function checkGitHub(report, read) { - const {identity, sourceSha, document, publicChangelog} = report - let observed = null - const checks = [] - const add = (resource, action, detail) => - checks.push({resource, action, detail}) - try { - const repository = await read('') - const draftVisibility = repository.permissions?.push === true - if (!draftVisibility) { - add( - 'draft visibility', - 'unverified', - 'This token cannot establish full draft visibility. Draft creation requires a check with release permissions before execution.', - ) - } - const ref = async name => { - const refs = await read(`git/matching-refs/${name}`) - if (!Array.isArray(refs)) - throw new Error('Invalid GitHub reference response.') - return refs.find(item => item.ref === `refs/${name}`) ?? null - } - const branch = await ref(`heads/${identity.branch}`) - const tag = await ref(`tags/${identity.tag}`) - const releases = [] - for (let page = 1; ; page++) { - const items = await read(`releases?per_page=100&page=${page}`) - if (!Array.isArray(items)) - throw new Error('Invalid GitHub releases response.') - releases.push(...items.filter(item => item.tag_name === identity.tag)) - if (items.length < 100) break - } - const base = await read(`git/commits/${sourceSha}`) - const before = await read(`git/trees/${base.tree.sha}?recursive=1`) - if (before.truncated || !Array.isArray(before.tree)) - throw new Error('Cannot verify the complete source tree.') - if (before.tree.some(item => item.path === identity.filename)) { - throw new Error( - 'Selected source already contains this release file. Select the original source before preparation; existing release metadata will not be overwritten.', - ) - } - let candidate = null - if (!branch) { - add('branch', 'create', `${identity.branch} does not exist.`) - add( - 'release file', - 'create', - `Would commit ${identity.filename}; no prepared commit exists yet.`, - ) - } else if (branch.object?.type !== 'commit') { - add('branch', 'blocked', 'Release branch does not point to a commit.') - } else if (branch.object.sha === sourceSha) { - add( - 'branch', - 'reuse', - `Branch still points to the selected source ${sourceSha}.`, - ) - add( - 'release file', - 'create', - 'The preparation commit has not been made yet.', - ) - } else { - const commit = await read(`git/commits/${branch.object.sha}`) - if (commit.parents?.length !== 1 || commit.parents[0].sha !== sourceSha) { - add( - 'branch', - 'blocked', - 'Branch has moved or was prepared from a different source.', - ) - } else { - const after = await read(`git/trees/${commit.tree.sha}?recursive=1`) - if ( - before.truncated || - after.truncated || - !Array.isArray(before.tree) || - !Array.isArray(after.tree) - ) - throw new Error('Cannot verify the complete Git trees.') - const entries = tree => - tree - .filter( - item => item.type !== 'tree' && item.path !== identity.filename, - ) - .map(({path, mode, type, sha}) => ({path, mode, type, sha})) - .sort((a, b) => a.path.localeCompare(b.path)) - const file = after.tree.find(item => item.path === identity.filename) - let matches = false - if ( - file?.type === 'blob' && - file.mode === '100644' && - JSON.stringify(entries(before.tree)) === - JSON.stringify(entries(after.tree)) - ) { - const blob = await read(`git/blobs/${file.sha}`) - matches = - blob.encoding === 'base64' && - Buffer.from(blob.content, 'base64').toString('utf8') === document - } - if (matches) { - candidate = branch.object.sha - add( - 'branch', - 'reuse', - `Verified preparation commit ${candidate}: same source, same release file, no other file changes.`, - ) - add( - 'release file', - 'reuse', - 'Contents already match; no new commit is needed.', - ) - } else - add( - 'branch', - 'blocked', - 'Release file or other files differ from the expected preparation.', - ) - } - } - observed = { - branch, - tag, - releases, - sourceTreeSha: base.tree.sha, - sourceTree: before.tree, - candidateSha: candidate, - draftVisibility, - } - if (!tag) - add( - 'tag', - 'create', - `${identity.tag} does not exist. It would point to the prepared commit.`, - ) - else { - let object = tag.object - for (let depth = 0; object?.type === 'tag' && depth < 10; depth++) - object = (await read(`git/tags/${object.sha}`)).object - add( - 'tag', - candidate && object?.type === 'commit' && object.sha === candidate - ? 'reuse' - : 'blocked', - `Existing tag resolves to ${object?.sha ?? 'an unknown object'}. It must match a verified preparation commit.`, - ) - } - if (releases.length === 0) - add( - 'GitHub Release', - draftVisibility ? 'create' : 'unverified', - draftVisibility - ? `No release uses tag ${identity.tag}.` - : `No visible release uses tag ${identity.tag}; a hidden draft may exist.`, - ) - else if (releases.length !== 1) - add('GitHub Release', 'blocked', 'Multiple releases use this tag.') - else { - const release = releases[0] - const matches = - candidate && - tag && - checks.find(item => item.resource === 'tag')?.action === 'reuse' && - release.draft === true && - release.prerelease === false && - release.name === identity.githubReleaseName && - release.body === publicChangelog - add( - 'GitHub Release', - matches ? 'reuse' : 'blocked', - matches - ? `Draft #${release.id} matches the verified tag and public notes.` - : 'Existing release is published, differs from the expected draft, or has no verified tag and preparation commit.', - ) - } - } catch (error) { - add('GitHub checks', 'blocked', error.message) - } - return { - ...report, - github: { - status: checks.some(item => item.action === 'blocked') - ? 'blocked' - : checks.some(item => item.action === 'unverified') - ? 'incomplete' - : 'ready', - checkedAt: new Date().toISOString(), - checks, - observed, - }, - } -} - -if ( - process.argv[1] && - import.meta.url === pathToFileURL(resolve(process.argv[1])).href -) { - try { - const [directory, repository, ...extra] = process.argv.slice(2) - if (!directory || !repository || extra.length) - throw new Error( - 'Usage: node scripts/release/check-github.mjs REPORT_DIRECTORY OWNER/REPO', - ) - const report = await checkGitHub( - JSON.parse(readFileSync(join(directory, 'report.json'), 'utf8')), - githubReader(repository, process.env.GH_TOKEN), - ) - report.github.repository = repository - writeFileSync( - join(directory, 'report.json'), - JSON.stringify(report, null, 2) + '\n', - ) - const markdown = renderReport(report) - writeFileSync(join(directory, 'README.md'), markdown) - process.stdout.write(markdown) - if (report.github.status === 'blocked') process.exitCode = 1 - } catch (error) { - process.stderr.write(`${error.message}\n`) - process.exitCode = 1 - } -} diff --git a/scripts/release/check-github.test.js b/scripts/release/check-github.test.js deleted file mode 100644 index 81edcbdeb..000000000 --- a/scripts/release/check-github.test.js +++ /dev/null @@ -1,326 +0,0 @@ -/* oxlint-disable import/no-nodejs-modules -- Tests execute the Node release checker with API fixtures. */ -import {spawnSync} from 'node:child_process' -import {resolve} from 'node:path' -import {pathToFileURL} from 'node:url' - -const plannerUrl = pathToFileURL(resolve('scripts/release/plan.mjs')).href - -const moduleUrl = pathToFileURL( - resolve('scripts/release/check-github.mjs'), -).href - -/** Run the real checker with a strict fake reader; no network calls. */ -function check(scenario) { - const result = spawnSync( - process.execPath, - [ - '--input-type=module', - '-e', - ` - import {checkGitHub, githubReader} from ${JSON.stringify(moduleUrl)} - import {dryRunRelease, buildWorkflows} from ${JSON.stringify(plannerUrl)} - const scenario = process.argv[1] - const hashes = Object.fromEntries(buildWorkflows.map(build => [build.file, build.file])) - const report = {identity: {branch:'release-1.2.3',tag:'1.2.3',filename:'RELEASE-1.2.3.md',githubReleaseName:'Release 1.2.3'},sourceSha:'source',document:'exact document',publicChangelog:'notes'} - const file = {path:'app.js',mode:'100644',type:'blob',sha:'app'} - const data = { - '': {permissions:{push:!scenario.includes('hidden')}}, - 'git/matching-refs/heads/release-1.2.3': [{ref:'refs/heads/release-1.2.3',object:{type:'commit',sha:'candidate'}}], - 'git/matching-refs/tags/1.2.3': [{ref:'refs/tags/1.2.3',object:{type:'tag',sha:'annotated'}}], - 'git/tags/annotated': {object:{type:'commit',sha:'candidate'}}, - 'git/commits/candidate': {parents:[{sha:'source'}],tree:{sha:'after'}}, - 'git/commits/source': {tree:{sha:'before'}}, - 'git/trees/before?recursive=1': {tree:[file]}, - 'git/trees/after?recursive=1': {tree:[file,{path:report.identity.filename,type:'blob',mode:'100644',sha:'document'}]}, - 'git/blobs/document': {encoding:'base64',content:Buffer.from('exact document').toString('base64')}, - 'releases?per_page=100&page=1': [{id:1,tag_name:'1.2.3',draft:true,prerelease:false,name:'Release 1.2.3',body:'notes'}], - } - if (scenario === 'new' || ['plan-new','plan-drift','plan-workflow','plan-hidden'].includes(scenario)) for (const key of Object.keys(data)) if (key.includes('matching-refs') || key.startsWith('releases')) data[key] = [] - if (scenario === 'moved') data['git/commits/candidate'].parents = [{sha:'other'}] - if (scenario === 'changed') data['git/trees/after?recursive=1'].tree[0] = {...file,sha:'changed'} - if (scenario === 'truncated') data['git/trees/after?recursive=1'].truncated = true - if (scenario === 'published' || scenario === 'plan-hidden-published') data['releases?per_page=100&page=1'][0].draft = false - if (scenario === 'pagination') { - data['releases?per_page=100&page=2'] = data['releases?per_page=100&page=1'] - data['releases?per_page=100&page=1'] = Array.from({length:100},()=>({tag_name:'other'})) - } - if (scenario.startsWith('plan-')) { - const files = buildWorkflows.map(build => ({path:'.github/workflows/' + build.file,mode:'100644',type:'blob',sha:build.file})) - data['git/trees/before?recursive=1'].tree.push(...files) - data['git/trees/after?recursive=1'].tree.push(...files) - } - if (scenario === 'plan-workflow') data['git/trees/before?recursive=1'].tree.pop() - let passes = 0 - for (const build of buildWorkflows) data['actions/workflows/' + build.file] = {state:scenario === 'plan-disabled' ? 'disabled_manually' : 'active',path:'.github/workflows/' + build.file} - const read = async path => { - if (path === '') passes++ - if (scenario === 'plan-drift' && passes === 3 && path === 'git/matching-refs/heads/release-1.2.3') return [{ref:'refs/heads/release-1.2.3',object:{type:'commit',sha:'source'}}] - - if (scenario === 'api-error') throw new Error('HTTP 403') - if (!(path in data)) throw new Error('Unexpected request ' + path) - return data[path] - } - const checked = scenario.startsWith('plan-') ? await dryRunRelease(report, 'owner/repo', read, hashes) : await checkGitHub(report, read) - if (scenario === 'get-only') { - globalThis.fetch = async (url, options) => { - if (url !== 'https://api.github.com/repos/owner/repo') throw new Error('Wrong repository endpoint') - if (options.method !== 'GET' || options.body) throw new Error('Mutation attempted') - return {ok:false,status:404} - } - try { await githubReader('owner/repo','dummy')('') } catch(error) { checked.transportError = error.message } - } - process.stdout.write(JSON.stringify(checked)) - `, - scenario, - ], - {encoding: 'utf8'}, - ) - if (result.status !== 0) throw new Error(result.stderr) - return JSON.parse(result.stdout) -} - -test('missing resources propose creation; matching resources including annotated tags are reused', () => { - expect(check('new')).toMatchObject({ - github: { - status: 'ready', - checks: expect.arrayContaining([ - expect.objectContaining({resource: 'branch', action: 'create'}), - ]), - }, - }) - expect(check('matching')).toMatchObject({ - github: { - status: 'ready', - checks: expect.arrayContaining([ - expect.objectContaining({resource: 'release file', action: 'reuse'}), - expect.objectContaining({resource: 'GitHub Release', action: 'reuse'}), - ]), - }, - }) -}) - -test('moved branches, unrelated file changes, published releases, and incomplete evidence block preparation', () => { - for (const scenario of [ - 'moved', - 'changed', - 'published', - 'truncated', - 'api-error', - ]) { - expect(check(scenario)).toMatchObject({github: {status: 'blocked'}}) - } -}) - -test('checks later pages of releases', () => { - expect(check('pagination')).toMatchObject({ - github: { - status: 'ready', - checks: expect.arrayContaining([ - expect.objectContaining({resource: 'GitHub Release', action: 'reuse'}), - ]), - }, - }) -}) - -test('reader only sends GET and treats HTTP errors as failures, not missing resources', () => { - expect(check('get-only')).toMatchObject({ - transportError: expect.stringContaining('HTTP 404'), - }) -}) - -test('new preparation prints dependent requests and skips every write and build dispatch', () => { - expect(check('plan-new')).toMatchObject({ - execution: { - status: 'complete', - steps: expect.arrayContaining([ - expect.objectContaining({ - id: 'prepared-commit', - result: 'skipped-dry-run', - request: expect.objectContaining({ - body: expect.objectContaining({ - tree: {fromStep: 'release-tree', field: 'sha'}, - parents: ['source'], - }), - }), - }), - expect.objectContaining({ - id: 'branch-tip', - request: expect.objectContaining({ - body: { - sha: {fromStep: 'prepared-commit', field: 'sha'}, - force: false, - }, - }), - }), - expect.objectContaining({ - id: 'build-ios', - result: 'skipped-dry-run', - request: expect.objectContaining({ - body: { - ref: '1.2.3', - inputs: { - profile: 'production', - submit: false, - testFlightGroup: 'none', - sourceRef: {fromStep: 'prepared-commit', field: 'sha'}, - }, - }, - }), - }), - expect.objectContaining({ - id: 'build-web', - result: 'skipped-dry-run', - request: expect.objectContaining({ - body: { - ref: '1.2.3', - inputs: {sourceRef: {fromStep: 'prepared-commit', field: 'sha'}}, - }, - }), - }), - ]), - }, - }) -}) - -test('retry reuses the verified commit and puts its real SHA into native build inputs', () => { - expect(check('plan-matching')).toMatchObject({ - execution: { - status: 'complete', - steps: expect.arrayContaining([ - expect.objectContaining({ - id: 'prepared-commit', - action: 'reuse', - value: 'candidate', - }), - expect.objectContaining({ - id: 'build-android', - request: expect.objectContaining({ - body: expect.objectContaining({ - inputs: { - profile: 'production', - submit: false, - sourceRef: 'candidate', - }, - }), - }), - }), - ]), - }, - }) -}) - -test('a change between proposed writes stops the remaining plan', () => { - expect(check('plan-drift')).toMatchObject({ - execution: { - status: 'blocked', - steps: expect.arrayContaining([ - expect.objectContaining({id: 'branch', result: 'skipped-dry-run'}), - expect.objectContaining({id: 'release-tree', result: 'blocked'}), - ]), - }, - }) -}) - -test('a missing or changed build workflow blocks all proposed operations', () => { - expect(check('plan-drift')).not.toMatchObject({ - execution: { - steps: expect.arrayContaining([ - expect.objectContaining({id: 'build-web', result: 'skipped-dry-run'}), - ]), - }, - }) - expect(check('plan-disabled')).toMatchObject({ - execution: {status: 'blocked', reason: expect.stringContaining('disabled')}, - }) - - expect(check('plan-workflow')).toMatchObject({ - execution: { - status: 'blocked', - reason: expect.stringContaining('build-and-push-bskyweb-aws.yaml'), - }, - }) -}) - -test('planned build inputs match the actual dispatch definitions and no live option exists', () => { - const result = spawnSync( - process.execPath, - [ - '--input-type=module', - '-e', - ` - import {readFileSync} from 'node:fs' - import {createRequire} from 'node:module' - import assert from 'node:assert/strict' - import {buildWorkflows,workflowHashes} from ${JSON.stringify(plannerUrl)} - const yaml = createRequire(import.meta.url)('js-yaml') - for (const build of buildWorkflows) { - const workflow = yaml.load(readFileSync('.github/workflows/' + build.file,'utf8')) - assert('workflow_dispatch' in workflow.on) - const definitions = workflow.on.workflow_dispatch?.inputs ?? {} - const inputs = {...build.inputs,sourceRef:'candidate'} - for (const [key,value] of Object.entries(inputs)) { - assert(definitions[key], key) - if (definitions[key].type === 'boolean') assert.equal(typeof value,'boolean') - if (definitions[key].options) assert(definitions[key].options.includes(value)) - } - for (const [key,definition] of Object.entries(definitions)) if (definition.required && definition.default === undefined) assert(key in inputs) - assert.match(workflowHashes()[build.file], /^[a-f0-9]{40}$/) - const job = workflow.jobs.build ?? workflow.jobs['bskyweb-container-aws'] - const checkout = job.steps.find(step => step.uses?.startsWith('actions/checkout@')) - assert.equal(checkout.with.ref, '${'$'}{{ inputs.sourceRef || github.sha }}') - assert.equal(job.outputs['source-sha'], '${'$'}{{ steps.source.outputs.sha }}') - if (build.platform !== 'web') { - assert.equal(workflow.on.workflow_call.inputs.sourceRef.default, '') - assert.equal(workflow.on.workflow_call.inputs.submit.default, true) - assert.equal(workflow.jobs.submit.if, '${'$'}{{ inputs.submit != false }}') - assert.equal(workflow.jobs.submit.steps.find(step => step.uses?.startsWith('actions/checkout@')).with.ref, '${'$'}{{ needs.build.outputs.source-sha }}') - } else { - const metadata = job.steps.find(step => step.uses?.startsWith('docker/metadata-action@')) - assert(metadata.with.tags.includes('${'$'}{{ steps.source.outputs.sha }}')) - assert(metadata.with.labels.includes('${'$'}{{ steps.source.outputs.sha }}')) - } - - } - `, - ], - {encoding: 'utf8'}, - ) - expect(result.stderr).toBe('') - expect(result.status).toBe(0) - const live = spawnSync( - process.execPath, - [resolve('scripts/release/plan.mjs'), 'report', 'owner/repo', '--apply'], - {encoding: 'utf8'}, - ) - expect(live.status).toBe(1) - expect(live.stderr).toContain('Live execution is not available') -}) - -test('read-only draft visibility allows a conditional dry-run plan but still catches conflicts', () => { - expect(check('plan-hidden')).toMatchObject({ - github: { - status: 'incomplete', - checks: expect.arrayContaining([ - expect.objectContaining({ - resource: 'GitHub Release', - action: 'unverified', - }), - ]), - }, - execution: { - status: 'complete-with-warnings', - steps: expect.arrayContaining([ - expect.objectContaining({ - id: 'draft', - precondition: expect.stringContaining('Confirm that no draft exists'), - result: 'skipped-dry-run', - }), - expect.objectContaining({id: 'build-web', result: 'skipped-dry-run'}), - ]), - }, - }) - expect(check('plan-hidden-published')).toMatchObject({ - github: {status: 'blocked'}, - execution: {status: 'blocked'}, - }) -}) diff --git a/scripts/release/cli.mjs b/scripts/release/cli.mjs deleted file mode 100644 index 46cdbae8a..000000000 --- a/scripts/release/cli.mjs +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env node - -import {readFileSync, writeFileSync} from 'node:fs' - -import { - ReleaseError, - appendOtaChangelog, - createReleaseDocument, - deriveReleaseIdentity, - extractPublicChangelog, - finalizeReleaseDocument, - parseReleaseDocument, -} from './model.mjs' - -function usage() { - return `Usage: - node scripts/release/cli.mjs identity - node scripts/release/cli.mjs create - node scripts/release/cli.mjs validate [prepared|final] - node scripts/release/cli.mjs extract-public - node scripts/release/cli.mjs append-ota - node scripts/release/cli.mjs finalize ` -} - -function requireArgs(args, count) { - if (args.length !== count) throw new ReleaseError(usage()) -} - -function read(path) { - return readFileSync(path, 'utf8') -} - -function write(path, content) { - writeFileSync(path, content, 'utf8') -} - -function run([command, ...args]) { - switch (command) { - case 'identity': { - requireArgs(args, 1) - console.log(JSON.stringify(deriveReleaseIdentity(args[0]), null, 2)) - return - } - case 'create': { - requireArgs(args, 3) - const [version, changelogFile, outputFile] = args - write(outputFile, createReleaseDocument(version, read(changelogFile))) - console.log(`Created ${outputFile}`) - return - } - case 'validate': { - if (args.length < 1 || args.length > 2) throw new ReleaseError(usage()) - const [releaseFile, stage = 'prepared'] = args - const parsed = parseReleaseDocument(read(releaseFile), { - filename: releaseFile.split('/').at(-1), - stage, - }) - console.log( - `Validated ${releaseFile} as a ${stage} release for ${parsed.metadata.releaseVersion}`, - ) - return - } - case 'extract-public': { - requireArgs(args, 1) - process.stdout.write(`${extractPublicChangelog(read(args[0]))}\n`) - return - } - case 'append-ota': { - requireArgs(args, 3) - const [releaseFile, rawSequence, changelogFile] = args - const sequence = Number(rawSequence) - write( - releaseFile, - appendOtaChangelog(read(releaseFile), sequence, read(changelogFile)), - ) - console.log(`Added OTA ${rawSequence} to ${releaseFile}`) - return - } - case 'finalize': { - requireArgs(args, 5) - const [ - releaseFile, - sourceTag, - sourceSha, - iosBuildNumber, - androidVersionCode, - ] = args - write( - releaseFile, - finalizeReleaseDocument(read(releaseFile), { - sourceTag, - sourceSha, - iosBuildNumber, - androidVersionCode, - }), - ) - console.log(`Finalized ${releaseFile}`) - return - } - default: - throw new ReleaseError(usage()) - } -} - -try { - run(process.argv.slice(2)) -} catch (error) { - if (error instanceof ReleaseError) { - console.error(`Error: ${error.message}`) - process.exitCode = 1 - } else { - throw error - } -} diff --git a/scripts/release/common.sh b/scripts/release/common.sh deleted file mode 100644 index 5765bf5dc..000000000 --- a/scripts/release/common.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -fail() { echo "::error::$*" >&2; exit 1; } -summary() { echo "$*" | tee -a "$GITHUB_STEP_SUMMARY"; } -api() { gh api "repos/$GH_REPO/$@"; } - -[[ "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || fail 'Expected strict x.y.z version.' -BRANCH="release-$VERSION" -FILE="RELEASE-$VERSION.md" -WORKFLOWS=(build-submit-ios.yml build-submit-android.yml build-and-push-bskyweb-aws.yaml) - -# Empty results mean absent; authentication and network failures still abort. -ref_sha() { - api "git/matching-refs/$1" | jq -er --arg ref "refs/$1" ' - [.[] | select(.ref == $ref)] | - if length == 0 then "" elif length == 1 and .[0].object.type == "commit" - then .[0].object.sha else error("Unexpected ref type or count") end' -} - -releases() { - api 'releases?per_page=100' --paginate --slurp | - jq -c --arg tag "$VERSION" '[.[][] | select(.tag_name == $tag)]' -} - -validate_source() { - [[ "$BASE_SHA" =~ ^[0-9a-f]{40}$ ]] || fail 'Expected full source SHA.' - git -C source merge-base --is-ancestor "$BASE_SHA" "$TOOLING_SHA" || fail 'Source is not in the trusted main history.' - [[ "$(git -C source rev-parse --is-shallow-repository)" == false ]] || fail 'Full source history is required.' - [[ -z "$(git -C source status --porcelain)" ]] || fail 'Source checkout is dirty.' - node tooling/scripts/release/validate.cjs source "$VERSION" "$1" - api '' | jq -e '.permissions.push == true' >/dev/null || fail 'Cannot establish visibility of all draft releases.' - for workflow in "${WORKFLOWS[@]}"; do - cmp "tooling/.github/workflows/$workflow" "source/.github/workflows/$workflow" || fail "Unreviewed build workflow: $workflow" - api "actions/workflows/$workflow" | jq -e --arg path ".github/workflows/$workflow" \ - '.state == "active" and .path == $path' >/dev/null || fail "Build workflow is not active: $workflow" - done -} - -require_new_release() { - [[ -z "$(ref_sha "heads/$BRANCH")" ]] || fail 'Release branch already exists; use Run Release for recovery.' - [[ -z "$(ref_sha "tags/$VERSION")" ]] || fail 'Release tag already exists.' - [[ "$(releases)" == '[]' ]] || fail 'GitHub Release already exists.' - for platform in ios android web; do - [[ -z "$(ref_sha "heads/release-build-$VERSION-$platform")" ]] || fail 'Build reservation already exists.' - done -} - -verify_prepared() { - [[ "$(ref_sha "heads/$BRANCH")" == "$PREPARED_SHA" ]] || fail 'Release branch moved.' - local tag - tag=$(ref_sha "tags/$VERSION") - [[ -z "$tag" || "$tag" == "$PREPARED_SHA" ]] || fail 'Release tag points to another commit.' - if [[ "${REQUIRE_TAG:-false}" == true ]]; then - [[ "$tag" == "$PREPARED_SHA" ]] || fail 'Release tag is missing.' - fi - RELEASES=$(releases) - jq -e --arg sha "$PREPARED_SHA" --arg name "Release $VERSION" ' - length == 0 or (length == 1 and .[0].draft == true and - .[0].prerelease == false and .[0].name == $name and .[0].target_commitish == $sha) - ' <<< "$RELEASES" >/dev/null || fail 'Existing release is published or has a different identity.' - if [[ "${REQUIRE_DRAFT:-false}" == true ]]; then - [[ "$(jq length <<< "$RELEASES")" == 1 ]] || fail 'Draft release is missing.' - fi -} - -generate_notes() { - local previous_tag - previous_tag=$(git -C source tag --merged "$BASE_SHA" --sort=-version:refname | - awk -v version="$VERSION" '/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/ && $0 != version {print; exit}') - local args=(-f "tag_name=$VERSION" -f "target_commitish=$BASE_SHA") - if [[ -n "$previous_tag" ]]; then args+=(-f "previous_tag_name=$previous_tag"); fi - api releases/generate-notes -X POST "${args[@]}" --jq .body > "$RUNNER_TEMP/notes.md" - [[ -s "$RUNNER_TEMP/notes.md" ]] || fail 'GitHub generated empty notes.' -} diff --git a/scripts/release/create.sh b/scripts/release/create.sh deleted file mode 100644 index 30da7c6b9..000000000 --- a/scripts/release/create.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -source tooling/scripts/release/common.sh -BASE_SHA=$(git -C source rev-parse HEAD) -validate_source source -[[ ! -e "source/$FILE" ]] || fail 'Source already contains this release document.' -require_new_release -# Check the handoff before creating anything. -api actions/workflows/run-release.yml | jq -e '.state == "active" and .path == ".github/workflows/run-release.yml"' >/dev/null - -generate_notes -{ - printf '%s\n' '---' "releaseVersion: $VERSION" '---' '' "# Release $VERSION" '' '' '' '## Initial release' '' - # Nest GitHub headings under the release document's Initial release section. - sed 's/^## /### /' "$RUNNER_TEMP/notes.md" - printf '\n%s\n' '' -} > "$RUNNER_TEMP/$FILE" -summary "Source: $BASE_SHA. Version, runtime, ancestry, workflows, and release conflicts checked." -if [[ "$DRY_RUN" == true ]]; then - summary 'Preview only: no branch, tag, release, or builds created.' - cat "$RUNNER_TEMP/$FILE" >> "$GITHUB_STEP_SUMMARY" - exit 0 -fi - -require_new_release -base_tree=$(api "git/commits/$BASE_SHA" --jq .tree.sha) -jq -n --arg tree "$base_tree" --arg path "$FILE" --rawfile content "$RUNNER_TEMP/$FILE" \ - '{base_tree: $tree, tree: [{path: $path, mode: "100644", type: "blob", content: $content}]}' > "$RUNNER_TEMP/tree.json" -tree=$(api git/trees -X POST --input "$RUNNER_TEMP/tree.json" --jq .sha) -jq -n --arg tree "$tree" --arg parent "$BASE_SHA" --arg message "Prepare release $VERSION" \ - '{tree: $tree, parents: [$parent], message: $message}' > "$RUNNER_TEMP/commit.json" -PREPARED_SHA=$(api git/commits -X POST --input "$RUNNER_TEMP/commit.json" --jq .sha) -require_new_release -# Create the branch directly at the prepared commit; never advance or force a ref. -api git/refs -X POST -f "ref=refs/heads/$BRANCH" -f "sha=$PREPARED_SHA" >/dev/null -summary "Created $BRANCH at $PREPARED_SHA (source $BASE_SHA)." -verify_prepared -{ - echo "source-sha=$BASE_SHA" - echo "prepared-sha=$PREPARED_SHA" -} >> "$GITHUB_OUTPUT" diff --git a/scripts/release/model.mjs b/scripts/release/model.mjs deleted file mode 100644 index b7d2c931e..000000000 --- a/scripts/release/model.mjs +++ /dev/null @@ -1,293 +0,0 @@ -const VERSION_COMPONENT = '(?:0|[1-9][0-9]*)' -const VERSION_PATTERN = new RegExp( - `^${VERSION_COMPONENT}\\.${VERSION_COMPONENT}\\.${VERSION_COMPONENT}$`, -) -const RELEASE_FILENAME_PATTERN = new RegExp( - `^RELEASE-(${VERSION_COMPONENT}\\.${VERSION_COMPONENT}\\.${VERSION_COMPONENT})\\.md$`, -) -const SOURCE_SHA_PATTERN = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/ -const POSITIVE_INTEGER_PATTERN = /^[1-9][0-9]*$/ - -const FRONTMATTER_KEYS = [ - 'releaseVersion', - 'sourceTag', - 'sourceSha', - 'iosBuildNumber', - 'androidVersionCode', -] - -const PUBLIC_CHANGELOG_START = '' -const PUBLIC_CHANGELOG_END = '' - -export class ReleaseError extends Error { - constructor(message) { - super(message) - this.name = 'ReleaseError' - } -} - -function fail(message) { - throw new ReleaseError(message) -} - -function normalizeLineEndings(markdown) { - return markdown.replace(/\r\n?/g, '\n') -} - -export function assertReleaseVersion(version) { - if (typeof version !== 'string' || !VERSION_PATTERN.test(version)) { - fail(`Release version must use strict x.y.z format; found '${version}'.`) - } - return version -} - -export function deriveReleaseIdentity(version) { - assertReleaseVersion(version) - return Object.freeze({ - version, - branch: `release-${version}`, - tag: version, - filename: `RELEASE-${version}.md`, - githubReleaseName: `Release ${version}`, - }) -} - -function parseFrontmatter(markdown) { - const normalized = normalizeLineEndings(markdown) - if (!normalized.startsWith('---\n')) { - fail('Release file must start with YAML frontmatter.') - } - - const end = normalized.indexOf('\n---\n', 4) - if (end === -1) fail('Release file frontmatter is not closed.') - - const metadata = {} - const lines = normalized.slice(4, end).split('\n') - for (const line of lines) { - if (!line.trim()) continue - const match = /^([A-Za-z][A-Za-z0-9]*):[ \t]*(.*)$/.exec(line) - if (!match) fail(`Unsupported frontmatter line: '${line}'.`) - - const [, key, rawValue] = match - if (!FRONTMATTER_KEYS.includes(key)) { - fail(`Unknown release frontmatter field '${key}'.`) - } - if (Object.hasOwn(metadata, key)) { - fail(`Duplicate release frontmatter field '${key}'.`) - } - if (!rawValue) fail(`Release frontmatter field '${key}' cannot be empty.`) - metadata[key] = rawValue - } - - const body = normalized.slice(end + 5) - if (!body.startsWith('\n')) { - fail('Release file must contain a blank line after frontmatter.') - } - - return {metadata, body: body.slice(1)} -} - -function findDelimitedSection(body, startMarker, endMarker) { - const start = body.indexOf(startMarker) - const end = body.indexOf(endMarker) - if (start === -1 || end === -1) { - fail('Release file must contain the public changelog delimiters.') - } - if ( - start !== body.lastIndexOf(startMarker) || - end !== body.lastIndexOf(endMarker) - ) { - fail('Public changelog delimiters must occur exactly once.') - } - if (end < start) - fail('Public changelog end delimiter precedes its start delimiter.') - - return { - before: body.slice(0, start + startMarker.length), - content: body.slice(start + startMarker.length, end).trim(), - after: body.slice(end), - } -} - -function parseChangelogSections(publicChangelog) { - const unsupportedHeading = publicChangelog.match( - /^## (?!Initial release\s*$|OTA [1-9][0-9]*\s*$).+$/m, - ) - if (unsupportedHeading) { - fail(`Unsupported public changelog section '${unsupportedHeading[0]}'.`) - } - - const headings = [ - ...publicChangelog.matchAll( - /^## (Initial release|OTA ([1-9][0-9]*))\s*$/gm, - ), - ] - if (!headings.length || headings[0][1] !== 'Initial release') { - fail("Public changelog must begin with an '## Initial release' section.") - } - - const prefix = publicChangelog.slice(0, headings[0].index).trim() - if (prefix) - fail( - 'Public changelog cannot contain content before its initial release section.', - ) - - const sections = headings.map((heading, index) => { - const start = heading.index + heading[0].length - const end = headings[index + 1]?.index ?? publicChangelog.length - const content = publicChangelog.slice(start, end).trim() - if (!content) fail(`Changelog section '${heading[1]}' cannot be empty.`) - return { - type: heading[1] === 'Initial release' ? 'initial' : 'ota', - sequence: heading[2] ? Number(heading[2]) : null, - content, - } - }) - - sections.slice(1).forEach((section, index) => { - const expected = index + 1 - if (section.type !== 'ota' || section.sequence !== expected) { - fail( - `OTA changelog sections must be contiguous; expected OTA ${expected}.`, - ) - } - }) - - return sections -} - -function validateMetadata(metadata, stage) { - assertReleaseVersion(metadata.releaseVersion) - - if (metadata.sourceTag !== undefined) { - assertReleaseVersion(metadata.sourceTag) - if (metadata.sourceTag !== metadata.releaseVersion) { - fail('sourceTag must match releaseVersion.') - } - } - if ( - metadata.sourceSha !== undefined && - !SOURCE_SHA_PATTERN.test(metadata.sourceSha) - ) { - fail('sourceSha must be a full lowercase hexadecimal Git object ID.') - } - for (const key of ['iosBuildNumber', 'androidVersionCode']) { - if ( - metadata[key] !== undefined && - !POSITIVE_INTEGER_PATTERN.test(metadata[key]) - ) { - fail(`${key} must be a positive integer.`) - } - } - - if (stage === 'final') { - for (const key of FRONTMATTER_KEYS) { - if (metadata[key] === undefined) { - fail(`Finalized release file is missing '${key}'.`) - } - } - } -} - -export function parseReleaseDocument(markdown, options = {}) { - if (typeof markdown !== 'string') fail('Release document must be a string.') - const stage = options.stage ?? 'prepared' - if (!['prepared', 'final'].includes(stage)) { - fail(`Unknown release validation stage '${stage}'.`) - } - - const {metadata, body} = parseFrontmatter(markdown) - validateMetadata(metadata, stage) - - const expectedTitle = `# Release ${metadata.releaseVersion}` - if (!body.startsWith(`${expectedTitle}\n`)) { - fail( - `Release document must begin with '${expectedTitle}' after frontmatter.`, - ) - } - - if (options.filename !== undefined) { - const filenameMatch = RELEASE_FILENAME_PATTERN.exec(options.filename) - if (!filenameMatch || filenameMatch[1] !== metadata.releaseVersion) { - fail(`Filename must be 'RELEASE-${metadata.releaseVersion}.md'.`) - } - } - - const delimited = findDelimitedSection( - body, - PUBLIC_CHANGELOG_START, - PUBLIC_CHANGELOG_END, - ) - const sections = parseChangelogSections(delimited.content) - - return Object.freeze({ - metadata: Object.freeze({...metadata}), - publicChangelog: delimited.content, - sections: Object.freeze(sections.map(section => Object.freeze(section))), - }) -} - -export function createReleaseDocument(version, initialChangelog) { - assertReleaseVersion(version) - const content = initialChangelog?.trim() - if (!content) fail('Initial release changelog cannot be empty.') - - return `--- -releaseVersion: ${version} ---- - -# Release ${version} - -${PUBLIC_CHANGELOG_START} - -## Initial release - -${content} - -${PUBLIC_CHANGELOG_END} -` -} - -export function extractPublicChangelog(markdown) { - return parseReleaseDocument(markdown).publicChangelog -} - -export function appendOtaChangelog(markdown, sequence, changelog) { - const normalized = normalizeLineEndings(markdown) - const parsed = parseReleaseDocument(normalized) - const expectedSequence = parsed.sections.length - if (!Number.isSafeInteger(sequence) || sequence !== expectedSequence) { - fail(`Next OTA sequence must be ${expectedSequence}; found '${sequence}'.`) - } - const content = changelog?.trim() - if (!content) fail('OTA changelog cannot be empty.') - - const delimiter = `\n\n${PUBLIC_CHANGELOG_END}` - if (!normalized.includes(delimiter)) { - fail('Could not find the public changelog end delimiter to append the OTA.') - } - const replacement = `\n\n## OTA ${sequence}\n\n${content}${delimiter}` - const updated = normalized.replace(delimiter, replacement) - parseReleaseDocument(updated) - return updated -} - -export function finalizeReleaseDocument(markdown, finalMetadata) { - const normalized = normalizeLineEndings(markdown) - const parsed = parseReleaseDocument(normalized) - const metadata = {...parsed.metadata, ...finalMetadata} - validateMetadata(metadata, 'final') - - const frontmatter = FRONTMATTER_KEYS.map( - key => `${key}: ${metadata[key]}`, - ).join('\n') - const frontmatterPattern = /^---\n[\s\S]*?\n---\n/ - if (!frontmatterPattern.test(normalized)) - fail('Could not replace the release frontmatter.') - const updated = normalized.replace( - frontmatterPattern, - `---\n${frontmatter}\n---\n`, - ) - parseReleaseDocument(updated, {stage: 'final'}) - return updated -} diff --git a/scripts/release/plan.mjs b/scripts/release/plan.mjs deleted file mode 100644 index 51a0558e1..000000000 --- a/scripts/release/plan.mjs +++ /dev/null @@ -1,287 +0,0 @@ -import {createHash} from 'node:crypto' -import {readFileSync, writeFileSync} from 'node:fs' -import {dirname, join, resolve} from 'node:path' -import {fileURLToPath, pathToFileURL} from 'node:url' - -import {checkGitHub, githubReader} from './check-github.mjs' -import {renderReport} from './prepare.mjs' - -export const buildWorkflows = [ - { - platform: 'iOS', - file: 'build-submit-ios.yml', - inputs: {profile: 'production', submit: false, testFlightGroup: 'none'}, - }, - { - platform: 'Android', - file: 'build-submit-android.yml', - inputs: {profile: 'production', submit: false}, - }, - { - platform: 'web', - file: 'build-and-push-bskyweb-aws.yaml', - inputs: {}, - }, -] - -/** Keep dispatch plans tied to the workflow definitions reviewed with this tool. */ -export function workflowHashes() { - const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..') - return Object.fromEntries( - buildWorkflows.map(({file}) => { - const content = readFileSync(join(root, '.github/workflows', file)) - const sha = createHash('sha1') - .update(`blob ${content.length}\0`) - .update(content) - .digest('hex') - return [file, sha] - }), - ) -} - -/** An output reference is deliberately not a fake Git SHA or an executable API value. */ -function output(step, field) { - return {fromStep: step, field} -} - -/** Construct ordered request templates. This function cannot send them. */ -export function planRelease(report, repository, hashes) { - if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository)) - throw new Error('Expected repository owner/name.') - const plan = { - mode: 'dry-run', - status: 'planned', - steps: [], - pending: [ - 'Build completion and artifact-derived build numbers.', - 'Final release file and manual app release.', - ], - } - if ( - !['ready', 'incomplete'].includes(report.github?.status) || - !report.github.observed - ) - return { - ...plan, - status: 'blocked', - reason: 'GitHub checks must pass before requests can be planned.', - } - plan.warnings = report.github.checks - .filter(check => check.action === 'unverified') - .map(check => check.detail) - const {identity, sourceSha, document, publicChangelog} = report - const {sourceTreeSha, sourceTree, candidateSha} = report.github.observed - const action = resource => - report.github.checks.find(check => check.resource === resource)?.action - const add = (id, label, method, path, body, dependsOn = []) => - plan.steps.push({ - id, - label, - dependsOn, - request: {method, path: `repos/${repository}/${path}`, body}, - }) - const reuse = (id, label, value) => - plan.steps.push({id, label, action: 'reuse', value}) - if (action('branch') === 'reuse') - reuse( - 'branch', - 'Reuse release branch', - report.github.observed.branch.object.sha, - ) - else - add('branch', 'Create release branch', 'POST', 'git/refs', { - ref: `refs/heads/${identity.branch}`, - sha: sourceSha, - }) - let candidate = candidateSha - if (candidate) - reuse('prepared-commit', 'Reuse verified release file commit', candidate) - else { - add( - 'release-tree', - 'Write release file into a new Git tree', - 'POST', - 'git/trees', - { - base_tree: sourceTreeSha, - tree: [ - { - path: identity.filename, - mode: '100644', - type: 'blob', - content: document, - }, - ], - }, - ['branch'], - ) - add( - 'prepared-commit', - 'Commit release file', - 'POST', - 'git/commits', - { - message: `Prepare release ${identity.version}`, - tree: output('release-tree', 'sha'), - parents: [sourceSha], - }, - ['release-tree'], - ) - candidate = output('prepared-commit', 'sha') - add( - 'branch-tip', - 'Advance release branch to prepared commit', - 'PATCH', - `git/refs/heads/${identity.branch}`, - {sha: candidate, force: false}, - ['prepared-commit'], - ) - } - if (action('tag') === 'reuse') - reuse('tag', 'Reuse verified release tag', identity.tag) - else - add( - 'tag', - 'Create release tag', - 'POST', - 'git/refs', - {ref: `refs/tags/${identity.tag}`, sha: candidate}, - [candidateSha ? 'prepared-commit' : 'branch-tip'], - ) - if (action('GitHub Release') === 'reuse') - reuse( - 'draft', - 'Reuse matching draft release', - report.github.observed.releases[0].id, - ) - else - add( - 'draft', - 'Create draft GitHub Release', - 'POST', - 'releases', - { - tag_name: identity.tag, - target_commitish: candidate, - name: identity.githubReleaseName, - body: publicChangelog, - draft: true, - prerelease: false, - }, - ['tag'], - ) - if (action('GitHub Release') === 'unverified') { - plan.steps.find(step => step.id === 'draft').precondition = - `Confirm that no draft exists for tag ${identity.tag} with a token that has release permissions.` - } - for (const build of buildWorkflows) { - const path = `.github/workflows/${build.file}` - const file = sourceTree.find(entry => entry.path === path) - if (!hashes[build.file] || file?.sha !== hashes[build.file]) { - plan.status = 'blocked' - plan.reason = `Selected source has a missing or different ${path}; its build inputs have not been verified by this tool.` - } - add( - `build-${build.platform.toLowerCase()}`, - `Request ${build.platform} build`, - 'POST', - `actions/workflows/${build.file}/dispatches`, - { - ref: identity.tag, - inputs: { - ...build.inputs, - sourceRef: candidate, - }, - }, - ['draft'], - ) - } - plan.notes = [ - 'Requests are templates only. Objects with fromStep/field refer to outputs that do not exist until a live request succeeds.', - 'All workflow dispatches use the release tag and receive the exact prepared commit. Native builds have store submission disabled.', - 'The web workflow would build and push a production image to ECR. No workflow is dispatched in this dry run.', - 'Existing build runs and receipts are not checked here. A future live runner must prevent duplicate dispatches when retrying.', - ] - return plan -} - -/** Re-read GitHub before each proposed operation, but never execute a write or dispatch. */ -export async function dryRunRelease( - report, - repository, - read, - hashes = workflowHashes(), -) { - const checked = await checkGitHub(report, read) - const plan = planRelease(checked, repository, hashes) - const baseline = JSON.stringify(checked.github.observed) - if (plan.status !== 'blocked') { - for (const step of plan.steps) { - const fresh = await checkGitHub(report, read) - step.checkedAt = fresh.github.checkedAt - if ( - !['ready', 'incomplete'].includes(fresh.github.status) || - JSON.stringify(fresh.github.observed) !== baseline - ) { - plan.status = 'blocked' - plan.reason = `GitHub changed or could not be verified before ${step.id}. No requests were sent.` - step.result = 'blocked' - plan.latestChecks = fresh.github.checks - break - } - const build = buildWorkflows.find( - item => step.id === `build-${item.platform.toLowerCase()}`, - ) - if (build) { - try { - const workflow = await read(`actions/workflows/${build.file}`) - if ( - workflow.state !== 'active' || - workflow.path !== `.github/workflows/${build.file}` - ) - throw new Error('Workflow is disabled or its path differs.') - } catch (error) { - plan.status = 'blocked' - plan.reason = `Cannot request ${build.platform} build: ${error.message}` - step.result = 'blocked' - break - } - } - step.result = - step.action === 'reuse' ? 'verified-reuse' : 'skipped-dry-run' - } - if (plan.status !== 'blocked') - plan.status = plan.warnings.length ? 'complete-with-warnings' : 'complete' - } - return {...checked, execution: plan} -} - -if ( - process.argv[1] && - import.meta.url === pathToFileURL(resolve(process.argv[1])).href -) { - try { - const [directory, repository, ...extra] = process.argv.slice(2) - if (!directory || !repository || extra.length) - throw new Error( - 'Usage: node scripts/release/plan.mjs REPORT_DIRECTORY OWNER/REPO. Live execution is not available.', - ) - const report = await dryRunRelease( - JSON.parse(readFileSync(join(directory, 'report.json'), 'utf8')), - repository, - githubReader(repository, process.env.GH_TOKEN), - ) - report.github.repository = repository - writeFileSync( - join(directory, 'report.json'), - JSON.stringify(report, null, 2) + '\n', - ) - const markdown = renderReport(report) - writeFileSync(join(directory, 'README.md'), markdown) - process.stdout.write(markdown) - if (report.execution.status === 'blocked') process.exitCode = 1 - } catch (error) { - process.stderr.write(`${error.message}\n`) - process.exitCode = 1 - } -} diff --git a/scripts/release/prepare.mjs b/scripts/release/prepare.mjs deleted file mode 100644 index 20df814b3..000000000 --- a/scripts/release/prepare.mjs +++ /dev/null @@ -1,214 +0,0 @@ -import {execFileSync} from 'node:child_process' -import {mkdirSync, readFileSync, writeFileSync} from 'node:fs' -import {createRequire} from 'node:module' -import {join, resolve} from 'node:path' -import {pathToFileURL} from 'node:url' - -import { - createReleaseDocument, - deriveReleaseIdentity, - parseReleaseDocument, -} from './model.mjs' - -/** Read a selected checkout and describe release preparation without changing it. */ -export function prepareRelease(sourceDirectory, releaseVersion) { - const identity = deriveReleaseIdentity(releaseVersion) - const source = resolve(sourceDirectory) - const git = (...args) => - execFileSync('git', ['-C', source, ...args], {encoding: 'utf8'}).trim() - if (git('status', '--porcelain', '--untracked-files=no')) { - throw new Error( - 'The source checkout has tracked changes. Commit or discard them first.', - ) - } - if (git('rev-parse', '--is-shallow-repository') !== 'false') { - throw new Error('Full Git history is required to generate the changelog.') - } - const sourceSha = git('rev-parse', 'HEAD') - const packageVersion = JSON.parse( - readFileSync(join(source, 'package.json'), 'utf8'), - ).version - const require = createRequire(join(source, 'package.json')) - delete require.cache[require.resolve('./app.config.js')] - const expo = require('./app.config.js')({}).expo - if (packageVersion !== releaseVersion || expo.version !== releaseVersion) { - throw new Error( - `Requested ${releaseVersion}, but package version is ${packageVersion} and Expo version is ${expo.version}.`, - ) - } - if (expo.runtimeVersion?.policy !== 'appVersion') { - throw new Error( - 'Expected Expo runtimeVersion.policy to be appVersion. Review the runtime policy before preparing this release.', - ) - } - const previousTag = - git('tag', '--merged', sourceSha, '--sort=-version:refname') - .split('\n') - .find( - tag => - /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(tag) && - tag !== releaseVersion, - ) || null - const changelog = - git( - 'log', - '--no-merges', - '--pretty=format:- %s', - previousTag ? `${previousTag}..${sourceSha}` : sourceSha, - ) || '- No changes since the previous release.' - const document = createReleaseDocument(releaseVersion, changelog) - const {publicChangelog} = parseReleaseDocument(document, { - filename: identity.filename, - }) - return { - mode: 'dry-run', - identity, - sourceSha, - packageVersion, - expoVersion: expo.version, - runtimePolicy: expo.runtimeVersion.policy, - previousTag, - document, - publicChangelog, - steps: [ - `Create ${identity.branch} from ${sourceSha}.`, - `Commit ${identity.filename} to that branch. Its contents are included below.`, - `Create draft GitHub Release "${identity.githubReleaseName}" with tag ${identity.tag} and the public notes below.`, - 'Request production iOS, Android, and web builds from the prepared commit.', - 'After successful builds, record their actual build numbers and source commit in the release file.', - 'Leave the app release to a person.', - ], - notChecked: [ - 'Existing GitHub branches, tags, and releases are not checked for conflicts or safe reuse.', - 'Builds, credentials, store submissions, and deployment are not exercised.', - 'The prepared commit, build numbers, and final release file do not exist yet.', - 'Translations are not refreshed. Release notes are provisional commit titles.', - ], - } -} - -/** Format the same report for the terminal and the Actions summary. */ -export function renderReport(report) { - return [ - `# Release ${report.identity.version}: dry run`, - '', - 'Version checks passed. No release branch, commit, tag, GitHub Release, build, or deployment was created.', - '', - `- Source commit: ${report.sourceSha}`, - `- Package / Expo version: ${report.packageVersion} / ${report.expoVersion}`, - `- Runtime policy: ${report.runtimePolicy}`, - `- Previous release tag: ${report.previousTag ?? 'none (using all reachable history)'}`, - `- Release branch: ${report.identity.branch}`, - `- Release tag: ${report.identity.tag}`, - `- GitHub Release: ${report.identity.githubReleaseName}`, - '', - '## GitHub checks', - '', - ...(report.github - ? [ - `Result: ${report.github.status}. Checked at ${report.github.checkedAt}.`, - ...report.github.checks.map( - check => - `- ${check.resource}: **${check.action}** — ${check.detail}`, - ), - '', - 'Create/reuse describes a proposed action only. If any check is blocked, the whole preparation is blocked. These reads are a snapshot; a live run must recheck before writing.', - ] - : [ - 'GitHub has not been checked. Run check-github.mjs to inspect existing resources.', - ]), - '', - ...(report.execution - ? [ - '## Planned requests', - '', - `Dry run: ${report.execution.status}. No requests below were sent.`, - ...(report.execution.reason ? [report.execution.reason] : []), - ...(report.execution.warnings ?? []).map( - warning => `- Unverified: ${warning}`, - ), - '', - ...report.execution.steps.flatMap(step => [ - `### ${step.label}`, - '', - `Result: ${step.result ?? 'not reached'}.`, - ...(step.precondition - ? [`Precondition: ${step.precondition}`] - : []), - ...(step.checkedAt - ? [`GitHub rechecked at ${step.checkedAt}.`] - : []), - ...(step.dependsOn?.length - ? [`Depends on: ${step.dependsOn.join(', ')}.`] - : []), - '', - '
',
-            JSON.stringify(step.request ?? {reuse: step.value}, null, 2)
-              .replaceAll('&', '&')
-              .replaceAll('<', '<')
-              .replaceAll('>', '>'),
-            '
', - '', - ]), - ...(report.execution.notes ?? []).map(note => `- ${note}`), - '', - 'Still pending:', - ...report.execution.pending.map(item => `- ${item}`), - '', - ] - : []), - '## What a real run would do', - '', - ...report.steps.map((step, index) => `${index + 1}. ${step}`), - '', - '## Still unverified', - '', - ...report.notChecked - .filter(item => !report.github || !item.startsWith('Existing GitHub')) - .map(item => `- ${item}`), - '', - `## ${report.identity.filename}`, - '', - '
',
-    report.document
-      .replaceAll('&', '&')
-      .replaceAll('<', '<')
-      .replaceAll('>', '>'),
-    '
', - '', - '## Public release notes', - '', - report.publicChangelog, - '', - ].join('\n') -} - -if ( - process.argv[1] && - import.meta.url === pathToFileURL(resolve(process.argv[1])).href -) { - try { - const [version, source, output, ...extra] = process.argv.slice(2) - if (!version || !source || extra.length) { - throw new Error( - 'Usage: node scripts/release/prepare.mjs VERSION SOURCE_DIRECTORY [NEW_OUTPUT_DIRECTORY]', - ) - } - const report = prepareRelease(source, version) - const markdown = renderReport(report) - if (output) { - mkdirSync(output) - for (const [name, content] of Object.entries({ - 'README.md': markdown, - 'report.json': JSON.stringify(report, null, 2) + '\n', - [report.identity.filename]: report.document, - 'github-release-body.md': report.publicChangelog + '\n', - })) - writeFileSync(join(output, name), content, {flag: 'wx'}) - } - process.stdout.write(markdown) - } catch (error) { - process.stderr.write(`${error.message}\n`) - process.exitCode = 1 - } -} diff --git a/scripts/release/prepare.test.js b/scripts/release/prepare.test.js deleted file mode 100644 index c9fd1ddee..000000000 --- a/scripts/release/prepare.test.js +++ /dev/null @@ -1,116 +0,0 @@ -/* oxlint-disable import/no-nodejs-modules -- This suite exercises a Node CLI with temporary Git repositories. */ -import {execFileSync, spawnSync} from 'node:child_process' -import {mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs' -import {tmpdir} from 'node:os' -import {join, resolve} from 'node:path' - -const cli = resolve('scripts/release/prepare.mjs') -let directory -let source - -function git(...args) { - return execFileSync('git', ['-C', source, ...args], {encoding: 'utf8'}).trim() -} - -function run(version = '1.2.3', output) { - return spawnSync( - process.execPath, - [cli, version, source, ...(output ? [output] : [])], - {encoding: 'utf8'}, - ) -} - -beforeEach(() => { - directory = mkdtempSync(join(tmpdir(), 'release-dry-run-')) - source = join(directory, 'source') - execFileSync('git', ['init', '--quiet', source]) - git('config', 'user.email', 'test@example.com') - git('config', 'user.name', 'Test') - git('config', 'commit.gpgsign', 'false') - git('config', 'tag.gpgsign', 'false') - git('config', 'core.hooksPath', '/dev/null') - writeFileSync(join(source, 'package.json'), '{"version":"1.2.3"}') - writeFileSync( - join(source, 'app.config.js'), - "module.exports = () => ({expo: {version: '1.2.3', runtimeVersion: {policy: 'appVersion'}}})", - ) - git('add', '.') - git('commit', '--quiet', '-m', 'Old change') - git('tag', '1.2.2') - writeFileSync(join(source, 'change.txt'), 'change') - git('add', '.') - git('commit', '--quiet', '-m', 'New change') -}) - -afterEach(() => rmSync(directory, {recursive: true, force: true})) - -test('reads real history and saves notes without changing source or refs; repeats safely', () => { - const before = [ - git('rev-parse', 'HEAD'), - git('show-ref'), - git('status', '--porcelain'), - ] - const output = join(directory, 'report') - const result = run('1.2.3', output) - expect(result.status).toBe(0) - expect(result.stdout).toContain(before[0]) - expect(result.stdout).toContain('release-1.2.3') - expect( - JSON.parse(readFileSync(join(output, 'report.json'), 'utf8')), - ).toMatchObject({ - mode: 'dry-run', - sourceSha: before[0], - previousTag: '1.2.2', - publicChangelog: '## Initial release\n\n- New change', - }) - expect( - readFileSync(join(output, 'github-release-body.md'), 'utf8'), - ).not.toContain('releaseVersion:') - expect(run().stdout).toBe(result.stdout) - expect(run('1.2.3', output).status).toBe(1) - expect([ - git('rev-parse', 'HEAD'), - git('show-ref'), - git('status', '--porcelain'), - ]).toEqual(before) -}) - -test('rejects invalid and mismatched versions before writing a report', () => { - expect(run('01.2.3').stderr).toContain('strict x.y.z') - expect(run('1.2.4').stderr).toContain('package version is 1.2.3') - expect(run('--apply').status).toBe(1) -}) - -test('rejects changed source instead of claiming it matches the commit', () => { - writeFileSync(join(source, 'change.txt'), 'uncommitted') - expect(run().stderr).toContain('tracked changes') -}) - -test('rejects a different runtime policy', () => { - writeFileSync( - join(source, 'app.config.js'), - "module.exports = () => ({expo: {version: '1.2.3', runtimeVersion: {policy: 'fingerprint'}}})", - ) - git('add', '.') - git('commit', '--quiet', '-m', 'Change runtime') - expect(run().stderr).toContain('runtimeVersion.policy') -}) - -test('uses reachable history when there is no previous version tag', () => { - git('tag', '-d', '1.2.2') - expect(run().stdout).toContain('- Old change') - expect(run().stdout).toContain('none (using all reachable history)') -}) - -test('rejects shallow history instead of generating incomplete notes', () => { - const clone = join(directory, 'shallow') - execFileSync('git', [ - 'clone', - '--quiet', - '--depth=1', - `file://${source}`, - clone, - ]) - source = clone - expect(run().stderr).toContain('Full Git history') -}) diff --git a/scripts/release/run.sh b/scripts/release/run.sh deleted file mode 100644 index fe4f0e59e..000000000 --- a/scripts/release/run.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -source tooling/scripts/release/common.sh -[[ "$PREPARED_SHA" =~ ^[0-9a-f]{40}$ ]] || fail 'Expected full prepared SHA.' -[[ "$(git -C source rev-parse HEAD)" == "$PREPARED_SHA" ]] || fail 'Checkout does not match prepared SHA.' -[[ "$(git -C source show -s --format=%P HEAD)" == "$BASE_SHA" ]] || fail 'Prepared commit must have exactly the selected source as its parent.' -[[ "$(git -C source diff-tree --no-commit-id --name-status -r HEAD)" == $'A\t'"$FILE" ]] || fail 'Prepared commit must only add the release document.' -[[ "$(git -C source ls-tree HEAD -- "$FILE" | cut -d ' ' -f 1)" == 100644 ]] || fail 'Release document must be a regular file.' -validate_source prepared -verify_prepared -# Validate all reservations before any write or dispatch. -for platform in ios android web; do - reservation=$(ref_sha "heads/release-build-$VERSION-$platform") - [[ -z "$reservation" || "$reservation" == "$PREPARED_SHA" ]] || fail "Conflicting $platform build reservation." -done -summary "Validated $BRANCH at $PREPARED_SHA (source $BASE_SHA)." -generate_notes -verify_prepared -if [[ -z "$(ref_sha "tags/$VERSION")" ]]; then - api git/refs -X POST -f "ref=refs/tags/$VERSION" -f "sha=$PREPARED_SHA" >/dev/null - summary "Created tag $VERSION at $PREPARED_SHA." -fi -REQUIRE_TAG=true -verify_prepared -if [[ "$RELEASES" == '[]' ]]; then - gh release create "$VERSION" --verify-tag --target "$PREPARED_SHA" --draft \ - --title "Release $VERSION" --notes-file "$RUNNER_TEMP/notes.md" -else - gh release edit "$VERSION" --notes-file "$RUNNER_TEMP/notes.md" -fi -REQUIRE_DRAFT=true -verify_prepared -summary "Draft notes updated for $VERSION." - -if [[ "$START_BUILDS" != true ]]; then - summary 'Build dispatch disabled. Existing builds were not changed.' - exit 0 -fi -platforms=(ios android web) -for index in 0 1 2; do - platform=${platforms[$index]} - workflow=${WORKFLOWS[$index]} - verify_prepared - reservation="heads/release-build-$VERSION-$platform" - if [[ -n "$(ref_sha "$reservation")" ]]; then - summary "$platform dispatch was previously reserved. No new build started; inspect Actions and rerun failed build jobs if needed." - continue - fi - api "actions/workflows/$workflow" | jq -e '.state == "active"' >/dev/null - # Reserve before dispatch: a timeout must never cause an automatic duplicate build. - api git/refs -X POST -f "ref=refs/$reservation" -f "sha=$PREPARED_SHA" >/dev/null - summary "$platform dispatch reserved for $PREPARED_SHA. If no run link follows, inspect Actions before recovery." - verify_prepared - case "$platform" in - ios) inputs='{"profile":"production","submit":"false","testFlightGroup":"none"}' ;; - android) inputs='{"profile":"production","submit":"false"}' ;; - web) inputs='{}' ;; - esac - jq -n --arg ref "$VERSION" --arg sha "$PREPARED_SHA" --argjson inputs "$inputs" \ - '{ref: $ref, inputs: ($inputs + {sourceRef: $sha}), return_run_details: true}' > "$RUNNER_TEMP/dispatch.json" - api "actions/workflows/$workflow/dispatches" -X POST --input "$RUNNER_TEMP/dispatch.json" > "$RUNNER_TEMP/run.json" - jq -e '.workflow_run_id > 0 and (.html_url | type == "string")' "$RUNNER_TEMP/run.json" >/dev/null || fail 'Dispatch outcome uncertain; inspect Actions before retrying.' - summary "$platform build: $(jq -r .html_url "$RUNNER_TEMP/run.json"). Dispatched does not mean successful." -done diff --git a/scripts/release/validate.cjs b/scripts/release/validate.cjs deleted file mode 100644 index f78d28fb2..000000000 --- a/scripts/release/validate.cjs +++ /dev/null @@ -1,39 +0,0 @@ -const assert = require('node:assert/strict') -const {readFileSync} = require('node:fs') -const {resolve} = require('node:path') - -const [source, version, stage] = process.argv.slice(2) -assert.match(version, /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/) -const root = resolve(source) -assert.equal( - require(`${root}/package.json`).version, - version, - 'Package version mismatch', -) -for (const platform of ['ios', 'android', 'web']) { - process.env.EXPO_PUBLIC_ENV = 'production' - process.env.EAS_BUILD_PLATFORM = platform - const {expo} = require(`${root}/app.config.js`)({}) - assert.equal(expo.version, version, `${platform}: Expo version mismatch`) - assert.equal( - expo.runtimeVersion?.policy, - 'appVersion', - `${platform}: unsupported runtime policy`, - ) -} -if (stage === 'prepared') { - const document = readFileSync(`${root}/RELEASE-${version}.md`, 'utf8') - const prefix = `---\nreleaseVersion: ${version}\n---\n\n# Release ${version}\n\n\n\n## Initial release\n\n` - const suffix = '\n\n\n' - assert.ok( - document.startsWith(prefix) && document.endsWith(suffix), - 'Invalid prepared release document', - ) - const notes = document.slice(prefix.length, -suffix.length) - assert.ok(notes.trim(), 'Empty release notes') - assert.ok(!/^## /m.test(notes), 'Unexpected release section') - assert.ok( - !notes.includes('