Skip to content

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

TypeScript

ci: allow existing changeset reclassification with specs (#6775)

Cindy Zhang58ae2714a126
diff --git a/.github/scripts/change-scope.cjs b/.github/scripts/change-scope.cjs
index 230b1c756a..dba1043991 100644
--- a/.github/scripts/change-scope.cjs
+++ b/.github/scripts/change-scope.cjs
@@ -130,11 +130,12 @@ function surfacesForPath(filePath) {
function normalizeChange(change) {
if (typeof change === 'string') {
- return {filename: change, previous_filename: null};
+ return {filename: change, previous_filename: null, status: null};
}
return {
filename: change.filename,
previous_filename: change.previous_filename ?? null,
+ status: change.status ?? null,
};
}
@@ -173,12 +174,26 @@ function classifyChanges(changes, {expectedCount} = {}) {
filePath.startsWith('docs/design/assets/'),
);
const hasSpecRecord = allPaths.some(isSpecRecordPath);
- const hasChangeset = allPaths.some(filePath =>
- CHANGESET_PATTERN.test(filePath),
- );
+ // Only an exact in-place M can represent correcting already-pending release
+ // metadata. Added, deleted, renamed (in either direction), or status-unknown
+ // Changesets stay fail-closed so a spec-only change cannot create, remove, or
+ // park a package release.
+ const hasNonModificationChangeset = normalized.some(change => {
+ const touchesChangeset =
+ CHANGESET_PATTERN.test(change.filename) ||
+ (change.previous_filename != null &&
+ CHANGESET_PATTERN.test(change.previous_filename));
+ return (
+ touchesChangeset &&
+ (change.status !== 'M' || change.previous_filename != null)
+ );
+ });
const hasPackageReleaseChange = allPaths.some(isPackageReleasePath);
const specChangesetConflict =
- complete && hasSpecRecord && hasChangeset && !hasPackageReleaseChange;
+ complete &&
+ hasSpecRecord &&
+ hasNonModificationChangeset &&
+ !hasPackageReleaseChange;
const exactSurface = surface =>
complete && surfaces.length === 1 && surfaces[0] === surface;
const specOnly = exactSurface(SURFACES.KNOWLEDGE);
@@ -216,9 +231,10 @@ function parseNameStatus(input) {
return {
filename: fields[2],
previous_filename: fields[1],
+ status,
};
}
- return {filename: fields[1] ?? fields[0]};
+ return {filename: fields[1] ?? fields[0], status};
});
}
diff --git a/.github/scripts/change-scope.test.mjs b/.github/scripts/change-scope.test.mjs
index 19e502299e..0161155f80 100644
--- a/.github/scripts/change-scope.test.mjs
+++ b/.github/scripts/change-scope.test.mjs
@@ -57,6 +57,50 @@ describe('spec-only change scope', () => {
expect(result.specChangesetConflict).toBe(true);
});
+ it('allows an existing Changeset reclassification beside its governing spec', () => {
+ const result = classifyChanges([
+ {status: 'M', filename: 'docs/specs/AST-017/spec.md'},
+ {status: 'M', filename: '.changeset/existing-release.md'},
+ ]);
+ expect(result.specChangesetConflict).toBe(false);
+ });
+
+ it.each([
+ ['added', {status: 'A', filename: '.changeset/new-release.md'}],
+ ['deleted', {status: 'D', filename: '.changeset/old-release.md'}],
+ [
+ 'renamed in',
+ {
+ status: 'R100',
+ filename: '.changeset/new-release.md',
+ previous_filename: 'notes/release.md',
+ },
+ ],
+ [
+ 'renamed out',
+ {
+ status: 'R100',
+ filename: 'notes/release.md',
+ previous_filename: '.changeset/old-release.md',
+ },
+ ],
+ ['missing status', {filename: '.changeset/unknown-release.md'}],
+ [
+ 'worktree/index status',
+ {status: 'MM', filename: '.changeset/mixed-release.md'},
+ ],
+ [
+ 'rename-like M status',
+ {status: 'M087', filename: '.changeset/odd-release.md'},
+ ],
+ ])('rejects a %s Changeset beside spec records', (_label, changeset) => {
+ const result = classifyChanges([
+ {status: 'M', filename: 'docs/specs/AST-017/spec.md'},
+ changeset,
+ ]);
+ expect(result.specChangesetConflict).toBe(true);
+ });
+
it('does not let an unrelated file hide a spec-only Changeset', () => {
const result = classifyChanges([
{filename: 'docs/families/input-fields.md'},
@@ -174,8 +218,12 @@ describe('spec-only change scope', () => {
'A\tdocs/specs/AST-001-x/spec.md\nR100\told.ts\tpackages/core/src/X/X.spec.md\n',
),
).toEqual([
- {filename: 'docs/specs/AST-001-x/spec.md'},
- {filename: 'packages/core/src/X/X.spec.md', previous_filename: 'old.ts'},
+ {filename: 'docs/specs/AST-001-x/spec.md', status: 'A'},
+ {
+ filename: 'packages/core/src/X/X.spec.md',
+ previous_filename: 'old.ts',
+ status: 'R100',
+ },
]);
});
});