Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(ci): keep checked release heads valid as main advances (#7119)

Cindy Zhang83f635a8e4f9
diff --git a/.github/scripts/release-check-workflow.test.mjs b/.github/scripts/release-check-workflow.test.mjs
index a8f582c59a..68f082df3a 100644
--- a/.github/scripts/release-check-workflow.test.mjs
+++ b/.github/scripts/release-check-workflow.test.mjs
@@ -99,6 +99,22 @@ function shell(script, env = {}, prefix = '') {
const sha = 'a'.repeat(40);
const releaseBranch = 'release/v0.6.5';
const planDigest = 'b'.repeat(64);
+
+function mainAuthorityGit(remoteSha = sha, ancestor = true) {
+ return `MAIN_FETCHED=false
+ git() {
+ case "$1" in
+ ls-remote) printf '%s\\n' '${remoteSha}\\trefs/heads/main' ;;
+ fetch) MAIN_FETCHED=true ;;
+ merge-base)
+ [ "$MAIN_FETCHED" = true ] || return 98
+ return ${ancestor ? 0 : 1}
+ ;;
+ *) return 99 ;;
+ esac
+ }`;
+}
+
async function githubScript(
script,
{
@@ -110,6 +126,7 @@ async function githubScript(
plan = planDigest,
needs,
apiFails = false,
+ compareStatus = 'identical',
} = {},
) {
const summary = {
@@ -139,6 +156,12 @@ async function githubScript(
return {data: {object: {sha: remoteSha}}};
},
},
+ repos: {
+ async compareCommitsWithBasehead(request) {
+ expect(request.basehead).toBe(`${expectedHead}...${remoteSha}`);
+ return {data: {status: compareStatus}};
+ },
+ },
},
},
{summary},
@@ -252,7 +275,7 @@ describe('exact main pre-cut authority', () => {
);
});
- it('binds the run and remote main to the requested SHA', () => {
+ it('binds the run to the requested SHA in current main history', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-main-check-'));
const output = path.join(dir, 'output');
try {
@@ -264,7 +287,7 @@ describe('exact main pre-cut authority', () => {
GITHUB_SHA: sha,
GITHUB_OUTPUT: output,
},
- `git() { printf '%s\\n' '${sha}\trefs/heads/main'; }`,
+ mainAuthorityGit(),
);
expect(result.status, result.stderr).toBe(0);
expect(fs.readFileSync(output, 'utf8')).toBe(
@@ -275,6 +298,20 @@ describe('exact main pre-cut authority', () => {
}
});
+ it('accepts a checked SHA that remains an ancestor after main advances', () => {
+ const result = shell(
+ authority.run,
+ {
+ EXPECTED_HEAD: sha,
+ GITHUB_REF: 'refs/heads/main',
+ GITHUB_SHA: sha,
+ GITHUB_OUTPUT: '/dev/null',
+ },
+ mainAuthorityGit('b'.repeat(40)),
+ );
+ expect(result.status, result.stderr).toBe(0);
+ });
+
it.each([
['wrong ref', {GITHUB_REF: 'refs/heads/candidate', GITHUB_SHA: sha}],
[
@@ -285,12 +322,12 @@ describe('exact main pre-cut authority', () => {
const result = shell(
authority.run,
{...values, EXPECTED_HEAD: sha, GITHUB_OUTPUT: '/dev/null'},
- `git() { printf '%s\\n' '${sha}\trefs/heads/main'; }`,
+ mainAuthorityGit(),
);
expect(result.status).not.toBe(0);
});
- it('rejects remote main drift', () => {
+ it('rejects a checked SHA removed from current main history', () => {
const result = shell(
authority.run,
{
@@ -299,10 +336,12 @@ describe('exact main pre-cut authority', () => {
GITHUB_SHA: sha,
GITHUB_OUTPUT: '/dev/null',
},
- `git() { printf '%s\\n' '${'b'.repeat(40)}\trefs/heads/main'; }`,
+ mainAuthorityGit('b'.repeat(40), false),
);
expect(result.status).not.toBe(0);
- expect(result.stdout).toContain('Main moved before checks began');
+ expect(result.stdout).toContain(
+ 'Checked main commit is not an ancestor of current main',
+ );
});
});
@@ -335,6 +374,30 @@ describe('exact main and release branch completion', () => {
).resolves.toBeUndefined();
});
+ it('accepts complete exact-main evidence after main advances', async () => {
+ await expect(
+ githubScript(join, {
+ branch: 'main',
+ remoteSha: 'b'.repeat(40),
+ compareStatus: 'ahead',
+ plan: '',
+ needs: complete,
+ }),
+ ).resolves.toBeUndefined();
+ });
+
+ it('rejects exact-main evidence removed from current main history', async () => {
+ await expect(
+ githubScript(join, {
+ branch: 'main',
+ remoteSha: 'b'.repeat(40),
+ compareStatus: 'diverged',
+ plan: '',
+ needs: complete,
+ }),
+ ).rejects.toThrow('not an ancestor of current main');
+ });
+
it('requires the successful main authority step to bind the expected head', async () => {
await expect(
githubScript(join, {
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e3c1d161bf..bdcc564e56 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -146,8 +146,13 @@ jobs:
exit 1
fi
REMOTE_HEAD=$(git ls-remote origin refs/heads/main | awk '{print $1}')
- if [ -z "$REMOTE_HEAD" ] || [ "$REMOTE_HEAD" != "$EXPECTED_HEAD" ]; then
- echo 'Main moved before checks began; dispatch again for its new head.'
+ if [ -z "$REMOTE_HEAD" ]; then
+ echo 'Current main head is unavailable.'
+ exit 1
+ fi
+ git fetch --no-tags origin "$REMOTE_HEAD"
+ if ! git merge-base --is-ancestor "$EXPECTED_HEAD" "$REMOTE_HEAD"; then
+ echo 'Checked main commit is not an ancestor of current main.'
exit 1
fi
printf 'branch=main\nhead=%s\n' "$EXPECTED_HEAD" >> "$GITHUB_OUTPUT"
@@ -2385,20 +2390,27 @@ jobs:
throw new Error('Checked-out commit does not match expected head.');
}
const {data} = await github.rest.git.getRef({...context.repo, ref: `heads/${branch}`});
- if (data.object.sha !== expectedHead) {
- throw new Error(`${branch} moved during checks; dispatch release-check again for its new head.`);
- }
if (branch === 'main') {
if (process.env.CHECKED_HEAD !== expectedHead) {
throw new Error('Main authority check did not bind the expected head.');
}
+ const comparison = await github.rest.repos.compareCommitsWithBasehead({
+ ...context.repo,
+ basehead: `${expectedHead}...${data.object.sha}`,
+ });
+ if (!['identical', 'ahead'].includes(comparison.data.status)) {
+ throw new Error('Checked main commit is not an ancestor of current main.');
+ }
await core.summary
.addHeading('Main pre-cut checks complete')
.addRaw(`Exact head: ${expectedHead}\n\n`)
- .addRaw('Canonical visual, accessibility, and RTL checks completed with full scope. A release may cut only while main still points to this exact head.')
+ .addRaw('Canonical visual, accessibility, and RTL checks completed with full scope. This exact checked commit may be used as the cut SHA while it remains in current main history; later main commits are next-release input.')
.write();
return;
}
+ if (data.object.sha !== expectedHead) {
+ throw new Error(`${branch} moved during checks; dispatch release-check again for its new head.`);
+ }
if (!branch.startsWith('release/v')) {
throw new Error('Post-bump release checks require a marked release branch.');
}