Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion typescript/.releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
13 changes: 9 additions & 4 deletions typescript/PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 46 additions & 2 deletions typescript/scripts/release-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
31 changes: 31 additions & 0 deletions typescript/scripts/release-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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" };

Expand Down
23 changes: 15 additions & 8 deletions typescript/scripts/release-paths.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Commit extends ReleaseCommit>(
cwd: string,
Expand All @@ -61,7 +64,11 @@ export function commitsTouching<Commit extends ReleaseCommit>(
"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" },
);
Expand Down
Loading