From cb97a4b40cd5fd1849f90a75bdf96268d70c380c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 23:23:51 +0000 Subject: [PATCH] build(release): release the TypeScript package only when a published file changes The release filter counted every commit under typescript/ or conformance/, so a feat commit that changed only tests, scripts, examples or the conformance vectors would cut a release with no package difference. Count only the files the npm and JSR packages publish, add excluding globs to release-paths for test files, and test that the list matches package.json, jsr.json and tsconfig.build.json. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YPqZer6DeXwJsTVBC3d77s --- typescript/.releaserc.json | 11 +++++- typescript/PUBLISHING.md | 13 ++++-- typescript/scripts/release-config.test.ts | 48 ++++++++++++++++++++++- typescript/scripts/release-paths.test.ts | 31 +++++++++++++++ typescript/scripts/release-paths.ts | 23 +++++++---- 5 files changed, 111 insertions(+), 15 deletions(-) diff --git a/typescript/.releaserc.json b/typescript/.releaserc.json index a7c5d8c..2eade97 100644 --- a/typescript/.releaserc.json +++ b/typescript/.releaserc.json @@ -5,7 +5,16 @@ [ "./scripts/release-paths.ts", { - "paths": ["typescript/", "conformance/"], + "paths": [ + "typescript/src/", + "!typescript/src/**/*.test.ts", + "typescript/README.md", + "typescript/LICENSE", + "typescript/package.json", + "typescript/jsr.json", + "typescript/tsconfig.json", + "typescript/tsconfig.build.json" + ], "preset": "conventionalcommits", "releaseRules": [ { diff --git a/typescript/PUBLISHING.md b/typescript/PUBLISHING.md index 54823d1..aad058a 100644 --- a/typescript/PUBLISHING.md +++ b/typescript/PUBLISHING.md @@ -10,10 +10,15 @@ minor version, so a `BREAKING CHANGE` footer never produces 1.0.0 on its own. The package lives in the repository's `typescript/` directory, and every command below runs from there. Releases are still tagged with the bare version (`0.12.1`); a language prefix waits until a second package releases from this -repository, matching `udibo/oauth2`. Only commits that touch `typescript/` or `conformance/` count toward a -release: `scripts/release-paths.ts` filters the commits before -`@semantic-release/commit-analyzer` and `@semantic-release/release-notes-generator` -see them, so a commit to another language's package releases nothing here. +repository, matching `udibo/oauth2`. Only commits that change a file the npm or JSR package +publishes count toward a release: the non-test files in `src/`, `README.md`, +`LICENSE`, `package.json`, `jsr.json` and the two `tsconfig` files that shape +the build (`paths` in `.releaserc.json`). `scripts/release-paths.ts` filters the +commits before `@semantic-release/commit-analyzer` and +`@semantic-release/release-notes-generator` see them, so a commit that changes +only tests, scripts, examples, CI, the conformance vectors or another +language's package releases nothing here. The package embeds nothing from +`conformance/`; only `src/conformance.test.ts` reads it. The release job in [`.github/workflows/ci.yml`](../.github/workflows/ci.yml) only runs when the repository variable `RELEASE_ENABLED` is `true`. Setting it to diff --git a/typescript/scripts/release-config.test.ts b/typescript/scripts/release-config.test.ts index 20f397d..83f7e9f 100644 --- a/typescript/scripts/release-config.test.ts +++ b/typescript/scripts/release-config.test.ts @@ -192,14 +192,58 @@ describe("the TypeScript package's place in the repository", () => { typeof plugin === "string" ? plugin : plugin[0], ); + it("counts every file the npm and JSR packages publish and nothing they exclude", () => { + const paths = (releaseConfig.plugins[0]![1] as { paths: string[] }).paths; + const counted = (file: string): boolean => + paths.some((path) => + path.endsWith("/") ? file.startsWith(path) : file === path, + ); + const jsr = JSON.parse(read("jsr.json")) as { + publish: { include: string[]; exclude: string[] }; + }; + const npm = JSON.parse(read("package.json")) as { files: string[] }; + const build = JSON.parse(read("tsconfig.build.json")) as { + include: string[]; + exclude: string[]; + }; + const published = [ + ...jsr.publish.include, + ...npm.files.filter((file) => file !== "dist" && !file.startsWith("!")), + ...build.include.map((dir) => `${dir}/**/*.ts`), + ]; + const uncounted = published.filter( + (pattern) => + !counted( + `typescript/${pattern.replace("**/", "nested/").replace("*", "sample")}`, + ), + ); + expect(uncounted).toEqual([]); + expect(paths).toEqual( + expect.arrayContaining( + [...jsr.publish.exclude, ...build.exclude].map( + (pattern) => `!typescript/${pattern}`, + ), + ), + ); + }); + it("keeps the bare version tags of earlier releases", () => { expect(releaseConfig.tagFormat).toBe("${version}"); }); - it("analyzes only the commits that touch the package or the conformance suite", () => { + it("analyzes only the commits that change a published file", () => { expect(pluginNames[0]).toBe("./scripts/release-paths.ts"); expect(releaseConfig.plugins[0]![1]).toMatchObject({ - paths: ["typescript/", "conformance/"], + paths: [ + "typescript/src/", + "!typescript/src/**/*.test.ts", + "typescript/README.md", + "typescript/LICENSE", + "typescript/package.json", + "typescript/jsr.json", + "typescript/tsconfig.json", + "typescript/tsconfig.build.json", + ], preset: "conventionalcommits", }); expect(pluginNames).not.toContain("@semantic-release/commit-analyzer"); diff --git a/typescript/scripts/release-paths.test.ts b/typescript/scripts/release-paths.test.ts index 7a53cd3..da57540 100644 --- a/typescript/scripts/release-paths.test.ts +++ b/typescript/scripts/release-paths.test.ts @@ -40,6 +40,9 @@ beforeAll(() => { commit("typescript", "fix: fix the typescript package", "typescript/a.ts"); commit("vectors", "feat: add a test vector", "conformance/vectors.json"); commit("prefix", "feat!: a sibling with a shared prefix", "typescript-old/a"); + commit("test", "feat: test the package", "typescript/src/mod.test.ts"); + commit("nested", "feat: test a nested module", "typescript/src/x/y.test.ts"); + commit("source", "fix: fix the package source", "typescript/src/mod.ts"); }); afterAll(() => { @@ -84,6 +87,34 @@ describe("commitsTouching", () => { }); }); +describe("commitsTouching with an excluding glob", () => { + const published = ["typescript/src/", "!typescript/src/**/*.test.ts"]; + + it("drops commits that change only excluded files or unlisted paths", () => { + const { cwd, commits } = context( + "vectors", + "typescript", + "test", + "nested", + "source", + ); + expect( + commitsTouching(cwd, published, commits, hashes.released).map( + ({ hash }) => hash, + ), + ).toEqual([hashes.source]); + }); + + it("releases nothing for a feature that changes only tests and vectors", async () => { + expect( + await analyzeCommits( + { paths: published, preset: "conventionalcommits" }, + context("vectors", "test", "nested"), + ), + ).toBeNull(); + }); +}); + describe("analyzeCommits", () => { const config = { paths, preset: "conventionalcommits" }; diff --git a/typescript/scripts/release-paths.ts b/typescript/scripts/release-paths.ts index 2210ef6..39ace74 100644 --- a/typescript/scripts/release-paths.ts +++ b/typescript/scripts/release-paths.ts @@ -1,18 +1,21 @@ /** * A semantic-release plugin that releases this package only for the commits - * that touch its own paths. The repository holds one package per language, so - * a commit to another language's directory must not release this one. + * that change a file it publishes. The repository holds one package per + * language, plus tests, tooling and shared conformance vectors that ship in no + * package, so a commit that changes only those must not release this one. * * Use it in place of `@semantic-release/commit-analyzer` and - * `@semantic-release/release-notes-generator`. `paths` lists the directories, - * relative to the repository root, whose commits count; every other option is - * passed to both of those plugins unchanged. + * `@semantic-release/release-notes-generator`. `paths` lists the files and + * directories, relative to the repository root, whose commits count; an entry + * starting with `!` is a glob that excludes matching files, such as tests + * inside a counted directory. Every other option is passed to both of those + * plugins unchanged. * * It refuses any release that has no previous release tag: a missing tag would * otherwise publish 1.0.0, and a published version cannot be taken back. * * ```json - * ["./scripts/release-paths.ts", { "paths": ["typescript/", "conformance/"], "preset": "conventionalcommits" }] + * ["./scripts/release-paths.ts", { "paths": ["typescript/src/", "!typescript/src/*.test.ts"], "preset": "conventionalcommits" }] * ``` * * @module @@ -43,7 +46,7 @@ export interface ReleaseContext { /** * Returns the commits, in their original order, that change a file under one - * of `paths` (relative to the repository root). + * of `paths` (relative to the repository root) that no `!` glob excludes. */ export function commitsTouching( cwd: string, @@ -61,7 +64,11 @@ export function commitsTouching( "HEAD", ...(since === undefined ? [] : [`^${since}`]), "--", - ...paths.map((path) => `:(top)${path}`), + ...paths.map((path) => + path.startsWith("!") + ? `:(top,glob,exclude)${path.slice(1)}` + : `:(top)${path}`, + ), ], { cwd, encoding: "utf8" }, );