Freeze release notes with test and stable candidates (#464)

Prepare read-only change drafts during candidate builds and seal their identity and hashes. Reuse frozen notes during publication while preserving legacy candidates and retries. Disclose truncated comparison history, deduplicate repeated pages, and keep acceptance status explicit. This merge does not dispatch a candidate build or publish a package.
This commit is contained in:
open-design-crew[bot]
2026-11-16 19:23:42 +08:00
committed by GitHub
parent df95932999
commit 36fcbc5a49
9 changed files with 274 additions and 50 deletions

View File

@@ -2,9 +2,93 @@ import assert from 'node:assert/strict';
import { readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { releaseInputs, verifyDownloaded, repository } from './motion-release.mjs';
import { releaseInputs, verifyDownloaded, repository, releaseChannel, candidateNoteIdentity } from './motion-release.mjs';
import { sha256 } from '../../scripts/runtime-assets.mjs';
import { compareReleaseVersions } from '../../scripts/release-version.mjs';
function githubApi(env, fetcher) {
return async (route, method = 'GET', data, allowMissing = false) => {
const response = await fetcher(`https://api.github.com/repos/${repository}${route}`, {
method, redirect: 'error', signal: AbortSignal.timeout(30_000),
headers: { Accept: 'application/vnd.github+json', ...(env.GH_TOKEN ? { Authorization: `Bearer ${env.GH_TOKEN}` } : {}), 'X-GitHub-Api-Version': '2022-11-28', 'Content-Type': 'application/json' },
...(data === undefined ? {} : { body: JSON.stringify(data) }),
});
if (allowMissing && response.status === 404) return null;
assert(response.ok, `GitHub release ${method} ${route} failed: HTTP ${response.status}`);
return response.json();
};
}
async function listReleases(api) {
const releases = [];
for (let page = 1; ; page++) {
assert(page <= 100, 'GitHub release history exceeds the bounded lookup');
const batch = await api(`/releases?per_page=100&page=${page}`);
assert(Array.isArray(batch), 'Invalid GitHub release list');
releases.push(...batch);
if (batch.length < 100) break;
}
return releases;
}
function previousRelease(releases, version, prerelease) {
return releases.filter(r => !r.draft && r.prerelease === prerelease && /^v\d+\.\d+\.\d+(?:-test\.[1-9]\d*(?:\.[1-9]\d*)*)?$/.test(r.tag_name))
.filter(r => compareReleaseVersions(r.tag_name.slice(1), version) < 0)
.sort((a, b) => compareReleaseVersions(b.tag_name.slice(1), a.tag_name.slice(1)))[0];
}
export async function prepareCandidateNotes(directory, { env = process.env, fetcher = fetch } = {}) {
const manifest = JSON.parse(await readFile(path.join(directory, 'release-npm.json'), 'utf8'));
const channel = releaseChannel(manifest.version), source = manifest.commit;
assert.equal(manifest.version, env.MOTION_VERSION); assert.equal(source, env.MOTION_SOURCE_SHA);
assert.match(source, /^[a-f0-9]{40}$/);
assert.equal(manifest.installer.url, `./openmotion-app-${manifest.version}.tgz`);
assert.equal(await sha256(path.join(directory, manifest.installer.url)), manifest.installer.sha256);
const api = githubApi(env, fetcher), previous = previousRelease(await listReleases(api), manifest.version, channel === 'test');
let base, commits, link, warning = '';
if (previous) {
let object = (await api(`/git/ref/tags/${previous.tag_name}`)).object;
for (let depth = 0; object.type === 'tag' && depth < 5; depth++) object = (await api(`/git/tags/${object.sha}`)).object;
assert.equal(object.type, 'commit'); assert.match(object.sha, /^[a-f0-9]{40}$/); base = object.sha;
link = `https://github.com/${repository}/compare/${base}...${source}`;
commits = [];
const seen = new Set();
let total = 0, truncated = false;
for (let page = 1; page <= 10; page++) {
const compared = await api(`/compare/${base}...${source}?per_page=100&page=${page}`);
assert(['ahead', 'identical'].includes(compared.status), 'Published baseline must be an ancestor of the selected source');
assert(Array.isArray(compared.commits) && Number.isSafeInteger(compared.total_commits) && compared.total_commits >= 0, 'Invalid comparison metadata');
total = compared.total_commits;
const fresh = compared.commits.filter(commit => {
if (seen.has(commit.sha)) return false;
seen.add(commit.sha); return true;
});
commits.push(...fresh);
if (commits.length >= total) break;
// A short or repeated page is incomplete evidence, not a candidate-build failure.
truncated = compared.commits.length < 100 || fresh.length !== compared.commits.length || page === 10;
if (truncated) break;
}
if (truncated) warning = `Only the first ${commits.length.toLocaleString('en-US')} of ${total.toLocaleString('en-US')} compared commits are shown; inspect the full comparison.`;
} else {
// First-channel history is bounded; use the full-history link for older changes.
commits = await api(`/commits?sha=${source}&per_page=100`);
link = `https://github.com/${repository}/commits/${source}`;
warning = 'No earlier GitHub Release exists in this channel. Showing up to 100 recent commits; this is not a complete release delta.';
}
assert(Array.isArray(commits));
const escape = text => text.replace(/[\\`*_[\]<>]/g, '\\$&');
const rows = commits.map(commit => {
assert.match(commit.sha, /^[a-f0-9]{40}$/); assert.equal(typeof commit.commit?.message, 'string');
const title = escape(commit.commit.message.split(/\r?\n/, 1)[0]);
return `- ${title} ([${commit.sha.slice(0, 7)}](https://github.com/${repository}/commit/${commit.sha}))`;
});
const body = `# OpenMotion ${manifest.version}\n\nChannel: ${channel}; templates: ${manifest.templateEnvironment}.\nSource: [${source}](https://github.com/${repository}/commit/${source}).\nBaseline: ${previous ? `${previous.tag_name} (${base})` : 'not available'}.\n\n## Changes\n\n${warning ? warning + '\n\n' : ''}${rows.join('\n') || (previous && !warning ? 'No source commits since the baseline.' : 'No complete commit list is available; inspect the full history/comparison.')}\n\n[Full source comparison/history](${link})\n\n## Acceptance focus\n\nNOT PROVIDED — maintainers record the required checks and actual results in their private acceptance.md copy. No acceptance is implied.\n\n## Known issues\n\nNOT PROVIDED — review before distribution; this does not mean there are no known issues. Maintainers may edit the published GitHub Release prose.\n\n${candidateNoteIdentity({ version: manifest.version, sourceCommit: source, tgzSHA256: manifest.installer.sha256 })}\n`;
assert(Buffer.byteLength(body) <= 1024 * 1024, 'Candidate notes exceed 1 MiB');
await writeFile(path.join(directory, 'release-notes.md'), body, { flag: 'wx' });
return body;
}
export async function publishReleaseNotes(directory, { env = process.env, fetcher = fetch } = {}) {
const inputs = releaseInputs(env);
assert.notEqual(inputs.action, 'archive-only', 'Snapshot recovery must not create GitHub releases');
@@ -15,16 +99,7 @@ export async function publishReleaseNotes(directory, { env = process.env, fetche
assert(env.GH_TOKEN, 'Missing scoped GitHub release token');
const origin = new URL(env.MOTION_INSTALL_PUBLIC_ORIGIN);
assert(origin.protocol === 'https:' && origin.pathname === '/' && !origin.username && !origin.password && !origin.search && !origin.hash);
const api = async (route, method = 'GET', data, allowMissing = false) => {
const response = await fetcher(`https://api.github.com/repos/${repository}${route}`, {
method, redirect: 'error', signal: AbortSignal.timeout(30_000),
headers: { Accept: 'application/vnd.github+json', Authorization: `Bearer ${env.GH_TOKEN}`, 'X-GitHub-Api-Version': '2022-11-28', 'Content-Type': 'application/json' },
...(data === undefined ? {} : { body: JSON.stringify(data) }),
});
if (allowMissing && response.status === 404) return null;
assert(response.ok, `GitHub release ${method} ${route} failed: HTTP ${response.status}`);
return response.json();
};
const api = githubApi(env, fetcher);
const tag = 'v' + candidate.version, prerelease = inputs.channel === 'test';
const marker = `<!-- openmotion source=${candidate.sourceCommit} sha256=${candidate.tgzSHA256} -->`;
// Refuse an existing tag pointing at other bytes; never force or move a tag.
@@ -34,27 +109,23 @@ export async function publishReleaseNotes(directory, { env = process.env, fetche
for (let depth = 0; object.type === 'tag' && depth < 5; depth++) object = (await api(`/git/tags/${object.sha}`)).object;
assert.equal(object.type, 'commit'); assert.equal(object.sha, candidate.sourceCommit, 'Release tag already identifies another source');
}
// Listing with write access includes drafts; the by-tag endpoint documents published releases only.
const releases = [];
for (let page = 1; ; page++) {
assert(page <= 100, 'GitHub release history exceeds the bounded lookup');
const batch = await api(`/releases?per_page=100&page=${page}`);
assert(Array.isArray(batch), 'Invalid GitHub release list');
releases.push(...batch);
if (batch.length < 100) break;
}
const releases = await listReleases(api);
let release = releases.find(r => r.tag_name === tag);
if (!release) {
const previous = releases.filter(r => !r.draft && r.prerelease === prerelease && /^v\d+\.\d+\.\d+(?:-test\.[1-9]\d*(?:\.[1-9]\d*)*)?$/.test(r.tag_name))
.filter(r => compareReleaseVersions(r.tag_name.slice(1), candidate.version) < 0)
.sort((a, b) => compareReleaseVersions(b.tag_name.slice(1), a.tag_name.slice(1)))[0];
const generated = await api('/releases/generate-notes', 'POST', {
tag_name: tag, target_commitish: candidate.sourceCommit, ...(previous ? { previous_tag_name: previous.tag_name } : {}),
});
assert.equal(typeof generated.body, 'string', 'Missing generated release notes');
let changes;
if (candidate.schemaVersion >= 3) changes = await readFile(path.join(directory, 'release-notes.md'), 'utf8');
else {
// Older sealed candidates have no draft; retain their existing publication behavior.
const previous = previousRelease(releases, candidate.version, prerelease);
const generated = await api('/releases/generate-notes', 'POST', {
tag_name: tag, target_commitish: candidate.sourceCommit, ...(previous ? { previous_tag_name: previous.tag_name } : {}),
});
assert.equal(typeof generated.body, 'string', 'Missing generated release notes');
changes = `${previous ? '' : 'This is the first GitHub Release in this channel; the generated changes may include earlier repository history.\n\n'}${generated.body}`;
}
const prefix = prerelease ? 'open-motion/dev' : 'open-motion';
const body = `## Installation\n\n- [Exact ${candidate.version} installation](${origin.origin}/${prefix}/${candidate.version}/install.md)\n- [Current ${inputs.channel} installation](${origin.origin}/${prefix}/install.md)\n- npm: \`${candidate.packageName}@${candidate.version}\`; templates: **${prerelease ? 'DEV' : 'prod'}**.\n\n## Release identity\n\n- Source: [\`${candidate.sourceCommit}\`](https://github.com/${repository}/commit/${candidate.sourceCommit})\n- npm tgz SHA256: \`${candidate.tgzSHA256}\`\n- [Publication and verification](https://github.com/${repository}/actions/runs/${env.GITHUB_RUN_ID})\n\n${prerelease ? 'Test installation checks run separately and may still be pending.' : 'Both exact-version macOS ARM64 and Windows x64 installation checks passed.'} Live templates, real Agent creation and human audiovisual acceptance are separate checks.\n\n${previous ? '' : 'This is the first GitHub Release in this channel; the generated changes may include earlier repository history.\n\n'}${generated.body}\n\n${marker}\n`;
await writeFile(path.join(directory, 'release-notes.md'), body);
const body = `## Installation\n\n- [Exact ${candidate.version} installation](${origin.origin}/${prefix}/${candidate.version}/install.md)\n- [Current ${inputs.channel} installation](${origin.origin}/${prefix}/install.md)\n- npm: \`${candidate.packageName}@${candidate.version}\`; templates: **${prerelease ? 'DEV' : 'prod'}**.\n\n## Release identity\n\n- Source: [\`${candidate.sourceCommit}\`](https://github.com/${repository}/commit/${candidate.sourceCommit})\n- npm tgz SHA256: \`${candidate.tgzSHA256}\`\n- [Publication and verification](https://github.com/${repository}/actions/runs/${env.GITHUB_RUN_ID})\n\n${prerelease ? 'Test installation checks run separately and may still be pending.' : 'Both exact-version macOS ARM64 and Windows x64 installation checks passed.'} Live templates, real Agent creation and human audiovisual acceptance are separate checks.\n\n${changes}\n\n${marker}\n`;
await writeFile(path.join(directory, 'github-release-notes.md'), body);
release = await api('/releases', 'POST', { tag_name: tag, target_commitish: candidate.sourceCommit, name: `OpenMotion ${candidate.version}`, body, draft: true, prerelease });
}
assert.equal(release.tag_name, tag); assert.equal(release.prerelease, prerelease);
@@ -65,7 +136,7 @@ export async function publishReleaseNotes(directory, { env = process.env, fetche
make_latest: !prerelease && attempt.stage !== 'archived-superseded' ? 'true' : 'false' });
}
assert.equal(release.draft, false); assert.equal(release.tag_name, tag); assert.equal(release.prerelease, prerelease);
await writeFile(path.join(directory, 'release-notes.md'), release.body);
await writeFile(path.join(directory, 'github-release-notes.md'), release.body);
const record = { version: candidate.version, sourceCommit: candidate.sourceCommit, tgzSHA256: candidate.tgzSHA256,
publicationRun: env.GITHUB_RUN_ID, releaseId: release.id, url: release.html_url, tag, prerelease, status: 'published' };
await writeFile(path.join(directory, 'github-release.json'), JSON.stringify(record, null, 2) + '\n');
@@ -73,6 +144,8 @@ export async function publishReleaseNotes(directory, { env = process.env, fetche
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
assert.equal(process.argv.length, 3, 'Usage: motion-release-notes.mjs <verified-candidate-directory>');
console.log(JSON.stringify(await publishReleaseNotes(path.resolve(process.argv[2])), null, 2));
const prepare = process.argv[2] === 'prepare';
assert.equal(process.argv.length, prepare ? 4 : 3, 'Usage: motion-release-notes.mjs [prepare] <directory>');
const result = prepare ? await prepareCandidateNotes(path.resolve(process.argv[3])) : await publishReleaseNotes(path.resolve(process.argv[2]));
if (!prepare) console.log(JSON.stringify(result, null, 2));
}

View File

@@ -92,6 +92,10 @@ export async function validateSource(control, commit, version, run = runFile, ch
await run('git', ['merge-base', '--is-ancestor', commit, 'refs/remotes/origin/main'], { cwd: control });
}
export function candidateNoteIdentity(candidate) {
return `<!-- openmotion-candidate version=${candidate.version} source=${candidate.sourceCommit} sha256=${candidate.tgzSHA256} -->`;
}
export async function sealCandidate(build, output, source, env = process.env) {
const manifest = await json(path.join(build, 'release-npm.json'));
assert.equal(manifest.commit, (await runFile('git', ['rev-parse', 'HEAD'], { cwd: source })).trim());
@@ -105,7 +109,7 @@ export async function sealCandidate(build, output, source, env = process.env) {
const filename = manifest.installer.url.replace(/^\.\//, '');
assert.equal(filename, `openmotion-app-${manifest.version}.tgz`);
await mkdir(output, { recursive: true });
for (const name of [filename, 'release-npm.json', 'source-scan.json', 'package-scan.json']) await cp(path.join(build, name), path.join(output, name));
for (const name of [filename, 'release-npm.json', 'source-scan.json', 'package-scan.json', 'release-notes.md']) await cp(path.join(build, name), path.join(output, name));
const guide = await generateInstallGuide(path.join(output, filename), output);
assert.equal(guide.packageName, '@openmotion/app'); assert.equal(guide.commit, env.MOTION_SOURCE_SHA);
for (const name of ['source-scan.json', 'package-scan.json']) assert.equal((await json(path.join(output, name))).status, 'passed');
@@ -123,9 +127,11 @@ export async function sealCandidate(build, output, source, env = process.env) {
const instructions = installTemplate.replace(/\{\{([A-Z0-9_]+)\}\}/g, (_, key) => { assert(Object.hasOwn(values, key)); return values[key]; });
assert(!instructions.includes('{{'), 'Unresolved candidate instructions');
await writeFile(path.join(output, 'candidate-install.md'), instructions);
const names = [filename, 'release-npm.json', 'source-scan.json', 'package-scan.json', 'install.md', 'install-record.json', 'acceptance.md', 'candidate-install.md'];
const notes = await readFile(path.join(output, 'release-notes.md'), 'utf8');
assert(Buffer.byteLength(notes) <= 1024 * 1024 && notes.includes(candidateNoteIdentity({ ...identity, version: manifest.version })), 'Candidate notes identity mismatch');
const names = [filename, 'release-npm.json', 'source-scan.json', 'package-scan.json', 'install.md', 'install-record.json', 'acceptance.md', 'candidate-install.md', 'release-notes.md'];
const files = Object.fromEntries(await Promise.all(names.map(async name => [name, await sha256(path.join(output, name))])));
const candidate = { schemaVersion: 2, kind: 'motion-candidate', packageName: guide.packageName, version: guide.version,
const candidate = { schemaVersion: 3, kind: 'motion-candidate', packageName: guide.packageName, version: guide.version,
sourceCommit: guide.commit, tgz: filename, tgzSHA256: files[filename], integrity: integrity(await readFile(path.join(output, filename))), files,
workflow: { repository, path: candidateWorkflow, ref: workflowRef, sha: env.GITHUB_SHA,
runId: Number(env.GITHUB_RUN_ID), attempt: Number(env.GITHUB_RUN_ATTEMPT) },
@@ -184,7 +190,7 @@ async function verifyAuthorization(directory, inputs, env = process.env) {
export async function verifyCandidate(directory, expectedSHA256, run) {
const candidate = await json(path.join(directory, 'candidate.json'));
assert.equal(candidate.schemaVersion, 2); assert.equal(candidate.kind, 'motion-candidate'); assert.equal(candidate.packageName, '@openmotion/app');
assert([2, 3].includes(candidate.schemaVersion), 'Unsupported candidate schema'); assert.equal(candidate.kind, 'motion-candidate'); assert.equal(candidate.packageName, '@openmotion/app');
checkReleaseVersion(candidate.version);
assert.equal(candidate.tgz, `openmotion-app-${candidate.version}.tgz`); assert.equal(candidate.tgzSHA256, expectedSHA256);
assert.match(expectedSHA256, hashPattern); assert.match(candidate.sourceCommit, /^[a-f0-9]{40}$/);
@@ -196,8 +202,13 @@ export async function verifyCandidate(directory, expectedSHA256, run) {
assert([repository, 'nexu-io/html-anything'].includes(receiptRepository), 'Untrusted candidate repository');
assert.deepEqual(candidate.workflow, { repository: receiptRepository, path: candidateWorkflow, ref, sha: run.head_sha, runId: run.id, attempt: run.run_attempt });
const names = [candidate.tgz, 'release-npm.json', 'source-scan.json', 'package-scan.json', 'install.md', 'install-record.json', 'acceptance.md', 'candidate-install.md'];
if (candidate.schemaVersion >= 3) names.push('release-notes.md');
assert.deepEqual(Object.keys(candidate.files).sort(), names.sort());
for (const name of names) assert.equal(await sha256(path.join(directory, name)), candidate.files[name], 'Candidate file changed: ' + name);
if (candidate.schemaVersion >= 3) {
const notes = await readFile(path.join(directory, 'release-notes.md'), 'utf8');
assert(Buffer.byteLength(notes) <= 1024 * 1024 && notes.includes(candidateNoteIdentity(candidate)), 'Candidate notes identity mismatch');
}
assert.equal(await sha256(path.join(directory, candidate.tgz)), expectedSHA256);
assert.equal(integrity(await readFile(path.join(directory, candidate.tgz))), candidate.integrity);
const guide = await json(path.join(directory, 'install-record.json'));
@@ -244,7 +255,7 @@ export async function downloadCandidate(version, directory, expectedSHA256, fetc
try {
const archive = path.join(work, 'candidate.zip'); await writeFile(archive, bytes);
const entries = (await runFile('unzip', ['-Z1', archive])).trim().split('\n');
assert(entries.length === 9 && new Set(entries).size === 9, 'Unexpected candidate artifact files');
assert([9, 10].includes(entries.length) && new Set(entries).size === entries.length, 'Unexpected candidate artifact files');
assert(entries.every(name => /^[a-zA-Z0-9._-]+$/.test(name) && name.length < 160), 'Unsafe candidate artifact entry');
await mkdir(directory, { recursive: true });
for (const name of entries) {
@@ -252,6 +263,7 @@ export async function downloadCandidate(version, directory, expectedSHA256, fetc
await writeFile(path.join(directory, name), stdout);
}
const candidate = await verifyCandidate(directory, expectedSHA256 || (await json(path.join(directory, 'candidate.json'))).tgzSHA256, run);
assert.deepEqual(entries.sort(), ['candidate.json', ...Object.keys(candidate.files)].sort(), 'Unexpected candidate artifact files');
assert.equal(candidate.version, version, 'Artifact version differs from the accepted version');
await writeJSON(path.join(directory, 'provenance.json'), { runId: run.id, attempt: run.run_attempt, head_branch: run.head_branch, head_sha: run.head_sha, artifactId: artifact.id, digest: artifact.digest });
return candidate;