versionary 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -68,6 +68,7 @@ The full documentation lives at <https://versionary.dev/>:
68
68
  - [GitHub Actions setup](https://versionary.dev/guide/github-actions)
69
69
  (including tokens and permissions)
70
70
  - [Release workflows](https://versionary.dev/guide/workflows)
71
+ - [Julia registration with Registrator and TagBot](https://versionary.dev/guide/julia)
71
72
  - [Monorepos](https://versionary.dev/guide/monorepos)
72
73
  - [Conventional Commits](https://versionary.dev/guide/conventional-commits)
73
74
  and [Versioning](https://versionary.dev/guide/versioning)
@@ -83,8 +84,9 @@ PR automation, and tags + SCM release metadata (e.g. GitHub Releases).
83
84
 
84
85
  Out of scope (intentional): publishing artifacts to language registries,
85
86
  replacing package-specific publish tooling, and external/user-provided plugin
86
- loading. Use your CI/CD platform for registry publishing, triggered from a
87
- created release/tag.
87
+ loading. Use your CI/CD platform for registry publishing, triggered from release
88
+ outputs or a created release/tag. External release mode supports registration
89
+ before tagging, including [Julia's Registrator and TagBot workflow](https://versionary.dev/guide/julia).
88
90
 
89
91
  ## Contributing
90
92
 
@@ -1,6 +1,7 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { appendFileSync, readFileSync } from "node:fs";
4
+ import { isReleaseCommitMessage } from "../release/commit.js";
4
5
  function getInput(name) {
5
6
  const canonical = `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
6
7
  const underscoreAlias = canonical.replace(/-/g, "_");
@@ -48,10 +49,10 @@ function getRemoteRefSha(cwd, ref) {
48
49
  return null;
49
50
  }
50
51
  }
51
- function hasVersionaryReleaseMarker(cwd, sha) {
52
+ function isReleaseCommit(cwd, sha) {
52
53
  try {
53
54
  const message = runGit(cwd, ["show", "-s", "--format=%B", sha]);
54
- return /^Versionary-Release:\s*true$/imu.test(message);
55
+ return isReleaseCommitMessage(message);
55
56
  }
56
57
  catch {
57
58
  return false;
@@ -94,6 +95,7 @@ function skipRun(action, message) {
94
95
  setOutput("action", action);
95
96
  setOutput("message", message);
96
97
  setOutput("release_created", "false");
98
+ setOutput("release_ready", "false");
97
99
  setOutput("tag_name", "");
98
100
  setOutput("tag_names", "[]");
99
101
  setOutput("release_targets", "[]");
@@ -102,7 +104,37 @@ function skipRun(action, message) {
102
104
  setOutput("branch", "");
103
105
  setOutput("title", "");
104
106
  }
107
+ function runCi() {
108
+ const cwd = getInput("working-directory") || ".";
109
+ const version = getInput("versionary-version") || "0.7.0";
110
+ const raw = execFileSync("npx", ["--yes", `versionary@${version}`, "ci", "--json"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
111
+ let payload;
112
+ try {
113
+ payload = JSON.parse(raw);
114
+ }
115
+ catch {
116
+ throw new Error("Failed parsing Versionary CI JSON output.");
117
+ }
118
+ if (payload?.action !== "ci-evaluated" ||
119
+ typeof payload.runChecks !== "boolean" ||
120
+ typeof payload.isReleasePr !== "boolean") {
121
+ throw new Error("Versionary returned an invalid CI decision.");
122
+ }
123
+ process.stdout.write(`${raw}\n`);
124
+ setOutput("action", payload.action);
125
+ setOutput("message", payload.message ?? "");
126
+ setOutput("run_checks", String(payload.runChecks));
127
+ setOutput("is_release_pr", String(payload.isReleasePr));
128
+ }
105
129
  function main() {
130
+ const command = getInput("command") || "run";
131
+ if (command === "ci") {
132
+ runCi();
133
+ return;
134
+ }
135
+ if (command !== "run") {
136
+ throw new Error(`Unsupported command "${command}". Expected "run" or "ci".`);
137
+ }
106
138
  const token = getInput("token");
107
139
  if (!token) {
108
140
  if (isForkRepository()) {
@@ -150,7 +182,7 @@ function main() {
150
182
  if (remoteSha && remoteSha !== sha) {
151
183
  // Descendant pushes must not turn an otherwise valid release into a
152
184
  // recovery cycle.
153
- const releaseCanPublish = hasVersionaryReleaseMarker(cwd, sha) && isAncestor(cwd, sha, remoteSha);
185
+ const releaseCanPublish = isReleaseCommit(cwd, sha) && isAncestor(cwd, sha, remoteSha);
154
186
  if (!releaseCanPublish) {
155
187
  skipRun("stale-run-skipped", `Skipping stale push run for ${sha.slice(0, 7)}; ` +
156
188
  `${ref} now points to ${remoteSha.slice(0, 7)}.`);
@@ -182,10 +214,11 @@ function main() {
182
214
  ? payload.tagNames.filter((value) => typeof value === "string")
183
215
  : [];
184
216
  const firstTag = tagNames[0] ?? "";
185
- const releaseCreated = payload.releaseCreated === true || tagNames.length > 0 ? "true" : "false";
217
+ const releaseCreated = (payload.releaseCreated ?? tagNames.length > 0) ? "true" : "false";
186
218
  setOutput("action", payload.action ?? "");
187
219
  setOutput("message", payload.message ?? "");
188
220
  setOutput("release_created", releaseCreated);
221
+ setOutput("release_ready", payload.action === "release-ready" ? "true" : "false");
189
222
  setOutput("tag_name", firstTag);
190
223
  setOutput("tag_names", JSON.stringify(tagNames));
191
224
  setOutput("release_targets", JSON.stringify(Array.isArray(payload.releaseTargets) ? payload.releaseTargets : []));
package/dist/ci.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface CiDecision {
2
+ action: "ci-evaluated";
3
+ message: string;
4
+ runChecks: boolean;
5
+ isReleasePr: boolean;
6
+ }
7
+ export declare function evaluateCi(cwd?: string, env?: NodeJS.ProcessEnv): CiDecision;
package/dist/ci.js ADDED
@@ -0,0 +1,53 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { z } from "zod";
3
+ import { loadConfig } from "./config/load-config.js";
4
+ import { resolveSeparateReleaseBranchPrefix } from "./release/cohorts.js";
5
+ const pullRequestSchema = z.object({
6
+ pull_request: z.object({
7
+ head: z.object({
8
+ ref: z.string().min(1),
9
+ repo: z.object({ full_name: z.string().min(1) }),
10
+ }),
11
+ base: z.object({ repo: z.object({ full_name: z.string().min(1) }) }),
12
+ }),
13
+ });
14
+ function readPullRequest(env) {
15
+ if ((env.GITHUB_EVENT_NAME !== "pull_request" &&
16
+ env.GITHUB_EVENT_NAME !== "pull_request_target") ||
17
+ !env.GITHUB_EVENT_PATH) {
18
+ return null;
19
+ }
20
+ try {
21
+ const result = pullRequestSchema.safeParse(JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf8")));
22
+ return result.success ? result.data.pull_request : null;
23
+ }
24
+ catch {
25
+ // Incomplete event context must never suppress checks.
26
+ return null;
27
+ }
28
+ }
29
+ export function evaluateCi(cwd = process.cwd(), env = process.env) {
30
+ const { config } = loadConfig(cwd);
31
+ const request = readPullRequest(env);
32
+ const repository = env.GITHUB_REPOSITORY?.trim().toLowerCase();
33
+ const releaseBranch = resolveSeparateReleaseBranchPrefix(config["release-branch"] ?? "versionary/release");
34
+ const headBranch = request?.head.ref ?? "";
35
+ const separateBranch = config["separate-release-prs"] === true &&
36
+ headBranch.startsWith(`${releaseBranch}-`) &&
37
+ /^[A-Za-z0-9._-]+-[a-f0-9]{12}$/u.test(headBranch.slice(releaseBranch.length + 1));
38
+ const isReleasePr = Boolean(config["review-mode"] !== "direct" &&
39
+ releaseBranch &&
40
+ repository &&
41
+ request?.head.repo.full_name.toLowerCase() === repository &&
42
+ request?.base.repo.full_name.toLowerCase() === repository &&
43
+ (headBranch === releaseBranch || separateBranch));
44
+ const runChecks = config["release-pr-checks"] !== "skip" || !isReleasePr;
45
+ return {
46
+ action: "ci-evaluated",
47
+ message: runChecks
48
+ ? "CI checks are enabled."
49
+ : `Skipping checks for Versionary release PR ${headBranch}.`,
50
+ runChecks,
51
+ isReleasePr,
52
+ };
53
+ }
package/dist/cli/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { execFileSync } from "node:child_process";
3
3
  import path from "node:path";
4
4
  import { parseArgs } from "node:util";
5
+ import { evaluateCi } from "../ci.js";
5
6
  import { writeCommitOverride } from "../config/commit-overrides.js";
6
7
  import { loadConfig } from "../config/load-config.js";
7
8
  import { resolveCommitSha } from "../git/commit-overrides.js";
@@ -9,7 +10,7 @@ import { prependChangelog, renderReleasePlanChangelog, } from "../release/change
9
10
  import { runDirectRelease } from "../release/direct.js";
10
11
  import { createReleasePlan } from "../release/plan.js";
11
12
  import { closeStaleReviewRequestIfExists, isReleaseCommitMessage, openOrUpdateReviewRequest, preparePendingReleasePr, preparePendingSeparateReleasePrs, prepareReleasePr, prepareSeparateReleasePrs, pushReleaseBranch, reconcileSeparateReviewRequests, resolveReleaseHighlights, } from "../release/pr.js";
12
- import { runRelease, runReleaseDetailed } from "../release/release.js";
13
+ import { runRelease, runReleaseDetailed, } from "../release/release.js";
13
14
  import { hasFullyUntaggedPendingRelease, hasReleaseStateChangeAtHead, readPendingReleaseTargets, } from "../release/state.js";
14
15
  import { verifyProject } from "../release/verify-project.js";
15
16
  function recordCommitOverride(command, args) {
@@ -97,6 +98,20 @@ function parseFlags(args) {
97
98
  function emitJson(payload) {
98
99
  process.stdout.write(`${JSON.stringify(payload)}\n`);
99
100
  }
101
+ function printExternalRelease(result, flags) {
102
+ if (flags.json) {
103
+ emitJson({
104
+ action: result.action,
105
+ message: result.message,
106
+ releaseCreated: false,
107
+ tagNames: [],
108
+ releaseTargets: result.releaseTargets,
109
+ });
110
+ }
111
+ else {
112
+ console.log(result.message);
113
+ }
114
+ }
100
115
  function reviewResultPayload(action, message, reviewRequests) {
101
116
  const primary = reviewRequests[0];
102
117
  return {
@@ -140,11 +155,39 @@ async function prepareCurrentSeparateReviewRequests(flags, logger) {
140
155
  }
141
156
  async function recoverPendingReleaseIfNeeded(flags, logger) {
142
157
  const cwd = process.cwd();
158
+ const loaded = loadConfig(cwd);
159
+ if (loaded.config["release-mode"] === "external") {
160
+ const result = await runReleaseDetailed(cwd, {
161
+ logger,
162
+ "dry-run": flags["dry-run"],
163
+ });
164
+ if (result.action === "release-ready" ||
165
+ result.action === "release-waiting") {
166
+ printExternalRelease(result, flags);
167
+ return true;
168
+ }
169
+ if (result.action === "release-dry-run") {
170
+ if (flags.json) {
171
+ emitJson({
172
+ action: result.action,
173
+ message: result.message,
174
+ releaseCreated: false,
175
+ tagNames: result.targets.map((target) => target.tag),
176
+ releaseTargets: result.releaseTargets,
177
+ targets: result.targets,
178
+ });
179
+ }
180
+ else {
181
+ console.log(result.message);
182
+ }
183
+ return true;
184
+ }
185
+ return false;
186
+ }
143
187
  if (!hasFullyUntaggedPendingRelease(cwd)) {
144
188
  return false;
145
189
  }
146
190
  const pendingTargets = readPendingReleaseTargets(cwd);
147
- const loaded = loadConfig(cwd);
148
191
  const releaseBranch = loaded.config["release-branch"] ?? "versionary/release";
149
192
  if (loaded.config["separate-release-prs"]) {
150
193
  const prepared = preparePendingSeparateReleasePrs(cwd, {
@@ -235,6 +278,16 @@ async function main() {
235
278
  const [, , command, ...args] = process.argv;
236
279
  const flags = parseFlags(args);
237
280
  const logger = flags.json ? undefined : console;
281
+ if (command === "ci") {
282
+ const decision = evaluateCi();
283
+ if (flags.json) {
284
+ emitJson(decision);
285
+ }
286
+ else {
287
+ console.log(decision.message);
288
+ }
289
+ return 0;
290
+ }
238
291
  if (!command || command === "run") {
239
292
  if (loadConfig(process.cwd()).config["review-mode"] === "direct") {
240
293
  const release = await runDirectRelease(process.cwd(), {
@@ -276,6 +329,11 @@ async function main() {
276
329
  logger,
277
330
  "dry-run": flags["dry-run"],
278
331
  });
332
+ if (release.action === "release-ready" ||
333
+ release.action === "release-waiting") {
334
+ printExternalRelease(release, flags);
335
+ return 0;
336
+ }
279
337
  if (release.action === "release-skipped") {
280
338
  if (flags.json) {
281
339
  emitJson({
@@ -535,6 +593,7 @@ async function main() {
535
593
  console.log("Commands:");
536
594
  console.log(" run [--json] [--dry-run] Auto-dispatch release PR/update or release publish by context");
537
595
  console.log(" verify Validate config and basic repository shape");
596
+ console.log(" ci [--json] Decide whether CI should run checks");
538
597
  console.log(" plan Print release plan");
539
598
  console.log(' exclude <sha> [--reason "..."] Exclude a commit from release analysis and notes');
540
599
  console.log(' correct <sha> --message "..." [--reason "..."] Correct a commit for release analysis and notes');
@@ -6,6 +6,14 @@ export declare const configSchema: z.ZodObject<{
6
6
  direct: "direct";
7
7
  pr: "pr";
8
8
  }>>;
9
+ "release-mode": z.ZodOptional<z.ZodEnum<{
10
+ external: "external";
11
+ versionary: "versionary";
12
+ }>>;
13
+ "release-pr-checks": z.ZodOptional<z.ZodEnum<{
14
+ run: "run";
15
+ skip: "skip";
16
+ }>>;
9
17
  "version-file": z.ZodOptional<z.ZodString>;
10
18
  "changelog-file": z.ZodOptional<z.ZodString>;
11
19
  "changelog-format": z.ZodOptional<z.ZodEnum<{
@@ -109,6 +109,11 @@ export const configSchema = z
109
109
  $schema: z.string().optional(),
110
110
  version: z.literal(1),
111
111
  "review-mode": z.enum(["direct", "pr"]).optional(),
112
+ "release-mode": z.enum(["versionary", "external"]).optional(),
113
+ "release-pr-checks": z
114
+ .enum(["run", "skip"])
115
+ .optional()
116
+ .describe("Whether CI integration runs checks on Versionary release PRs."),
112
117
  "version-file": z.string().optional(),
113
118
  "changelog-file": z.string().optional(),
114
119
  "changelog-format": z.enum(["markdown-changelog", "r-news"]).optional(),
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { type CiDecision, evaluateCi } from "./ci.js";
1
2
  export { loadConfig } from "./config/load-config.js";
2
3
  export { verifyProject } from "./release/verify-project.js";
3
4
  export { findPluginsByCapability, pluginHasCapability, } from "./scm/capabilities.js";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { evaluateCi } from "./ci.js";
1
2
  export { loadConfig } from "./config/load-config.js";
2
3
  export { verifyProject } from "./release/verify-project.js";
3
4
  export { findPluginsByCapability, pluginHasCapability, } from "./scm/capabilities.js";
@@ -0,0 +1 @@
1
+ export declare function isReleaseCommitMessage(commitMessage: string): boolean;
@@ -0,0 +1,7 @@
1
+ export function isReleaseCommitMessage(commitMessage) {
2
+ if (/^Versionary-Release:\s*true$/imu.test(commitMessage)) {
3
+ return true;
4
+ }
5
+ const subject = commitMessage.split("\n")[0]?.trim() ?? "";
6
+ return /^chore\(release\):\s+(?:(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+)(?:,\s+(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+))*|(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+)\s+\(\+\d+\s+more\))(?:\s+\(#\d+\))?$/u.test(subject);
7
+ }
@@ -3,7 +3,7 @@ import { loadConfig } from "../config/load-config.js";
3
3
  import { createReleasePlan } from "./plan.js";
4
4
  import { buildReleaseTargets, isReleaseCommitMessage, preparePendingReleasePr, prepareReleasePr, } from "./pr.js";
5
5
  import { runReleaseDetailed, } from "./release.js";
6
- import { hasFullyUntaggedPendingRelease, hasReleaseStateChangeAtHead, readPendingReleaseTargets, } from "./state.js";
6
+ import { hasFullyUntaggedPendingRelease, hasReleaseStateChangeAtHead, readExternalReleaseTargets, readPendingReleaseTargets, } from "./state.js";
7
7
  import { releaseTargetHandoff } from "./targets.js";
8
8
  function git(cwd, ...args) {
9
9
  return execFileSync("git", args, {
@@ -44,7 +44,13 @@ export async function runDirectRelease(cwd = process.cwd(), options = {}) {
44
44
  const releaseContext = isReleaseCommitMessage(git(cwd, "log", "-1", "--pretty=%B")) ||
45
45
  hasReleaseStateChangeAtHead(cwd);
46
46
  if (!releaseContext) {
47
- const pending = hasFullyUntaggedPendingRelease(cwd);
47
+ const external = loadConfig(cwd).config["release-mode"] === "external";
48
+ const pending = external
49
+ ? readExternalReleaseTargets(cwd).length > 0
50
+ : hasFullyUntaggedPendingRelease(cwd);
51
+ if (pending && external) {
52
+ return runReleaseDetailed(cwd, options);
53
+ }
48
54
  const plan = pending ? undefined : createReleasePlan(cwd);
49
55
  if (plan && !plan.nextVersion) {
50
56
  return {
@@ -58,7 +64,7 @@ export async function runDirectRelease(cwd = process.cwd(), options = {}) {
58
64
  : readPendingReleaseTargets(cwd);
59
65
  return {
60
66
  action: "release-dry-run",
61
- message: `Dry run: would ${pending ? "recover and publish" : "prepare and publish"} releases ${targets.map((target) => target.tag).join(", ")}`,
67
+ message: `Dry run: would ${external ? "prepare external" : pending ? "recover and publish" : "prepare and publish"} releases ${targets.map((target) => target.tag).join(", ")}`,
62
68
  targets: targets.map(({ tag, version }) => ({ tag, version })),
63
69
  releaseTargets: releaseTargetHandoff(targets, options.logger),
64
70
  };
@@ -118,4 +118,4 @@ export declare function closeStaleReviewRequestIfExists(cwd?: string, options?:
118
118
  number?: number;
119
119
  }>;
120
120
  export declare function pushReleaseBranch(cwd: string, branch: string): void;
121
- export declare function isReleaseCommitMessage(commitMessage: string): boolean;
121
+ export { isReleaseCommitMessage } from "./commit.js";
@@ -1010,10 +1010,4 @@ export function pushReleaseBranch(cwd, branch) {
1010
1010
  throw new Error(redactCredentials(message));
1011
1011
  }
1012
1012
  }
1013
- export function isReleaseCommitMessage(commitMessage) {
1014
- if (/^Versionary-Release:\s*true$/imu.test(commitMessage)) {
1015
- return true;
1016
- }
1017
- const subject = commitMessage.split("\n")[0]?.trim() ?? "";
1018
- return /^chore\(release\):\s+(?:(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+)(?:,\s+(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+))*|(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+)\s+\(\+\d+\s+more\))(?:\s+\(#\d+\))?$/u.test(subject);
1019
- }
1013
+ export { isReleaseCommitMessage } from "./commit.js";
@@ -10,7 +10,7 @@ export declare function runRelease(cwd?: string): Promise<string>;
10
10
  export type RunReleaseResult = {
11
11
  action: "release-skipped";
12
12
  reason: string;
13
- } | {
13
+ } | ExternalReleaseResult | {
14
14
  action: "release-dry-run";
15
15
  message: string;
16
16
  targets: {
@@ -39,6 +39,21 @@ export type RunReleaseResult = {
39
39
  dependencies: string[];
40
40
  }[];
41
41
  };
42
+ export type ExternalReleaseResult = {
43
+ message: string;
44
+ releaseTargets: {
45
+ path: string;
46
+ tag: string;
47
+ version: string;
48
+ dependencies: string[];
49
+ sha: string;
50
+ notes: string;
51
+ }[];
52
+ } & ({
53
+ action: "release-ready";
54
+ } | {
55
+ action: "release-waiting";
56
+ });
42
57
  export interface RunReleaseOptions {
43
58
  logger?: VersionaryPluginContext["logger"];
44
59
  "dry-run"?: boolean;
@@ -8,7 +8,7 @@ import { resolveVersionStrategy } from "../strategy/resolve.js";
8
8
  import { getChangelogDefaults } from "./plan.js";
9
9
  import { isReleaseCommitMessage } from "./pr.js";
10
10
  import { executeIdempotentReleaseTarget } from "./recovery.js";
11
- import { hasReleaseStateChangeAtHead, readPendingReleaseTargets, readRecordedPendingReleaseTargets, } from "./state.js";
11
+ import { hasReleaseStateChangeAtHead, readExternalReleaseTargets, readPendingReleaseTargets, readRecordedPendingReleaseTargets, } from "./state.js";
12
12
  import { releaseTargetHandoff } from "./targets.js";
13
13
  function escapeRegExp(input) {
14
14
  return input.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
@@ -41,7 +41,7 @@ export function extractReleaseNotes(content, version, changelogFormat) {
41
41
  const shortMatch = new RegExp(`^#\\s+.+\\s+${escapeRegExp(shortVersion)}\\s*$`, "u");
42
42
  return fullMatch.test(line) || shortMatch.test(line);
43
43
  })
44
- : lines.findIndex((line) => line.startsWith(`## ${version} -`) ||
44
+ : lines.findIndex((line) => new RegExp(`^##\\s+${escapeRegExp(version)}(?:\\s|$)`, "u").test(line) ||
45
45
  line.startsWith(`## [${version}](`) ||
46
46
  line.startsWith(`# ${shortVersion} -`) ||
47
47
  line.startsWith(`# [${shortVersion}](`) ||
@@ -141,7 +141,56 @@ export async function runRelease(cwd = process.cwd()) {
141
141
  }
142
142
  return result.message;
143
143
  }
144
+ function describeExternalRelease(cwd, config, options) {
145
+ const targets = readExternalReleaseTargets(cwd);
146
+ if (targets.length === 0) {
147
+ return {
148
+ action: "release-skipped",
149
+ reason: "No untagged external release targets found.",
150
+ };
151
+ }
152
+ const head = execFileSync("git", ["rev-parse", "HEAD"], {
153
+ cwd,
154
+ encoding: "utf8",
155
+ }).trim();
156
+ const strategy = resolveVersionStrategy(config);
157
+ const { changelogFile } = getChangelogDefaults({
158
+ ...config,
159
+ defaultChangelogFormat: strategy.getDefaultChangelogFormat?.(),
160
+ });
161
+ const releaseTargets = releaseTargetHandoff(targets, options.logger).map((target) => {
162
+ const file = resolveTargetChangelogFile(config, changelogFile, target.path);
163
+ const content = execFileSync("git", ["show", `${target.sha}:${file}`], {
164
+ cwd,
165
+ encoding: "utf8",
166
+ stdio: ["ignore", "pipe", "pipe"],
167
+ });
168
+ const notes = extractReleaseNotes(content, target.version, resolveTargetChangelogFormat(config, target.path));
169
+ if (!notes) {
170
+ throw new Error(`No release notes for ${target.tag} in ${file} at ${target.sha}. Correct the release PR before handing it to external tooling.`);
171
+ }
172
+ return { ...target, notes };
173
+ });
174
+ const ready = targets.some((target) => target.sha === head);
175
+ if (options["dry-run"]) {
176
+ return {
177
+ action: "release-dry-run",
178
+ message: `Dry run: would hand off external releases ${targets.map((target) => target.tag).join(", ")}`,
179
+ targets: targets.map(({ tag, version }) => ({ tag, version })),
180
+ releaseTargets,
181
+ };
182
+ }
183
+ return {
184
+ action: ready ? "release-ready" : "release-waiting",
185
+ message: `${ready ? "Ready for external release" : "Waiting for external release"}: ${targets.map((target) => target.tag).join(", ")}`,
186
+ releaseTargets,
187
+ };
188
+ }
144
189
  export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
190
+ const loaded = loadConfig(cwd);
191
+ if (loaded.config["release-mode"] === "external") {
192
+ return describeExternalRelease(cwd, loaded.config, options);
193
+ }
145
194
  const commitMessage = getHeadCommitMessage(cwd);
146
195
  if (!isReleaseCommitMessage(commitMessage) &&
147
196
  !hasReleaseStateChangeAtHead(cwd)) {
@@ -150,7 +199,6 @@ export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
150
199
  reason: "No release commit context detected; skipping release stage.",
151
200
  };
152
201
  }
153
- const loaded = loadConfig(cwd);
154
202
  const strategy = resolveVersionStrategy(loaded.config);
155
203
  const { changelogFile } = getChangelogDefaults({
156
204
  ...loaded.config,
@@ -13,6 +13,9 @@ export declare function getPackageStateDirectory(cwd: string): string;
13
13
  export declare function readBaselineSha(cwd?: string): string | null;
14
14
  export declare function readReleaseTargets(cwd?: string): ReleaseTargetState[];
15
15
  export declare function readPendingReleaseTargets(cwd?: string): ReleaseTargetState[];
16
+ export declare function readExternalReleaseTargets(cwd?: string): (ReleaseTargetState & {
17
+ sha: string;
18
+ })[];
16
19
  export declare function readRecordedPendingReleaseTargets(cwd?: string): ReleaseTargetState[];
17
20
  export declare function readPendingReleaseCohorts(cwd?: string): PendingReleaseCohort[];
18
21
  /**
@@ -140,6 +140,61 @@ export function readPendingReleaseTargets(cwd = process.cwd()) {
140
140
  allowPartiallyTagged: true,
141
141
  }).flatMap((cohort) => cohort.targets);
142
142
  }
143
+ export function readExternalReleaseTargets(cwd = process.cwd()) {
144
+ return readPendingReleaseTargets(cwd)
145
+ .filter((target) => !hasLocalTag(cwd, target.tag))
146
+ .map((target) => {
147
+ const sidecar = path.join(getPackageStateDirectory(cwd), packageStateFileName(target.path));
148
+ const statePath = fs.existsSync(sidecar)
149
+ ? sidecar
150
+ : getBaselineStatePath(cwd);
151
+ const relativePath = path.relative(cwd, statePath);
152
+ const identity = (raw) => {
153
+ const state = fs.existsSync(sidecar)
154
+ ? parsePackageStateFile(raw, statePath)
155
+ : parseStateFile(raw, statePath);
156
+ const recorded = "release-target" in state
157
+ ? state["release-target"]
158
+ : state[PENDING_RELEASE_TARGETS_KEY]?.find((entry) => entry.path === target.path);
159
+ return recorded
160
+ ? JSON.stringify([
161
+ state[BASELINE_SHA_KEY],
162
+ recorded.path,
163
+ recorded.version,
164
+ recorded.tag,
165
+ ])
166
+ : null;
167
+ };
168
+ const expected = identity(fs.readFileSync(statePath, "utf8"));
169
+ // Walk the current intent back to its introduction on trunk. Formatting
170
+ // release state after merging must not move an in-flight registration.
171
+ const commits = execFileSync("git", ["log", "--first-parent", "--format=%H", "--", relativePath], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] })
172
+ .trim()
173
+ .split("\n")
174
+ .filter(Boolean);
175
+ let sha = "";
176
+ for (const commit of commits) {
177
+ let raw;
178
+ try {
179
+ raw = execFileSync("git", ["show", `${commit}:${relativePath}`], {
180
+ cwd,
181
+ encoding: "utf8",
182
+ stdio: ["ignore", "pipe", "pipe"],
183
+ });
184
+ }
185
+ catch {
186
+ break;
187
+ }
188
+ if (identity(raw) !== expected)
189
+ break;
190
+ sha = commit;
191
+ }
192
+ if (!sha) {
193
+ throw new Error(`External release ${target.tag} requires committed release state. Merge the release PR before requesting registration.`);
194
+ }
195
+ return { ...target, sha };
196
+ });
197
+ }
143
198
  // Every target the release state records, including cohorts whose tags already
144
199
  // exist. `release` needs these to tell "this repo never recorded a release"
145
200
  // apart from "this release was already published"; only the former may fall
@@ -157,38 +212,58 @@ function collectPendingReleaseCohorts(cwd, options) {
157
212
  const filePath = getBaselineStatePath(cwd);
158
213
  const packageStates = readPackageStates(cwd);
159
214
  const sidecarPaths = new Set(packageStates.map((state) => state.path));
215
+ // A branch can be reused after only part of its original package set changes.
216
+ // The baseline separates completed releases from the next release on it.
160
217
  const byBranch = new Map();
218
+ const addTargets = (branch, baselineSha, targets) => {
219
+ const byBaseline = byBranch.get(branch) ??
220
+ new Map();
221
+ byBaseline.set(baselineSha, [
222
+ ...(byBaseline.get(baselineSha) ?? []),
223
+ ...targets,
224
+ ]);
225
+ byBranch.set(branch, byBaseline);
226
+ };
161
227
  for (const state of packageStates) {
162
- const targets = byBranch.get(state["release-branch"]) ?? [];
163
- targets.push(state["release-target"]);
164
- byBranch.set(state["release-branch"], targets);
228
+ addTargets(state["release-branch"], state[BASELINE_SHA_KEY], [
229
+ state["release-target"],
230
+ ]);
165
231
  }
166
232
  if (fs.existsSync(filePath)) {
167
233
  const parsed = parseStateFile(fs.readFileSync(filePath, "utf8"), filePath);
168
234
  const legacyPending = (parsed[PENDING_RELEASE_TARGETS_KEY] ?? []).filter((target) => !sidecarPaths.has(target.path));
169
235
  if (legacyPending.length > 0) {
170
236
  const branch = loadConfig(cwd).config["release-branch"] ?? "versionary/release";
171
- byBranch.set(branch, [...(byBranch.get(branch) ?? []), ...legacyPending]);
237
+ addTargets(branch, parsed[BASELINE_SHA_KEY], legacyPending);
172
238
  }
173
239
  }
174
240
  const pending = [];
175
- for (const [branch, unsortedTargets] of byBranch) {
176
- const targets = [...unsortedTargets].sort((a, b) => a.path.localeCompare(b.path));
177
- const tagged = targets.filter((target) => hasLocalTag(cwd, target.tag));
178
- if (tagged.length === targets.length && !options.includeFullyTagged) {
179
- continue;
241
+ for (const [branch, byBaseline] of byBranch) {
242
+ const targets = [];
243
+ for (const cohortTargets of byBaseline.values()) {
244
+ const tagged = cohortTargets.filter((target) => hasLocalTag(cwd, target.tag));
245
+ if (tagged.length === cohortTargets.length &&
246
+ !options.includeFullyTagged) {
247
+ continue;
248
+ }
249
+ if (tagged.length > 0 &&
250
+ tagged.length < cohortTargets.length &&
251
+ !options.allowPartiallyTagged) {
252
+ const existingTags = tagged.map((target) => target.tag).join(", ");
253
+ const missingTags = cohortTargets
254
+ .filter((target) => !tagged.includes(target))
255
+ .map((target) => target.tag)
256
+ .join(", ");
257
+ throw new Error(`Pending release cohort on ${branch} is partially tagged and cannot move safely. Existing tags: ${existingTags}. Missing tags: ${missingTags}. Rerun the original release workflow to complete it.`);
258
+ }
259
+ targets.push(...cohortTargets);
180
260
  }
181
- if (tagged.length > 0 &&
182
- tagged.length < targets.length &&
183
- !options.allowPartiallyTagged) {
184
- const existingTags = tagged.map((target) => target.tag).join(", ");
185
- const missingTags = targets
186
- .filter((target) => !tagged.includes(target))
187
- .map((target) => target.tag)
188
- .join(", ");
189
- throw new Error(`Pending release cohort on ${branch} is partially tagged and cannot move safely. Existing tags: ${existingTags}. Missing tags: ${missingTags}. Rerun the original release workflow to complete it.`);
261
+ if (targets.length > 0) {
262
+ pending.push({
263
+ branch,
264
+ targets: targets.sort((a, b) => a.path.localeCompare(b.path)),
265
+ });
190
266
  }
191
- pending.push({ branch, targets });
192
267
  }
193
268
  return pending.sort((a, b) => a.branch.localeCompare(b.branch));
194
269
  }
@@ -1,6 +1,6 @@
1
1
  import type { ReleaseTargetState } from "./state.js";
2
- export interface ReleaseTargetOrder {
3
- ordered: ReleaseTargetState[];
2
+ export interface ReleaseTargetOrder<T extends ReleaseTargetState = ReleaseTargetState> {
3
+ ordered: T[];
4
4
  cyclicPaths: string[];
5
5
  }
6
6
  /**
@@ -13,9 +13,9 @@ export interface ReleaseTargetOrder {
13
13
  * degrading it must not block tagging; callers surface `cyclicPaths` so the
14
14
  * cycle still gets reported.
15
15
  */
16
- export declare function orderReleaseTargets(targets: readonly ReleaseTargetState[]): ReleaseTargetOrder;
17
- export declare function releaseTargetHandoff(targets: readonly ReleaseTargetState[], logger?: {
16
+ export declare function orderReleaseTargets<T extends ReleaseTargetState>(targets: readonly T[]): ReleaseTargetOrder<T>;
17
+ export declare function releaseTargetHandoff<T extends ReleaseTargetState>(targets: readonly T[], logger?: {
18
18
  warn: (message: string) => void;
19
- }): Array<ReleaseTargetState & {
19
+ }): Array<T & {
20
20
  dependencies: string[];
21
21
  }>;
@@ -35,6 +35,8 @@ export interface VersionaryPackage {
35
35
  export interface VersionaryConfig {
36
36
  version: 1;
37
37
  "review-mode"?: "direct" | "pr";
38
+ "release-mode"?: "versionary" | "external";
39
+ "release-pr-checks"?: "run" | "skip";
38
40
  "version-file"?: string;
39
41
  "changelog-file"?: string;
40
42
  "changelog-format"?: VersionaryChangelogFormat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versionary",
3
- "version": "1.7.1",
3
+ "version": "1.9.0",
4
4
  "description": "Automatic release framework based on conventional commits and semantic versioning",
5
5
  "keywords": [
6
6
  "releasing",
@@ -49,6 +49,7 @@
49
49
  "gen:schema": "tsx scripts/generate-schema.ts && biome format --write schemas/config.json",
50
50
  "test": "vitest run",
51
51
  "verify": "tsx src/cli/index.ts verify",
52
+ "ci": "tsx src/cli/index.ts ci",
52
53
  "run": "tsx src/cli/index.ts run",
53
54
  "plan": "tsx src/cli/index.ts plan",
54
55
  "exclude": "tsx src/cli/index.ts exclude",