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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- npm publishes only when plugin or catalog files change since the last tag — CI, tests, and scripts-only merges skip a release.

## [0.6.1] - 2026-08-28

### Added
Expand Down
44 changes: 30 additions & 14 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"catalog:ci": "bun run scripts/catalog-sync-ci.ts"
},
"devDependencies": {
"@semantic-release/commit-analyzer": "13.0.1",
"@semantic-release/exec": "7.1.0",
"@semantic-release/github": "12.0.9",
"@semantic-release/npm": "13.1.5",
"@semantic-release/release-notes-generator": "14.1.1",
Expand Down
9 changes: 8 additions & 1 deletion release.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module.exports = {
branches: ["main"],
plugins: [
"@semantic-release/commit-analyzer",
// Path-gated: prints major|minor|patch only when src/plugin/catalog files
// changed since the previous v* tag. Empty output skips npm + GitHub.
[
"@semantic-release/exec",
{
analyzeCommitsCmd: "bun scripts/analyze-release-scope.ts",
},
],
"./scripts/semantic-release-catalog-notes.cjs",
"@semantic-release/release-notes-generator",
"./scripts/semantic-release-changelog.cjs",
Expand Down
79 changes: 79 additions & 0 deletions scripts/analyze-release-scope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bun
// Path-gated releases (workit AR-16): a releasable commit counts only when it
// touches package payload. CI/docs/tests/scripts-only merges cut no npm publish.
import { execFileSync } from "node:child_process";
import { resolve } from "node:path";

const PRODUCT_FILES = new Set([
"plugin.ts",
"index.ts",
"models.json",
"manifest.json",
"_version.txt",
]);

export function isProductPath(file: string): boolean {
return PRODUCT_FILES.has(file) || file.startsWith("src/");
}

const g = (root: string, args: string[]): string =>
execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim();

const SEMVER_TAG = /^v\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;

export function latestTag(root = process.cwd()): string | null {
const out = g(root, ["tag", "--list", "v*", "--sort=-v:refname"])
.split("\n")
.map((l) => l.trim())
.filter((l) => SEMVER_TAG.test(l));
return out[0] ?? null;
}

type Level = "major" | "minor" | "patch";
const LEVEL_RANK: Record<Level, number> = { patch: 1, minor: 2, major: 3 };
const TYPE_LEVEL: Record<string, Level> = { fix: "patch", perf: "patch", feat: "minor" };

const subjectLevel = (commit: string): Level | null => {
const firstLine = commit.split("\n")[0] ?? "";
const m = /^(?:fix|perf|feat)(?:\([^)]*\))?!?:/.exec(firstLine);
if (!m) return null;
if (m[0].includes("!")) return "major";
const body = commit.split("\n").slice(1).join("\n");
const type = m[0].replace(/\(.*$/, "").replace(/!$/, "").replace(/:$/, "");
return /BREAKING[- ]CHANGE:/.test(body) ? "major" : (TYPE_LEVEL[type] ?? null);
};

const commitsSince = (root: string, from: string): { message: string; files: string[] }[] => {
const hashes = g(root, ["log", "--reverse", "--format=%H", `${from}..HEAD`])
.split("\n")
.filter(Boolean);
return hashes.map((h) => ({
message: g(root, ["show", "-s", "--format=%B", h]),
files: g(root, ["diff-tree", "--no-commit-id", "--name-only", "-r", "-m", "--root", "-z", h])
.split("\0")
.filter(Boolean),
}));
};

export function analyzeReleaseScope(root = process.cwd()): { level: Level | null } {
const from = latestTag(root);
if (from === null) return { level: "minor" };
const levels: Level[] = [];
for (const { message, files } of commitsSince(root, from)) {
if (!files.some(isProductPath)) continue;
const lvl = subjectLevel(message);
if (lvl) levels.push(lvl);
}
if (levels.length === 0) return { level: null };
const level = levels.reduce<Level>(
(best, l) => (LEVEL_RANK[l] > LEVEL_RANK[best] ? l : best),
"patch",
);
return { level };
}

if (import.meta.main) {
const root = process.argv[2] ? resolve(process.argv[2]) : process.cwd();
const { level } = analyzeReleaseScope(root);
if (level) process.stdout.write(`${level}\n`);
}
Loading