An open source design system that's fully customizable and agent ready
TypeScript
ci: validate a release merge-back against the main commit its merge was built on (#9841)
Cindy Zhang217fc4658dce
diff --git a/.github/scripts/release-publish-workflow.test.mjs b/.github/scripts/release-publish-workflow.test.mjsindex 688df918f7..04e063215b 100644--- a/.github/scripts/release-publish-workflow.test.mjs+++ b/.github/scripts/release-publish-workflow.test.mjs@@ -455,7 +455,7 @@ describe('stable and canary publication authority', () => {'git show origin/main:scripts/release/active-release.mjs','git show origin/main:scripts/lib/workspace-globs.mjs','validate-merge-back',- '--base origin/main',+ '--base HEAD^1','--release-ref "v$VERSION"','--active-branches "$ACTIVE_BRANCHES"',]) {@@ -466,7 +466,7 @@ describe('stable and canary publication authority', () => {'Validate published bytes and consumed-only Changeset merge-back',).run;expect(validation).toContain('validate-merge-back');- expect(validation).toContain('--base origin/main');+ expect(validation).toContain('--base HEAD^1');expect(validation).toContain('--release-ref "v$VERSION"');expect(validation).toContain('--active-branches "$ACTIVE_BRANCHES"');expect(diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex c082e251f2..b97a2777f3 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -464,9 +464,11 @@ jobs:printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'VALIDATOR="$RUNNER_TEMP/release-policy/scripts/release/active-release.mjs"ACTIVE_BRANCHES=$(node "$VALIDATOR" list-active --root "$GITHUB_WORKSPACE")+ # The merge commit's first parent: the main commit it was built on.+ # A main that moved since would read its new files as deletions.node "$VALIDATOR" validate-merge-back \--root "$GITHUB_WORKSPACE" \- --base origin/main \+ --base HEAD^1 \--release-ref "v$VERSION" \--active-branches "$ACTIVE_BRANCHES"diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex a78375c020..5a4f81bc84 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -139,9 +139,11 @@ jobs:> "$TRUSTED_POLICY/scripts/lib/workspace-globs.mjs"VALIDATOR="$TRUSTED_POLICY/scripts/release/active-release.mjs"ACTIVE_BRANCHES=$(node "$VALIDATOR" list-active --root "$GITHUB_WORKSPACE")+ # The merge commit's first parent: the main commit it was built on.+ # A main that moved since would read its new files as deletions.node "$VALIDATOR" validate-merge-back \--root "$GITHUB_WORKSPACE" \- --base origin/main \+ --base HEAD^1 \--release-ref "v$VERSION" \--active-branches "$ACTIVE_BRANCHES"diff --git a/scripts/release/active-release.mjs b/scripts/release/active-release.mjsindex 9c63e78e94..ce7cd34efa 100644--- a/scripts/release/active-release.mjs+++ b/scripts/release/active-release.mjs@@ -463,6 +463,22 @@ function currentOutputMap(root, files) {);}+/**+ * The merge-back's changes against `base`: `git diff --name-status` lines.+ * `base` must be the merge commit's first parent, the main commit the merge+ * was built on. A later main would show every file it gained as a deletion.+ */+function mergeBackEntries(root, base) {+ const raw = git(root, [+ 'diff',+ '--name-status',+ '--find-renames',+ base,+ 'HEAD',+ ]);+ return raw ? raw.split('\n') : [];+}+function markerAtRef(root, ref) {return JSON.parse(git(root, ['show', `${ref}:${RELEASE_DIR}/${MARKER_FILE}`]),@@ -1142,13 +1158,7 @@ async function main() {errors.push('release merge-back requires exactly the marked active branch',);- const raw = git(root, [- 'diff',- '--name-status',- '--find-renames',- base,- 'HEAD',- ]);+ const entries = mergeBackEntries(root, base);const releaseDiff = git(root, ['diff','--name-status',@@ -1198,7 +1208,7 @@ async function main() {const baseConfig = jsonAtRef(root, base, '.changeset/config.json');errors.push(...validateReleaseMergeBack({- entries: raw ? raw.split('\n') : [],+ entries,plan,baseChangesets: changesetMapAtRef(root, base),headChangesets: new Map(@@ -1292,6 +1302,7 @@ export {isStableReleasePackage,latestStableVersion,listActiveBranches,+ mergeBackEntries,validateIdentity,validateRefMarker,validateReleaseDiff,diff --git a/scripts/release/active-release.test.mjs b/scripts/release/active-release.test.mjsindex 1123a3e458..9c819224ea 100644--- a/scripts/release/active-release.test.mjs+++ b/scripts/release/active-release.test.mjs@@ -19,6 +19,7 @@ import {canaryEligibility,declaredVersionAtRef,latestStableVersion,+ mergeBackEntries,nextPlannedVersion,validateReleaseDiff,validateReleaseMergeBack,@@ -688,6 +689,88 @@ describe('published release merge-back (FR50)', () => {);});+ describe('compared with the merge commit it was built on', () => {+ // A merge-back pull request's merge commit, built on an older main, while+ // main has since gained a file.+ function movedMain() {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-merge-back-'));+ roots.push(root);+ const write = (file, text) => {+ fs.mkdirSync(path.dirname(path.join(root, file)), {recursive: true});+ fs.writeFileSync(path.join(root, file), text);+ };+ git(root, 'init', '-q', '-b', 'main');+ git(root, 'config', 'user.name', 'Release Test');+ git(root, 'config', 'user.email', '[email protected]');+ write('.changeset/frozen.md', 'frozen\n');+ write('packages/core/CHANGELOG.md', '# Changelog\n');+ git(root, 'add', '.');+ git(root, 'commit', '-qm', 'main the merge was built on');+ const builtOn = git(root, 'rev-parse', 'HEAD');+ git(root, 'checkout', '-q', '-b', 'chore/merge-v0.7.0-to-main');+ fs.rmSync(path.join(root, '.changeset/frozen.md'));+ write('packages/core/CHANGELOG.md', '# Changelog\n\n## 0.7.0\n');+ git(root, 'add', '-A');+ git(root, 'commit', '-qm', 'merge back v0.7.0');+ git(root, 'checkout', '-q', 'main');+ write('packages/core/src/Later.tsx', 'export {};\n');+ git(root, 'add', '.');+ git(root, 'commit', '-qm', 'main moves on');+ git(root, 'update-ref', 'refs/remotes/origin/main', 'HEAD');+ git(root, 'checkout', '-q', '--detach', builtOn);+ git(+ root,+ 'merge',+ '-q',+ '--no-ff',+ '-m',+ 'merge ref',+ 'chore/merge-v0.7.0-to-main',+ );+ return root;+ }++ it('lists only the merge-back changes against the first parent', () => {+ const root = movedMain();+ const entries = mergeBackEntries(root, 'HEAD^1');+ expect(entries).toEqual([+ 'D\t.changeset/frozen.md',+ 'M\tpackages/core/CHANGELOG.md',+ ]);+ expect(+ mergeBack({base: mainAt('0.7.0'), head: mainAt('0.7.0'), entries}),+ ).toEqual([]);+ });++ it("reads a later main's new file as a deletion, which fails merge-back", () => {+ const root = movedMain();+ const entries = mergeBackEntries(root, 'origin/main');+ expect(entries).toContain('D\tpackages/core/src/Later.tsx');+ expect(+ mergeBack({+ base: mainAt('0.7.0'),+ head: mainAt('0.7.0'),+ entries,+ }).join('\n'),+ ).toContain('packages/core/src/Later.tsx');+ });++ it.each(['.github/workflows/ci.yml', '.github/workflows/lint.yml'])(+ '%s validates against the merge commit first parent',+ file => {+ const text = fs.readFileSync(+ path.join(import.meta.dirname, '../..', file),+ 'utf8',+ );+ const call = text.slice(text.indexOf('validate-merge-back \\'));+ expect(call).toMatch(+ /^validate-merge-back \\\n\s+--root "\$GITHUB_WORKSPACE" \\\n\s+--base HEAD\^1 \\/,+ );+ expect(text).not.toContain('--base origin/main');+ },+ );+ });+it('rejects missing frozen deletions and exact-output drift', () => {expect(mergeBack({