diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 510895096d..3d07bc0d73 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Release # One workflow owns every npm publish, so each package trusts exactly this file # (npm trusted publishing pins the workflow filename and the npm-publish # environment). scripts/release-plan.mjs maps the triggering event to a mode: -# dry-run (PR), nightly (schedule or dispatch on main), or stable (a vX.Y.Z tag on +# dry-run (PR), nightly (main-owned schedule or dispatch), or stable (a vX.Y.Z tag on # main). The tag ruleset, which only admins can bypass, is the stable release's # approval: a tag publishes without another review. on: @@ -21,8 +21,16 @@ on: # A nightly ships main's HEAD once its CI passes. CI that fails, is cancelled, # or outlasts the Plan job's wait skips that day. - cron: '23 1 * * *' + # The workflow stays on main; the planner resolves 0.22 to its exact source SHA. + - cron: '53 1 * * *' # On main: publish a nightly now. On a vX.Y.Z tag: retry that stable release. workflow_dispatch: + inputs: + source_branch: + description: 'Nightly source (run on main; stable tag retries require main)' + type: choice + options: [main, '0.22'] + default: main permissions: {} @@ -30,6 +38,7 @@ concurrency: group: >- ${{ github.event_name == 'pull_request' && format('release-pr-{0}', github.ref) || startsWith(github.ref, 'refs/tags/') && format('release-{0}', github.ref) + || (github.event.schedule == '53 1 * * *' || inputs.source_branch == '0.22') && 'release-nightly-0.22' || 'release-nightly' }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} @@ -48,11 +57,13 @@ jobs: dist_tag: ${{ steps.plan.outputs.dist_tag }} commit: ${{ steps.plan.outputs.commit }} previous_tag: ${{ steps.plan.outputs.previous_tag }} + nightly_tag: ${{ steps.plan.outputs.nightly_tag }} steps: - name: Checkout uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2 with: persist-credentials: false + ref: ${{ github.workflow_sha }} - name: Setup Node.js uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 @@ -73,6 +84,7 @@ jobs: timeout-minutes: 120 permissions: contents: read + cache-mode: none env: VERSION: ${{ needs.plan.outputs.version }} steps: @@ -80,6 +92,16 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false + ref: ${{ needs.plan.outputs.commit }} + + - name: Checkout version stamping entrypoint + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + ref: ${{ github.workflow_sha }} + path: .release-tools + sparse-checkout: scripts/release-version.mjs + sparse-checkout-cone-mode: false # No dependency cache: published bytes come from a clean install. - name: Setup toolchain @@ -92,7 +114,7 @@ jobs: uses: ./.github/actions/setup-android-sdk - name: Stamp release version - run: node scripts/release-version.mjs stamp "$VERSION" + run: node .release-tools/scripts/release-version.mjs stamp "$VERSION" - name: Build and verify every public package run: pnpm release:prepare @@ -100,7 +122,7 @@ jobs: - name: Upload packages uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: npm-packages + name: npm-packages-${{ needs.plan.outputs.commit }} path: .tmp/release/*.tgz include-hidden-files: true if-no-files-found: error @@ -122,6 +144,7 @@ jobs: uses: useblacksmith/checkout@2b9fe87d796feea153b455ec2f3125b471a7b0e7 # v1.8.2 with: persist-credentials: false + ref: ${{ github.workflow_sha }} sparse-checkout: scripts/release-publish.mjs sparse-checkout-cone-mode: false @@ -135,7 +158,7 @@ jobs: - name: Download packages uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: - name: npm-packages + name: npm-packages-${{ needs.plan.outputs.commit }} path: ${{ runner.temp }}/npm-packages - name: Publish @@ -156,11 +179,12 @@ jobs: - name: Tag the published commit env: GH_TOKEN: ${{ github.token }} - TAG: nightly/v${{ needs.plan.outputs.version }} + TAG: ${{ needs.plan.outputs.nightly_tag }} + DIST_TAG: ${{ needs.plan.outputs.dist_tag }} COMMIT: ${{ needs.plan.outputs.commit }} run: | gh api "repos/$GITHUB_REPOSITORY/git/refs" -f "ref=refs/tags/$TAG" -f "sha=$COMMIT" - echo "Published $TAG from $COMMIT: npm install agent-device@nightly" >> "$GITHUB_STEP_SUMMARY" + echo "Published $TAG from $COMMIT: npm install agent-device@$DIST_TAG" >> "$GITHUB_STEP_SUMMARY" github-release: name: Draft GitHub release diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d8db42ac0..7597c01efd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,13 +98,18 @@ exception is the empty `0.0.0` placeholder a maintainer publishes by hand to onb described below. A local `npm publish` from the repository root refuses to run. The core and every public workspace package release together at one version. Private packages -stay unpublished. There are three channels: +stay unpublished. The workflow supports these release modes: - **Nightly** (`npm install -g agent-device@nightly`): once a day, at 01:23 UTC, the workflow checks `main`. It publishes `X.Y.Z-nightly..` under the `nightly` dist-tag when `main`'s HEAD has changed since the last nightly and its CI passed, waiting up to 20 minutes for CI that is still running. If that CI fails, is cancelled, or is still running after the wait, no nightly ships that day. A published nightly is tagged `nightly/v`. To publish one now, run **Release** on `main`. +- **0.22 nightly** (`nightly-0.22`): at 01:53 UTC, the workflow on `main` resolves `0.22`'s + HEAD, reads its `0.22.X-dev` version, and requires successful push CI on that exact commit. + It builds that SHA as `0.22.X-nightly-0-22..` and tags it under + `nightly-0.22/v`. Deduplication and concurrency are separate from `main`'s nightly. + To publish manually after activation, run **Release** on `main` with `source_branch: 0.22`. - **Stable** (`latest`): a repository admin publishes a GitHub release with a new `vX.Y.Z` tag targeting `main`. Use the version `main` builds towards (its `X.Y.Z-dev`), or a later one, and write the notes or generate them in the release form. The tag starts a **Release** run. It waits @@ -155,7 +160,8 @@ granting npm trust: unattended. 2. **Tag ruleset** (Settings → Rules → Rulesets → New tag ruleset): active, targeting `refs/tags/v*` with no exclusions, restricting creations, updates, and deletions, with only the - Repository admin role allowed to bypass. Nightly tags live under `nightly/` and stay outside it. + Repository admin role allowed to bypass. Nightly tags live under `nightly/` or `nightly-0.22/` + and stay outside it. 3. **Actions** (Settings → Actions → General): workflow permissions set to read repository contents, and "Allow GitHub Actions to create and approve pull requests" turned off. 4. **Releases** (Settings → General): leave release immutability off, because the run attaches its @@ -186,6 +192,22 @@ release. To plan a minor or major release, commit the new `-dev` version to `mai the repository's tool surface per version string: a released number left on `main` while `main` keeps changing is indistinguishable from a republished ("rug-pull") version. +### Activate the 0.22 nightly channel + +The `nightly-0.22` channel is unavailable until these changes are reviewed and merged and its +first publish succeeds. Merge the `0.22` prerequisite first: enable CI pushes on `0.22`, stamp +`0.22.0-dev` with the existing version script, and include the update notifier's `nightly-0.22` +routing. Require successful push CI at the resulting `0.22` HEAD. Then merge this release +configuration into `main`. Its next 01:53 UTC schedule can publish that source; merging the +configuration activates the schedule. Do not dispatch it before the independent review. + +Keep the existing `release.yml` trusted publisher and `npm-publish` policies (`main` and `v*`). +The planner and publisher use the workflow commit; the build uses the planned source commit. +The version-stamping entrypoint uses the workflow commit and calls the source commit's workspace +and MCP metadata helpers. The publisher verifies each package's name and version before publishing. +Do not grant the `0.22` branch deployment access. Private optional plugins remain unpublished; +this channel does not replace their placeholder, trusted-publisher, or native validation prerequisites. + ### Released-surface baselines roll forward on publish Compatibility gates baseline against the last **released tag**, not against `main`, so publishing is diff --git a/scripts/__tests__/release-plan.test.ts b/scripts/__tests__/release-plan.test.ts index 632e94c526..346952aa4f 100644 --- a/scripts/__tests__/release-plan.test.ts +++ b/scripts/__tests__/release-plan.test.ts @@ -1,4 +1,8 @@ import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { mkdtempForTestSync } from '@agent-device/test-kit'; import { test } from 'vitest'; import { isVersionOnlyCommit, @@ -9,6 +13,7 @@ import { const MAIN = 'a'.repeat(40); const NIGHTLY_COMMIT = 'b'.repeat(40); +const PLANNER_TIME = '2026-10-11T12:00:00.000Z'; function skipReason(plan: ReleasePlan): string { assert.equal(plan.mode, 'skip'); @@ -201,3 +206,351 @@ test('each missing protection is named on its own', () => { }; assert.match(repositorySetupGaps(creatable).join(), /tag ruleset/); }); + +test('the 0.22 source publishes an isolated nightly channel from its own version and SHA', () => { + assert.deepEqual( + planRelease(run({ sourceBranch: '0.22', sha: NIGHTLY_COMMIT, rootVersion: '0.22.0-dev' })), + { + mode: 'nightly', + version: '0.22.0-nightly-0-22.20261011.42', + distTag: 'nightly-0.22', + commit: NIGHTLY_COMMIT, + }, + ); +}); + +for (const latestStable of ['0.22.0', '0.22.1', '0.23.0']) { + test(`0.22 nightlies remain available after stable ${latestStable} ships`, () => { + const source = run({ + sourceBranch: '0.22', + rootVersion: '0.22.0-dev', + latestStable, + }); + for (const event of ['schedule', 'workflow_dispatch']) { + assert.deepEqual(planRelease({ ...source, event }), { + mode: 'nightly', + version: '0.22.0-nightly-0-22.20261011.42', + distTag: 'nightly-0.22', + commit: MAIN, + }); + } + assert.throws( + () => planRelease({ ...source, sourceBranch: 'main' }), + /not ahead of the published/, + ); + }); +} + +test('0.22 deduplication ignores main nightlies and skips only its own published source', () => { + const source = run({ sourceBranch: '0.22', sha: NIGHTLY_COMMIT, rootVersion: '0.22.0-dev' }); + assert.equal(planRelease(source).mode, 'nightly'); + const tags = new Map([ + ...source.tags, + ['nightly-0.22/v0.22.0-nightly-0-22.20261010.41', NIGHTLY_COMMIT], + ]); + assert.match(skipReason(planRelease({ ...source, tags })), /already ships/); + assert.equal(planRelease(run({ tags })).mode, 'nightly'); +}); + +test('0.22 refuses another series, unsupported sources, non-main workflow refs and stable selection', () => { + assert.throws(() => planRelease(run({ sourceBranch: '0.22' })), /0\.22.*version/); + assert.throws(() => planRelease(run({ sourceBranch: 'feature' })), /source/); + assert.throws( + () => planRelease(run({ sourceBranch: '0.22', ref: 'refs/heads/0.22' })), + /main or a vX/, + ); + assert.throws( + () => planRelease(run({ sourceBranch: '0.22', ref: 'refs/tags/v0.22.0' })), + /source/, + ); +}); + +for (const ciConclusion of [ + 'failure', + 'cancelled', + 'missing', + 'queued', + 'in_progress', + 'pending', +]) { + test(`0.22 skips scheduled ${ciConclusion} CI and refuses a manual publish`, () => { + const source = run({ sourceBranch: '0.22', rootVersion: '0.22.0-dev', ciConclusion }); + assert.equal(planRelease(source).mode, 'skip'); + assert.throws(() => planRelease({ ...source, event: 'workflow_dispatch' }), /CI on/); + }); +} + +for (const sourceBranch of ['main', '0.22'] as const) { + test(sourceBranch + ' schedule respects the published npm day without a Git tag', () => { + const rootVersion = sourceBranch === '0.22' ? '0.22.0-dev' : '0.21.25-dev'; + const base = sourceBranch === '0.22' ? '0.22.0' : '0.21.25'; + const suffix = sourceBranch === '0.22' ? 'nightly-0-22' : 'nightly'; + const latestNightly = base + '-' + suffix + '.20261011.41'; + const input = run({ sourceBranch, rootVersion, tags: new Map(), latestNightly }); + assert.equal(planRelease(input).mode, 'skip'); + assert.equal(planRelease({ ...input, event: 'workflow_dispatch' }).mode, 'nightly'); + assert.throws( + () => planRelease({ ...input, event: 'workflow_dispatch', ciConclusion: 'failure' }), + /CI on/, + ); + assert.equal( + planRelease({ ...input, latestNightly: base + '-' + suffix + '.20261010.41' }).mode, + 'nightly', + ); + const other = sourceBranch === '0.22' ? 'nightly' : 'nightly-0-22'; + assert.equal( + planRelease({ ...input, latestNightly: base + '-' + other + '.20261011.41' }).mode, + 'nightly', + ); + }); +} + +function runPlanner( + options: { + schedule?: string; + source?: string; + ref?: string; + ci?: string; + ciSha?: string; + ciEvent?: string; + rootVersion?: string; + tags?: string; + publishedNightly?: string | null; + latestStable?: string; + } = {}, +) { + const root = mkdtempForTestSync('release-plan-'); + const bin = path.join(root, 'bin'); + fs.mkdirSync(bin); + fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ version: '0.21.38-dev' })); + const event = path.join(root, 'event.json'); + fs.writeFileSync( + event, + JSON.stringify( + options.source + ? { inputs: { source_branch: options.source } } + : { schedule: options.schedule ?? '53 1 * * *' }, + ), + ); + const git = path.join(bin, 'git'); + fs.writeFileSync( + git, + '#!/usr/bin/env node\nprocess.stdout.write(process.env.RELEASE_TEST_TAGS);\n', + { mode: 0o755 }, + ); + const responses = { + '/repos/owner/repo/commits/0.22': { sha: NIGHTLY_COMMIT }, + [`/repos/owner/repo/contents/package.json?ref=${NIGHTLY_COMMIT}`]: { + content: Buffer.from( + JSON.stringify({ version: options.rootVersion ?? '0.22.0-dev' }), + ).toString('base64'), + }, + [`/repos/owner/repo/actions/workflows/ci.yml/runs?head_sha=${NIGHTLY_COMMIT}&event=push&branch=0.22&per_page=1`]: + { + workflow_runs: [ + { + head_sha: options.ciSha ?? NIGHTLY_COMMIT, + event: options.ciEvent ?? 'push', + head_branch: '0.22', + status: options.ci === 'pending' ? 'in_progress' : 'completed', + conclusion: options.ci ?? 'success', + }, + ], + }, + [`/repos/owner/repo/actions/workflows/ci.yml/runs?head_sha=${MAIN}&event=push&branch=main&per_page=1`]: + { + workflow_runs: [ + { + head_sha: MAIN, + event: 'push', + head_branch: 'main', + status: 'completed', + conclusion: 'success', + }, + ], + }, + [`/repos/owner/repo/actions/workflows/ci.yml/runs?head_sha=${MAIN}&event=push&per_page=1`]: { + workflow_runs: [ + { + head_sha: MAIN, + event: 'push', + head_branch: 'main', + status: 'completed', + conclusion: 'success', + }, + ], + }, + [`/repos/owner/repo/compare/main...${MAIN}`]: { status: 'identical' }, + '/agent-device/latest': { version: options.latestStable ?? '0.21.37' }, + '/agent-device/nightly': options.publishedNightly + ? { version: options.publishedNightly } + : null, + '/agent-device/nightly-0.22': options.publishedNightly + ? { version: options.publishedNightly } + : null, + '/repos/owner/repo/rulesets?targets=tag': [{ id: 1 }], + '/repos/owner/repo/rulesets/1': protectedRuleset(), + '/repos/owner/repo/environments/npm-publish': protectedSetup().npmPublish, + '/repos/owner/repo/environments/npm-publish/deployment-branch-policies': { + branch_policies: protectedSetup().npmPublishPolicies, + }, + }; + const requests = path.join(root, 'requests.jsonl'); + const mock = path.join(root, 'fetch.mjs'); + fs.writeFileSync( + mock, + `import fs from 'node:fs'; +const NativeDate = Date; +const now = NativeDate.parse(${JSON.stringify(PLANNER_TIME)}); +globalThis.Date = class extends NativeDate { + constructor(...args) { super(...(args.length ? args : [now])); } + static now() { return now; } +}; +const responses = ${JSON.stringify(responses)}; +globalThis.fetch = async (url) => { + const parsed = new URL(url); + const key = parsed.pathname + parsed.search; + fs.appendFileSync(${JSON.stringify(requests)}, JSON.stringify(key) + '\\n'); + if (!(key in responses)) throw new Error('Unexpected request ' + key); + return { ok: responses[key] !== null, status: responses[key] === null ? 404 : 200, json: async () => responses[key] }; +}; +globalThis.setTimeout = (callback) => { callback(); return 0; }; +`, + ); + const output = path.join(root, 'output'); + const result = spawnSync( + process.execPath, + ['--import', mock, path.resolve(import.meta.dirname, '../release-plan.mjs')], + { + cwd: root, + encoding: 'utf8', + env: { + ...process.env, + PATH: `${bin}${path.delimiter}${process.env.PATH}`, + RELEASE_TEST_TAGS: options.tags ?? '', + GITHUB_EVENT_NAME: options.source ? 'workflow_dispatch' : 'schedule', + GITHUB_REF: options.ref ?? 'refs/heads/main', + GITHUB_SHA: MAIN, + GITHUB_EVENT_PATH: event, + GITHUB_RUN_NUMBER: '42', + GITHUB_API_URL: 'https://api.github.test', + GITHUB_REPOSITORY: 'owner/repo', + GITHUB_TOKEN: 'fixture', + GITHUB_OUTPUT: output, + GITHUB_STEP_SUMMARY: path.join(root, 'summary'), + }, + }, + ); + return { + ...result, + output: fs.existsSync(output) ? fs.readFileSync(output, 'utf8') : '', + requests: fs.existsSync(requests) + ? fs + .readFileSync(requests, 'utf8') + .trim() + .split('\n') + .map((line) => JSON.parse(line)) + : [], + }; +} + +test('the scheduled planner resolves 0.22 once and reads its manifest and push CI by that exact SHA', () => { + const result = runPlanner(); + assert.equal(result.status, 0, result.stderr); + assert.match(result.output, /dist_tag=nightly-0\.22/); + assert.match(result.output, new RegExp(`commit=${NIGHTLY_COMMIT}`)); + assert.match(result.output, /version=0\.22\.0-nightly-0-22\./); + assert.match(result.output, /nightly_tag=nightly-0\.22\/v0\.22\.0-nightly-0-22/); + assert.equal( + result.requests.filter((request) => request === '/repos/owner/repo/commits/0.22').length, + 1, + ); + assert.ok( + result.requests.includes(`/repos/owner/repo/contents/package.json?ref=${NIGHTLY_COMMIT}`), + ); + assert.ok( + result.requests.includes( + `/repos/owner/repo/actions/workflows/ci.yml/runs?head_sha=${NIGHTLY_COMMIT}&event=push&branch=0.22&per_page=1`, + ), + ); +}); + +for (const options of [ + { ci: 'failure' }, + { ci: 'cancelled' }, + { ci: 'pending' }, + { ciSha: MAIN }, + { ciEvent: 'pull_request' }, +]) { + test(`the 0.22 entrypoint fails closed for CI ${JSON.stringify(options)}`, () => { + const result = runPlanner(options); + assert.equal(result.status, 0, result.stderr); + assert.match(result.output, /mode=skip/); + assert.doesNotMatch(result.output, /dist_tag=nightly-0/); + assert.ok( + !result.requests.some( + (request) => request.includes('/commits/') && !request.endsWith('/0.22'), + ), + '0.22 never substitutes parent CI', + ); + }); +} + +test('manual fixed-source selection works; unsupported sources, refs and schedules fail before API calls', () => { + const manual = runPlanner({ source: '0.22' }); + assert.equal(manual.status, 0, manual.stderr); + assert.match(manual.output, /dist_tag=nightly-0\.22/); + for (const options of [ + { source: 'feature' }, + { source: '0.22', ref: 'refs/heads/0.22' }, + { source: '0.22', ref: 'refs/tags/v0.22.0' }, + { schedule: '0 0 * * *' }, + ]) { + const result = runPlanner(options); + assert.notEqual(result.status, 0); + assert.deepEqual(result.requests, []); + } +}); + +test('the original main schedule, manual nightly and stable retry keep their channels and source', () => { + for (const options of [ + { schedule: '23 1 * * *' }, + { source: 'main' }, + { source: 'main', ref: 'refs/tags/v0.21.38' }, + ]) { + const result = runPlanner(options); + assert.equal(result.status, 0, result.stderr); + assert.match(result.output, new RegExp(`commit=${MAIN}`)); + assert.match(result.output, options.ref ? /dist_tag=latest/ : /dist_tag=nightly\n/); + assert.ok(!result.requests.includes('/repos/owner/repo/commits/0.22')); + } +}); + +for (const source of ['main', '0.22'] as const) { + test( + source + ' scheduled entrypoint deduplicates from its npm channel before any publish', + () => { + const today = PLANNER_TIME.slice(0, 10).replaceAll('-', ''); + const version = source === '0.22' ? '0.22.0-nightly-0-22.' : '0.21.38-nightly.'; + const result = runPlanner({ + schedule: source === '0.22' ? '53 1 * * *' : '23 1 * * *', + publishedNightly: version + today + '.41', + latestStable: source === '0.22' ? '0.23.0' : '0.21.37', + }); + assert.equal(result.status, 0, result.stderr); + assert.match(result.output, /mode=skip/); + assert.doesNotMatch(result.output, /dist_tag=nightly/); + assert.ok( + result.requests.includes( + '/agent-device/' + (source === '0.22' ? 'nightly-0.22' : 'nightly'), + ), + ); + if (source === '0.22') assert.ok(!result.requests.includes('/agent-device/latest')); + const manual = runPlanner({ source, publishedNightly: version + today + '.41' }); + assert.equal(manual.status, 0, manual.stderr); + assert.match(manual.output, /mode=nightly/); + assert.ok(!manual.requests.includes('/agent-device/nightly')); + assert.ok(!manual.requests.includes('/agent-device/nightly-0.22')); + }, + ); +} diff --git a/scripts/__tests__/release-version.test.ts b/scripts/__tests__/release-version.test.ts index dbc909b450..fad9ce187b 100644 --- a/scripts/__tests__/release-version.test.ts +++ b/scripts/__tests__/release-version.test.ts @@ -57,3 +57,28 @@ test('release versions compare numerically per segment', () => { assert.throws(() => compareReleaseVersions('0.21.25-dev', '0.21.25'), /release version/); assert.throws(() => compareReleaseVersions('01.2.3', '0.21.25'), /release version/); }); + +test('0.22 versions cannot collide with main versions at the same base, date and run', () => { + const version = nightlyVersion('0.22.0-dev', '20261114', 42, '0.22'); + assert.equal(version, '0.22.0-nightly-0-22.20261114.42'); + assert.notEqual(version, nightlyVersion('0.22.0-dev', '20261114', 42)); + assert.equal(nightlyBase(version), '0.22.0'); + const tags = ['nightly/v0.22.0-nightly.20261114.43', `nightly-0.22/v${version}`]; + assert.equal(latestNightlyTag(tags, '0.22'), `nightly-0.22/v${version}`); + assert.equal(latestNightlyTag(tags), tags[0]); +}); + +for (const sourceBranch of ['main', '0.22'] as const) { + test( + sourceBranch + ' tag selection rejects the other channel version shape in its namespace', + () => { + const prefix = sourceBranch === '0.22' ? 'nightly-0.22/v' : 'nightly/v'; + const suffix = sourceBranch === '0.22' ? 'nightly-0-22' : 'nightly'; + const other = sourceBranch === '0.22' ? 'nightly' : 'nightly-0-22'; + const own = prefix + '0.22.0-' + suffix + '.20261113.1'; + const wrong = prefix + '0.23.0-' + other + '.20261114.2'; + assert.equal(latestNightlyTag([own, wrong], sourceBranch), own); + assert.equal(latestNightlyTag([wrong], sourceBranch), null); + }, + ); +} diff --git a/scripts/release-plan.d.mts b/scripts/release-plan.d.mts index a3e70cf28f..d91564b81f 100644 --- a/scripts/release-plan.d.mts +++ b/scripts/release-plan.d.mts @@ -4,19 +4,21 @@ export type ReleaseRun = Readonly<{ event: string; ref: string; sha: string; + sourceBranch?: 'main' | '0.22'; rootVersion: string; today: string; runNumber: string | number; /** Remote tag names, each resolved to the commit it points at. */ tags: ReadonlyMap; latestStable?: string | null; + latestNightly?: string | null; ciConclusion: string; onMain?: boolean; }>; export type ReleasePlan = | { mode: 'dry-run'; version: string } - | { mode: 'nightly'; version: string; distTag: 'nightly'; commit: string } + | { mode: 'nightly'; version: string; distTag: 'nightly' | 'nightly-0.22'; commit: string } | { mode: 'stable'; version: string; distTag: 'latest'; commit: string; previousTag: string } | { mode: 'skip'; reason: string }; diff --git a/scripts/release-plan.mjs b/scripts/release-plan.mjs index b95f678745..3d18c0d8b3 100644 --- a/scripts/release-plan.mjs +++ b/scripts/release-plan.mjs @@ -6,6 +6,7 @@ import { isReleaseVersion, latestNightlyTag, nightlyBase, + nightlyDate, nightlyVersion, previousReleaseTag, } from './release-version.mjs'; @@ -13,7 +14,7 @@ import { /** * Decides what one `.github/workflows/release.yml` run does, from the event that started it: * pull_request dry-run: build and verify every package, publish nothing - * schedule / dispatch nightly: publish main's HEAD under the `nightly` dist-tag + * schedule / dispatch nightly: publish the fixed source branch under its own dist-tag * vX.Y.Z tag stable: publish that commit under the `latest` dist-tag * `tags` maps remote tag names to commits; `ciConclusion` and `onMain` describe `sha`. */ @@ -21,16 +22,38 @@ export function planRelease(run) { if (run.event === 'pull_request') { return { mode: 'dry-run', version: nightlyVersion(run.rootVersion, run.today, run.runNumber) }; } + const sourceBranch = run.sourceBranch ?? 'main'; + if ( + !['main', '0.22'].includes(sourceBranch) || + (run.ref.startsWith('refs/tags/') && sourceBranch !== 'main') + ) { + throw new Error(`Unsupported release source ${sourceBranch} for ${run.ref}.`); + } if (run.ref.startsWith('refs/tags/')) return planStable(run, run.ref.slice('refs/tags/'.length)); if (run.ref !== 'refs/heads/main') { throw new Error(`Releases run from main or a vX.Y.Z tag, not ${run.ref}.`); } - return planNightly(run); + if (!['schedule', 'workflow_dispatch'].includes(run.event)) { + throw new Error(`Unsupported nightly event ${run.event}.`); + } + return planNightly(run, sourceBranch); } -function planNightly(run) { +function nightlyDistTag(sourceBranch) { + return sourceBranch === '0.22' ? 'nightly-0.22' : 'nightly'; +} + +function planNightly(run, sourceBranch) { const scheduled = run.event === 'schedule'; - const latest = latestNightlyTag([...run.tags.keys()]); + const distTag = nightlyDistTag(sourceBranch); + if ( + scheduled && + run.latestNightly && + nightlyDate(run.latestNightly, sourceBranch) === run.today + ) { + return skip(distTag + ' already published on ' + run.today + '.'); + } + const latest = latestNightlyTag([...run.tags.keys()], sourceBranch); if (scheduled && latest && run.tags.get(latest) === run.sha) { return skip(`${latest} already ships ${run.sha}.`); } @@ -39,9 +62,17 @@ function planNightly(run) { if (scheduled) return skip(reason); throw new Error(reason); } - const version = nightlyVersion(run.rootVersion, run.today, run.runNumber); - assertAheadOfStable(run, nightlyBase(version)); - return { mode: 'nightly', version, distTag: 'nightly', commit: run.sha }; + if (sourceBranch === '0.22' && !/^0\.22\.(0|[1-9]\d*)-dev$/.test(run.rootVersion)) { + throw new Error(`0.22 must carry a 0.22.X-dev version, got ${run.rootVersion}.`); + } + const version = nightlyVersion(run.rootVersion, run.today, run.runNumber, sourceBranch); + if (sourceBranch === 'main') assertAheadOfStable(run, nightlyBase(version)); + return { + mode: 'nightly', + version, + distTag, + commit: run.sha, + }; } function planStable(run, tag) { @@ -138,7 +169,7 @@ const REPOSITORY_ADMIN_ROLE = 5; function assertAheadOfStable(run, version) { if (run.latestStable && compareReleaseVersions(version, run.latestStable) <= 0) { throw new Error( - `${version} is not ahead of the published ${run.latestStable}. Move main's -dev version past it.`, + `${version} is not ahead of the published ${run.latestStable}. Move ${run.sourceBranch ?? 'main'}'s -dev version past it.`, ); } } @@ -146,9 +177,13 @@ function assertAheadOfStable(run, version) { /** Remote release and nightly tags by name, resolved to the commit each one points at. */ function remoteTags() { const tags = new Map(); - const output = execFileSync('git', ['ls-remote', '--tags', 'origin', 'v*', 'nightly/*'], { - encoding: 'utf8', - }); + const output = execFileSync( + 'git', + ['ls-remote', '--tags', 'origin', 'v*', 'nightly/*', 'nightly-0.22/*'], + { + encoding: 'utf8', + }, + ); for (const line of output.split('\n').filter(Boolean)) { const [commit, name] = line.split('\t'); const tag = name.replace(/^refs\/tags\//, ''); @@ -158,14 +193,23 @@ function remoteTags() { return tags; } -async function ciConclusion(env, sha) { +async function ciConclusion(env, sha, sourceBranch) { const { workflow_runs: runs } = await github( env, - `actions/workflows/ci.yml/runs?head_sha=${sha}&event=push&per_page=1`, + `actions/workflows/ci.yml/runs?head_sha=${sha}&event=push${sourceBranch ? `&branch=${sourceBranch}` : ''}&per_page=1`, + ); + const run = runs.find( + (run) => + run.head_sha === sha && + run.event === 'push' && + (!sourceBranch || run.head_branch === sourceBranch), ); - if (runs.length > 0) return runs[0].status === 'completed' ? runs[0].conclusion : runs[0].status; + if (run) return run.status === 'completed' ? run.conclusion : run.status; + if (sourceBranch === '0.22') return 'missing'; const commit = await github(env, `commits/${sha}`); - return isVersionOnlyCommit(commit) ? ciConclusion(env, commit.parents[0].sha) : 'missing'; + return isVersionOnlyCommit(commit) + ? ciConclusion(env, commit.parents[0].sha, sourceBranch) + : 'missing'; } // `missing` included: a tag pushed right after a merge can arrive before the merge's CI run exists. @@ -179,9 +223,9 @@ const UNSETTLED_CI = new Set([ ]); /** A commit pushed moments ago waits, within the Plan job's budget, for its CI to finish. */ -async function settledCiConclusion(env, sha) { +async function settledCiConclusion(env, sha, sourceBranch) { for (let attempt = 0; ; attempt += 1) { - const conclusion = await ciConclusion(env, sha); + const conclusion = await ciConclusion(env, sha, sourceBranch); if (!UNSETTLED_CI.has(conclusion) || attempt >= 40) { return conclusion; } @@ -237,21 +281,64 @@ async function readRepositorySetup(env) { }; } +function sourceBranchForRun(event, ref, payload) { + if (event === 'pull_request') return 'main'; + const sourceBranch = + event === 'schedule' + ? { '23 1 * * *': 'main', '53 1 * * *': '0.22' }[payload.schedule] + : (payload.inputs?.source_branch ?? 'main'); + if (!['main', '0.22'].includes(sourceBranch)) { + throw new Error(`Unsupported release source ${sourceBranch}.`); + } + if (ref !== 'refs/heads/main' && (!ref.startsWith('refs/tags/') || sourceBranch !== 'main')) { + throw new Error(`Releases run from main or a vX.Y.Z tag, not ${ref}.`); + } + return sourceBranch; +} + +async function readPublishedVersions(event, sourceBranch, onBranch, onTag) { + return { + latestStable: + onTag || (onBranch && sourceBranch === 'main') ? await publishedVersion('latest') : null, + latestNightly: + event === 'schedule' && onBranch + ? await publishedVersion(nightlyDistTag(sourceBranch)) + : null, + }; +} + async function readRun(env) { const event = env.GITHUB_EVENT_NAME; const ref = env.GITHUB_REF; + const payload = JSON.parse(fs.readFileSync(env.GITHUB_EVENT_PATH, 'utf8')); + const sourceBranch = sourceBranchForRun(event, ref, payload); const onBranch = event !== 'pull_request' && ref === 'refs/heads/main'; const onTag = ref.startsWith('refs/tags/'); + const sha = + onBranch && sourceBranch === '0.22' ? (await github(env, 'commits/0.22')).sha : env.GITHUB_SHA; + const rootVersion = + sourceBranch === '0.22' && onBranch + ? JSON.parse( + Buffer.from( + (await github(env, `contents/package.json?ref=${sha}`)).content, + 'base64', + ).toString('utf8'), + ).version + : JSON.parse(fs.readFileSync('package.json', 'utf8')).version; return { event, ref, - sha: env.GITHUB_SHA, - rootVersion: JSON.parse(fs.readFileSync('package.json', 'utf8')).version, + sha, + sourceBranch, + rootVersion, today: new Date().toISOString().slice(0, 10).replaceAll('-', ''), runNumber: env.GITHUB_RUN_NUMBER, tags: event === 'pull_request' ? new Map() : remoteTags(), - latestStable: onBranch || onTag ? await publishedVersion('latest') : null, - ciConclusion: onBranch || onTag ? await settledCiConclusion(env, env.GITHUB_SHA) : undefined, + ...(await readPublishedVersions(event, sourceBranch, onBranch, onTag)), + ciConclusion: + onBranch || onTag + ? await settledCiConclusion(env, sha, onBranch ? sourceBranch : undefined) + : undefined, onMain: onTag ? await isOnMain(env) : undefined, }; } @@ -261,6 +348,7 @@ const OUTPUTS = { version: 'version', dist_tag: 'distTag', commit: 'commit', + nightly_tag: 'nightlyTag', previous_tag: 'previousTag', }; @@ -274,6 +362,8 @@ async function main(env) { ); } } + if (result.mode === 'dry-run') result.commit = env.GITHUB_SHA; + if (result.mode === 'nightly') result.nightlyTag = `${result.distTag}/v${result.version}`; const lines = Object.entries(OUTPUTS).map(([output, key]) => `${output}=${result[key] ?? ''}\n`); fs.appendFileSync(env.GITHUB_OUTPUT, lines.join('')); const summary = result.reason ?? `${result.mode} ${result.version}`; diff --git a/scripts/release-version.d.mts b/scripts/release-version.d.mts index fbfd94f3ab..986c0558f7 100644 --- a/scripts/release-version.d.mts +++ b/scripts/release-version.d.mts @@ -8,11 +8,17 @@ export function nightlyVersion( developmentVersion: string, date: string, runNumber: string | number, + sourceBranch?: 'main' | '0.22', ): string; export function nightlyBase(version: string): string; -export function latestNightlyTag(tags: readonly string[]): string | null; +export function nightlyDate(version: string, sourceBranch?: 'main' | '0.22'): string | null; + +export function latestNightlyTag( + tags: readonly string[], + sourceBranch?: 'main' | '0.22', +): string | null; export function previousReleaseTag(tags: readonly string[], version: string): string | null; diff --git a/scripts/release-version.mjs b/scripts/release-version.mjs index 128449eb4f..95df08f58e 100644 --- a/scripts/release-version.mjs +++ b/scripts/release-version.mjs @@ -10,7 +10,7 @@ import { pathToFileURL } from 'node:url'; const N = String.raw`(0|[1-9]\d*)`; const RELEASE = new RegExp(`^${N}\\.${N}\\.${N}$`); const DEVELOPMENT = new RegExp(`^${N}\\.${N}\\.${N}-dev$`); -const NIGHTLY = new RegExp(`^${N}\\.${N}\\.${N}-nightly\\.(\\d{8})\\.([1-9]\\d*)$`); +const NIGHTLY = new RegExp(`^${N}\\.${N}\\.${N}-nightly(?:-0-22)?\\.(\\d{8})\\.([1-9]\\d*)$`); const ASSET_TAG = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?![\s\S])/; @@ -29,14 +29,16 @@ export function compareReleaseVersions(left, right) { return a[0] - b[0] || a[1] - b[1] || a[2] - b[2]; } -export function nightlyVersion(developmentVersion, date, runNumber) { +export function nightlyVersion(developmentVersion, date, runNumber, sourceBranch = 'main') { const match = DEVELOPMENT.exec(developmentVersion); - if (!match) throw new Error(`main must carry an X.Y.Z-dev version, got ${developmentVersion}.`); + if (!match) + throw new Error(`${sourceBranch} must carry an X.Y.Z-dev version, got ${developmentVersion}.`); if (!/^\d{8}$/.test(date)) throw new Error(`Nightly date must be YYYYMMDD, got ${date}.`); if (!/^[1-9]\d*$/.test(String(runNumber))) { throw new Error(`Nightly run number must be a positive integer, got ${runNumber}.`); } - return `${match.slice(1, 4).join('.')}-nightly.${date}.${runNumber}`; + const suffix = sourceBranch === '0.22' ? 'nightly-0-22' : 'nightly'; + return `${match.slice(1, 4).join('.')}-${suffix}.${date}.${runNumber}`; } /** The `X.Y.Z` release a nightly previews. */ @@ -46,17 +48,26 @@ export function nightlyBase(version) { return match.slice(1, 4).join('.'); } +function matchNightlyVersion(version, sourceBranch) { + const match = NIGHTLY.exec(version); + const suffix = sourceBranch === '0.22' ? '-nightly-0-22.' : '-nightly.'; + return match && version.includes(suffix) ? match : null; +} + +export function nightlyDate(version, sourceBranch = 'main') { + return matchNightlyVersion(version, sourceBranch)?.[4] ?? null; +} + /** * Nightly tags live outside `v*`, which only repository admins may create: the release workflow * tags each nightly itself, and no nightly tag ref may deploy to the npm-publish environment. + * The newest tag in each source namespace is ordered by base, then date, then run. */ -const NIGHTLY_TAG_PREFIX = 'nightly/v'; - -/** The newest `nightly/vX.Y.Z-nightly..` tag, ordered by base, then date, then run. */ -export function latestNightlyTag(tags) { +export function latestNightlyTag(tags, sourceBranch = 'main') { + const prefix = sourceBranch === '0.22' ? 'nightly-0.22/v' : 'nightly/v'; const nightlies = tags - .filter((tag) => tag.startsWith(NIGHTLY_TAG_PREFIX)) - .map((tag) => ({ tag, match: NIGHTLY.exec(tag.slice(NIGHTLY_TAG_PREFIX.length)) })) + .filter((tag) => tag.startsWith(prefix)) + .map((tag) => ({ tag, match: matchNightlyVersion(tag.slice(prefix.length), sourceBranch) })) .filter((entry) => entry.match); nightlies.sort((a, b) => { const [left, right] = [a.match, b.match].map((match) => match.slice(1).map(Number)); diff --git a/src/cli/__tests__/update-check.test.ts b/src/cli/__tests__/update-check.test.ts index 03e517e44c..155fc27e30 100644 --- a/src/cli/__tests__/update-check.test.ts +++ b/src/cli/__tests__/update-check.test.ts @@ -252,3 +252,37 @@ test('a failed check after a channel switch records the new channel and drops th assert.equal(cache.latestVersion, undefined); assert.equal(cache.checkedAt, '2026-03-31T10:00:00.000Z'); }); + +test('a 0.22 nightly follows its own dist-tag and ignores cached main-nightly updates', async () => { + const stateDir = makeTempStateDir(); + cleanupPaths.push(stateDir); + const currentVersion = '0.22.0-nightly-0-22.20261113.7'; + writeCache(stateDir, { latestVersion: '0.23.0-nightly.20261114.8', distTag: 'nightly' }); + assert.equal( + withCapturedStderr( + () => maybeRunUpgradeNotifier({ command: 'devices', currentVersion, stateDir, flags: {} }), + { interactive: true }, + ), + '', + ); + const fetchMock = vi.fn().mockResolvedValue({ + ok: true, + json: async () => ({ version: '0.22.0-nightly-0-22.20261114.8' }), + }); + vi.stubGlobal('fetch', fetchMock); + await runUpdateCheckWorker({ + cachePath: path.join(stateDir, 'update-check.json'), + currentVersion, + }); + assert.equal( + fetchMock.mock.calls[0]?.[0], + 'https://registry.npmjs.org/agent-device/nightly-0.22', + ); + assert.match( + withCapturedStderr( + () => maybeRunUpgradeNotifier({ command: 'devices', currentVersion, stateDir, flags: {} }), + { interactive: true }, + ), + /npm install -g agent-device@nightly-0\.22/, + ); +}); diff --git a/src/cli/update-check.ts b/src/cli/update-check.ts index 916d2f84f4..5a82fc535e 100644 --- a/src/cli/update-check.ts +++ b/src/cli/update-check.ts @@ -169,8 +169,9 @@ function cachedDistTag(cache: UpdateCheckCache): string { return cache.distTag ?? 'latest'; } -/** A nightly build follows the `nightly` dist-tag; every other build follows `latest`. */ -function distTagFor(version: string): 'latest' | 'nightly' { +/** Each nightly follows its source channel; other builds follow `latest`. */ +function distTagFor(version: string): 'latest' | 'nightly' | 'nightly-0.22' { + if (version.includes('-nightly-0-22.')) return 'nightly-0.22'; return version.includes('-nightly.') ? 'nightly' : 'latest'; } diff --git a/test/ci/release-workflow.test.ts b/test/ci/release-workflow.test.ts index 7f4fb51541..d50b1f55b1 100644 --- a/test/ci/release-workflow.test.ts +++ b/test/ci/release-workflow.test.ts @@ -7,12 +7,18 @@ const repoRoot = path.resolve(import.meta.dirname, '../..'); const source = fs.readFileSync(path.join(repoRoot, '.github/workflows/release.yml'), 'utf8'); type Job = { + 'cache-mode'?: string; environment?: string; permissions?: Record; steps?: Array<{ uses?: string; with?: Record }>; uses?: string; }; -const workflow = parse(source) as { permissions: unknown; jobs: Record }; +const workflow = parse(source) as { + permissions: unknown; + jobs: Record; + on: { schedule: Array<{ cron: string }> }; + concurrency: { group: string }; +}; // npm trusts release.yml in the npm-publish environment, so whichever job can mint an id-token // can publish. Only the publisher and the MCP Registry call (its own OIDC login) may. @@ -46,9 +52,42 @@ test('the publisher authenticates through OIDC alone', () => { expect(setupNode?.with).not.toHaveProperty('registry-url'); }); -test('the published bytes are built without a restored dependency cache', () => { +test('the release build has no cache token access and restores no dependency cache', () => { + expect(workflow.jobs.build?.['cache-mode']).toBe('none'); const setup = workflow.jobs.build?.steps?.find( (step) => step.uses === './.github/actions/setup-node-pnpm', ); expect(setup?.with?.['cache-store']).toBe('false'); }); + +test('the source checkout and artifact identity use the planned commit while the publisher stays trusted', () => { + const build = workflow.jobs.build?.steps ?? []; + const checkout = build.find((step) => step.uses?.startsWith('actions/checkout@')); + expect(checkout?.with?.ref).toBe('${{ needs.plan.outputs.commit }}'); + const upload = build.find((step) => step.uses?.startsWith('actions/upload-artifact@')); + expect(upload?.with?.name).toBe('npm-packages-${{ needs.plan.outputs.commit }}'); + const publisher = workflow.jobs.publish?.steps ?? []; + expect( + publisher.find((step) => step.uses?.startsWith('useblacksmith/checkout@'))?.with?.ref, + ).toBe('${{ github.workflow_sha }}'); + expect( + publisher.find((step) => step.uses?.startsWith('actions/download-artifact@'))?.with?.name, + ).toBe(upload?.with?.name); +}); + +test('the version stamping entrypoint is pinned to the workflow commit', () => { + const entrypoint = workflow.jobs.build?.steps?.find( + (step) => step.with?.path === '.release-tools', + ); + expect(entrypoint?.with?.ref).toBe('${{ github.workflow_sha }}'); +}); + +test('both nightly schedules keep separate concurrency groups for cron and manual selection', () => { + expect(workflow.on.schedule.map((entry) => entry.cron)).toEqual( + expect.arrayContaining(['23 1 * * *', '53 1 * * *']), + ); + expect(workflow.concurrency.group).toContain( + "(github.event.schedule == '53 1 * * *' || inputs.source_branch == '0.22') && 'release-nightly-0.22'", + ); + expect(workflow.concurrency.group).toContain("|| 'release-nightly'"); +}); diff --git a/website/docs/docs/installation.md b/website/docs/docs/installation.md index bd9afb69dc..7840eaabd7 100644 --- a/website/docs/docs/installation.md +++ b/website/docs/docs/installation.md @@ -61,7 +61,11 @@ Nightly builds publish `main` after its CI passes, at most once per UTC day: npm install -g agent-device@nightly ``` -A nightly install's update notice recommends a newer nightly when an update check finds one. To +The `0.22` preview channel requires a separate activation and first successful publish. Once +available, install it with `npm install -g agent-device@nightly-0.22`. If npm reports that the tag +is missing, that channel has not published yet; use `@nightly` for `main` or `@latest` for stable. + +A nightly install's update notice follows the channel you installed, including `nightly-0.22`. To return to stable releases, install `agent-device@latest`. ## Without installing