Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Batch release ancestry queries to finish reporter writeback (#4968)

Andrew Mikofalvy70497fa1c9c5
diff --git a/.github/scripts/resolve-shipped-version.mjs b/.github/scripts/resolve-shipped-version.mjs
index 51e325acd..36d4e9357 100644
--- a/.github/scripts/resolve-shipped-version.mjs
+++ b/.github/scripts/resolve-shipped-version.mjs
@@ -4,6 +4,7 @@ import { execFileSync, spawnSync } from 'node:child_process';
import { appendFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
import { realPublishedReleaseTags, sortReleaseTagsAscending } from './published-release-tags.mjs';
+import { createTagContainment } from './tag-containment.mjs';
const STABLE_TAG_RE = /^v(\d+)\.(\d+)\.(\d+)$/;
const FULL_SHA_RE = /^[0-9a-f]{40}$/i;
@@ -154,17 +155,6 @@ export function realFindMirroredCommits(privateSha) {
return commits;
}
-export function realContains(tag, sha) {
- const res = spawnSync('git', ['merge-base', '--is-ancestor', sha, `${tag}^{commit}`], {
- encoding: 'utf8',
- });
- if (res.status === 0) return true;
- if (res.status === 1) return false;
- throw new Error(
- `git merge-base --is-ancestor ${sha} ${tag} failed (exit ${res.status}): ${String(res.stderr || '').trim()}`,
- );
-}
-
function realResolvePrMergeSha({ owner, repo, number }) {
let out;
try {
@@ -207,7 +197,7 @@ function main() {
privateSha,
stableTags: realPublishedReleaseTags(),
findMirroredCommits: realFindMirroredCommits,
- contains: realContains,
+ contains: createTagContainment(),
});
} catch (err) {
console.error(`::error::resolve-shipped-version: ${err.message}`);
diff --git a/.github/scripts/stamp-by-containment.mjs b/.github/scripts/stamp-by-containment.mjs
index eecca63fb..70916a7cb 100644
--- a/.github/scripts/stamp-by-containment.mjs
+++ b/.github/scripts/stamp-by-containment.mjs
@@ -3,11 +3,8 @@
import { execFileSync } from 'node:child_process';
import { pathToFileURL } from 'node:url';
import { realPublishedReleaseTags } from './published-release-tags.mjs';
-import {
- realContains,
- realFindMirroredCommits,
- resolveShippedVersion,
-} from './resolve-shipped-version.mjs';
+import { realFindMirroredCommits, resolveShippedVersion } from './resolve-shipped-version.mjs';
+import { createTagContainment } from './tag-containment.mjs';
const BETA_VERSION_RE = /-beta\.\d+$/;
const PRIVATE_PR_RE = /github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/;
@@ -189,7 +186,7 @@ async function fetchPipeline() {
return { releaseByVersion, tickets: [...tickets.values()] };
}
-function resolveTicket(ticket, releaseTags, rank) {
+function resolveTicket(ticket, releaseTags, rank, contains) {
let best = null;
let provenNotShipped = false;
for (const url of ticket.prs) {
@@ -203,7 +200,7 @@ function resolveTicket(ticket, releaseTags, rank) {
privateSha: sha,
stableTags: releaseTags,
findMirroredCommits: realFindMirroredCommits,
- contains: realContains,
+ contains,
});
if (r.shipped) {
if (best === null || rank.get(r.tag) < rank.get(best)) best = r.tag;
@@ -231,8 +228,9 @@ async function main() {
log(`Considering ${tickets.length} ticket(s) across ${releaseByVersion.size} release(s).`);
const plans = [];
+ const contains = createTagContainment();
for (const ticket of tickets) {
- const { evidence, shippedTag } = resolveTicket(ticket, releaseTags, rank);
+ const { evidence, shippedTag } = resolveTicket(ticket, releaseTags, rank, contains);
const plan = planTicketReconciliation({
attachedReleases: ticket.attachedReleases,
shippedTag,
diff --git a/.github/scripts/tag-containment.mjs b/.github/scripts/tag-containment.mjs
new file mode 100644
index 000000000..d15cb1970
--- /dev/null
+++ b/.github/scripts/tag-containment.mjs
@@ -0,0 +1,23 @@
+import { execFileSync } from 'node:child_process';
+
+export function createTagContainment({ cwd = process.cwd(), exec = execFileSync } = {}) {
+ const containing = new Map();
+ let tags;
+ const readTags = (args) =>
+ new Set(
+ exec('git', ['for-each-ref', '--format=%(refname:strip=2)', ...args, 'refs/tags/'], {
+ cwd,
+ encoding: 'utf8',
+ })
+ .trim()
+ .split('\n')
+ .filter(Boolean),
+ );
+ return (tag, sha) => {
+ tags ??= readTags([]);
+ if (!tags.has(tag))
+ throw new Error(`Release tag ${tag} is absent from the checked-out history`);
+ if (!containing.has(sha)) containing.set(sha, readTags(['--contains', sha]));
+ return containing.get(sha).has(tag);
+ };
+}
diff --git a/.github/scripts/tag-containment.test.mjs b/.github/scripts/tag-containment.test.mjs
new file mode 100644
index 000000000..d940610a1
--- /dev/null
+++ b/.github/scripts/tag-containment.test.mjs
@@ -0,0 +1,74 @@
+import { execFileSync } from 'node:child_process';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { expect, test } from 'vitest';
+import { gitCleanEnv } from '../../scripts/git-clean-env.mjs';
+import { createTagContainment } from './tag-containment.mjs';
+
+test('batched containment agrees with Git across divergent and annotated tags, using one scan per fix', () => {
+ const cwd = mkdtempSync(join(tmpdir(), 'ok-tag-containment-'));
+ const env = gitCleanEnv();
+ const git = (...args) =>
+ execFileSync(
+ 'git',
+ [
+ '-c',
+ 'user.name=Test',
+ '-c',
+ '-c',
+ 'commit.gpgsign=false',
+ '-c',
+ 'tag.gpgsign=false',
+ ...args,
+ ],
+ { cwd, env, encoding: 'utf8', stdio: 'pipe' },
+ ).trim();
+ try {
+ git('init', '--quiet', '--initial-branch=main');
+ git('commit', '--allow-empty', '-m', 'base');
+ const base = git('rev-parse', 'HEAD');
+ git('tag', 'v0.1.0');
+ git('switch', '-c', 'point-release');
+ git('commit', '--allow-empty', '-m', 'stable-only fix');
+ const stableFix = git('rev-parse', 'HEAD');
+ git('tag', '-a', 'v0.1.2', '-m', 'divergent stable');
+ git('switch', 'main');
+ git('commit', '--allow-empty', '-m', 'feature fix');
+ const feature = git('rev-parse', 'HEAD');
+ git('update-ref', 'refs/tags/v0.1.1', feature);
+ const betaTags = Array.from({ length: 1100 }, (_, i) => `v0.2.0-beta.${i}`);
+ execFileSync('git', ['update-ref', '--stdin'], {
+ cwd,
+ env,
+ input: betaTags.map((tag) => `create refs/tags/${tag} ${feature}\n`).join(''),
+ });
+ let calls = 0;
+ const contains = createTagContainment({
+ cwd,
+ exec: (command, args, options) => {
+ calls++;
+ return execFileSync(command, args, { ...options, env });
+ },
+ });
+ expect(betaTags.map((tag) => contains(tag, feature))).toEqual(betaTags.map(() => true));
+ expect(calls).toBe(2);
+ expect(contains('v0.1.2', feature)).toBe(false);
+ expect(contains('v0.1.1', feature)).toBe(true);
+ expect(contains('v0.1.2', stableFix)).toBe(true);
+ expect(contains('v0.1.1', stableFix)).toBe(false);
+ expect(contains('v0.1.0', base)).toBe(true);
+ expect(contains('v0.1.2', base)).toBe(true);
+ expect(calls).toBe(4);
+ git('commit', '--allow-empty', '-m', 'not released yet');
+ const unreleased = git('rev-parse', 'HEAD');
+ expect(contains('v0.1.1', unreleased)).toBe(false);
+ expect(contains('v0.1.2', unreleased)).toBe(false);
+ expect(calls).toBe(5);
+ expect(() => contains('v9.9.9', feature)).toThrow('absent');
+ expect(() => contains('v0.1.2', 'f'.repeat(40))).toThrow();
+ } finally {
+ rmSync(cwd, { recursive: true, force: true });
+ }
+});
diff --git a/.github/scripts/write-back.mjs b/.github/scripts/write-back.mjs
index df83beba2..807a13a02 100644
--- a/.github/scripts/write-back.mjs
+++ b/.github/scripts/write-back.mjs
@@ -15,6 +15,7 @@ import {
resolveShippedVersion,
sortStableTagsAscending,
} from './resolve-shipped-version.mjs';
+import { createTagContainment } from './tag-containment.mjs';
import {
compareVersions,
composeReply,
@@ -681,17 +682,6 @@ function realFindMirroredCommits(privateSha) {
return commits;
}
-function realContains(tag, sha) {
- const res = spawnSync('git', ['merge-base', '--is-ancestor', sha, `${tag}^{commit}`], {
- encoding: 'utf8',
- });
- if (res.status === 0) return true;
- if (res.status === 1) return false;
- throw new Error(
- `git merge-base --is-ancestor ${sha} ${tag} failed (exit ${res.status}): ${String(res.stderr || '').trim()}`,
- );
-}
-
export function selectGhToken({ owner, repo, env }) {
const crossRepo = String(env.CROSS_REPO_TOKEN ?? '').trim();
if (!crossRepo) return null;
@@ -870,12 +860,13 @@ async function main() {
const stableTags = realPublishedReleaseTags();
requirePublishedRelease(releaseTag, stableTags);
+ const contains = createTagContainment();
const versionFor = (node) =>
deriveVersionForFixRefs({
fixReferences: partitionAttachments(node.attachmentUrls ?? []).fixReferences,
stableTags,
findMirroredCommits: realFindMirroredCommits,
- contains: realContains,
+ contains,
resolvePrMergeSha: realResolvePrMergeSha,
readCommitMessage: realReadCommitMessage,
channel,