versionary 1.8.0 → 1.10.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.
@@ -99,12 +99,43 @@ function skipRun(action, message) {
99
99
  setOutput("tag_name", "");
100
100
  setOutput("tag_names", "[]");
101
101
  setOutput("release_targets", "[]");
102
+ setOutput("external_release_targets", "[]");
102
103
  setOutput("review_url", "");
103
104
  setOutput("review_requests", "[]");
104
105
  setOutput("branch", "");
105
106
  setOutput("title", "");
106
107
  }
108
+ function runCi() {
109
+ const cwd = getInput("working-directory") || ".";
110
+ const version = getInput("versionary-version") || "0.7.0";
111
+ const raw = execFileSync("npx", ["--yes", `versionary@${version}`, "ci", "--json"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
112
+ let payload;
113
+ try {
114
+ payload = JSON.parse(raw);
115
+ }
116
+ catch {
117
+ throw new Error("Failed parsing Versionary CI JSON output.");
118
+ }
119
+ if (payload?.action !== "ci-evaluated" ||
120
+ typeof payload.runChecks !== "boolean" ||
121
+ typeof payload.isReleasePr !== "boolean") {
122
+ throw new Error("Versionary returned an invalid CI decision.");
123
+ }
124
+ process.stdout.write(`${raw}\n`);
125
+ setOutput("action", payload.action);
126
+ setOutput("message", payload.message ?? "");
127
+ setOutput("run_checks", String(payload.runChecks));
128
+ setOutput("is_release_pr", String(payload.isReleasePr));
129
+ }
107
130
  function main() {
131
+ const command = getInput("command") || "run";
132
+ if (command === "ci") {
133
+ runCi();
134
+ return;
135
+ }
136
+ if (command !== "run") {
137
+ throw new Error(`Unsupported command "${command}". Expected "run" or "ci".`);
138
+ }
108
139
  const token = getInput("token");
109
140
  if (!token) {
110
141
  if (isForkRepository()) {
@@ -188,10 +219,18 @@ function main() {
188
219
  setOutput("action", payload.action ?? "");
189
220
  setOutput("message", payload.message ?? "");
190
221
  setOutput("release_created", releaseCreated);
191
- setOutput("release_ready", payload.action === "release-ready" ? "true" : "false");
222
+ setOutput("release_ready", (payload.releaseReady ?? payload.action === "release-ready")
223
+ ? "true"
224
+ : "false");
192
225
  setOutput("tag_name", firstTag);
193
226
  setOutput("tag_names", JSON.stringify(tagNames));
194
227
  setOutput("release_targets", JSON.stringify(Array.isArray(payload.releaseTargets) ? payload.releaseTargets : []));
228
+ setOutput("external_release_targets", JSON.stringify(Array.isArray(payload.externalReleaseTargets)
229
+ ? payload.externalReleaseTargets
230
+ : payload.action === "release-ready" ||
231
+ payload.action === "release-waiting"
232
+ ? (payload.releaseTargets ?? [])
233
+ : []));
195
234
  setOutput("review_url", payload.reviewUrl ?? "");
196
235
  setOutput("review_requests", JSON.stringify(Array.isArray(payload.reviewRequests) ? payload.reviewRequests : []));
197
236
  setOutput("branch", payload.branch ?? "");
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,14 +2,16 @@
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";
8
9
  import { prependChangelog, renderReleasePlanChangelog, } from "../release/changelog.js";
9
10
  import { runDirectRelease } from "../release/direct.js";
11
+ import { hasExternalReleaseMode } from "../release/mode.js";
10
12
  import { createReleasePlan } from "../release/plan.js";
11
13
  import { closeStaleReviewRequestIfExists, isReleaseCommitMessage, openOrUpdateReviewRequest, preparePendingReleasePr, preparePendingSeparateReleasePrs, prepareReleasePr, prepareSeparateReleasePrs, pushReleaseBranch, reconcileSeparateReviewRequests, resolveReleaseHighlights, } from "../release/pr.js";
12
- import { runRelease, runReleaseDetailed, } from "../release/release.js";
14
+ import { describeExternalRelease, runRelease, runReleaseDetailed, } from "../release/release.js";
13
15
  import { hasFullyUntaggedPendingRelease, hasReleaseStateChangeAtHead, readPendingReleaseTargets, } from "../release/state.js";
14
16
  import { verifyProject } from "../release/verify-project.js";
15
17
  function recordCommitOverride(command, args) {
@@ -94,7 +96,18 @@ function parseFlags(args) {
94
96
  "dry-run": args.includes("--dry-run"),
95
97
  };
96
98
  }
99
+ let externalAtStart;
97
100
  function emitJson(payload) {
101
+ if (payload.action !== "ci-evaluated" &&
102
+ externalAtStart &&
103
+ !payload.externalReleaseTargets) {
104
+ payload = {
105
+ ...payload,
106
+ externalReleaseTargets: externalAtStart.releaseTargets,
107
+ releaseReady: payload.action === "release-ready" &&
108
+ externalAtStart.action === "release-ready",
109
+ };
110
+ }
98
111
  process.stdout.write(`${JSON.stringify(payload)}\n`);
99
112
  }
100
113
  function printExternalRelease(result, flags) {
@@ -105,6 +118,8 @@ function printExternalRelease(result, flags) {
105
118
  releaseCreated: false,
106
119
  tagNames: [],
107
120
  releaseTargets: result.releaseTargets,
121
+ externalReleaseTargets: result.releaseTargets,
122
+ releaseReady: result.action === "release-ready",
108
123
  });
109
124
  }
110
125
  else {
@@ -155,7 +170,9 @@ async function prepareCurrentSeparateReviewRequests(flags, logger) {
155
170
  async function recoverPendingReleaseIfNeeded(flags, logger) {
156
171
  const cwd = process.cwd();
157
172
  const loaded = loadConfig(cwd);
158
- if (loaded.config["release-mode"] === "external") {
173
+ if (hasExternalReleaseMode(loaded.config) &&
174
+ !hasFullyUntaggedPendingRelease(cwd) &&
175
+ !createReleasePlan(cwd).nextVersion) {
159
176
  const result = await runReleaseDetailed(cwd, {
160
177
  logger,
161
178
  "dry-run": flags["dry-run"],
@@ -276,7 +293,25 @@ async function recoverPendingReleaseIfNeeded(flags, logger) {
276
293
  async function main() {
277
294
  const [, , command, ...args] = process.argv;
278
295
  const flags = parseFlags(args);
296
+ if ((command === "run" || command === "pr") &&
297
+ hasExternalReleaseMode(loadConfig(process.cwd()).config)) {
298
+ // Preparing a PR can check out its branch; only hand off already-merged intent.
299
+ const external = describeExternalRelease(process.cwd(), loadConfig(process.cwd()).config, {});
300
+ if (external.action === "release-ready" ||
301
+ external.action === "release-waiting")
302
+ externalAtStart = external;
303
+ }
279
304
  const logger = flags.json ? undefined : console;
305
+ if (command === "ci") {
306
+ const decision = evaluateCi();
307
+ if (flags.json) {
308
+ emitJson(decision);
309
+ }
310
+ else {
311
+ console.log(decision.message);
312
+ }
313
+ return 0;
314
+ }
280
315
  if (!command || command === "run") {
281
316
  if (loadConfig(process.cwd()).config["review-mode"] === "direct") {
282
317
  const release = await runDirectRelease(process.cwd(), {
@@ -287,6 +322,10 @@ async function main() {
287
322
  if (flags.json) {
288
323
  emitJson({
289
324
  action: release.action,
325
+ externalReleaseTargets: "externalReleaseTargets" in release
326
+ ? release.externalReleaseTargets
327
+ : undefined,
328
+ releaseReady: "releaseReady" in release ? release.releaseReady : undefined,
290
329
  message,
291
330
  releaseCreated: release.action === "release-published" &&
292
331
  release.releases.length > 0,
@@ -341,6 +380,8 @@ async function main() {
341
380
  if (flags.json) {
342
381
  emitJson({
343
382
  action: "release-dry-run",
383
+ externalReleaseTargets: release.externalReleaseTargets,
384
+ releaseReady: false,
344
385
  message: release.message,
345
386
  releaseCreated: false,
346
387
  tagNames: release.targets.map((target) => target.tag),
@@ -361,6 +402,8 @@ async function main() {
361
402
  const primary = reviewRequests[0];
362
403
  emitJson({
363
404
  action: "release-published",
405
+ externalReleaseTargets: release.externalReleaseTargets,
406
+ releaseReady: release.releaseReady,
364
407
  message: release.message,
365
408
  releaseCreated: release.releases.length > 0,
366
409
  tagNames: release.releases.map((target) => target.tag),
@@ -582,6 +625,7 @@ async function main() {
582
625
  console.log("Commands:");
583
626
  console.log(" run [--json] [--dry-run] Auto-dispatch release PR/update or release publish by context");
584
627
  console.log(" verify Validate config and basic repository shape");
628
+ console.log(" ci [--json] Decide whether CI should run checks");
585
629
  console.log(" plan Print release plan");
586
630
  console.log(' exclude <sha> [--reason "..."] Exclude a commit from release analysis and notes');
587
631
  console.log(' correct <sha> --message "..." [--reason "..."] Correct a commit for release analysis and notes');
@@ -10,6 +10,10 @@ export declare const configSchema: z.ZodObject<{
10
10
  external: "external";
11
11
  versionary: "versionary";
12
12
  }>>;
13
+ "release-pr-checks": z.ZodOptional<z.ZodEnum<{
14
+ run: "run";
15
+ skip: "skip";
16
+ }>>;
13
17
  "version-file": z.ZodOptional<z.ZodString>;
14
18
  "changelog-file": z.ZodOptional<z.ZodString>;
15
19
  "changelog-format": z.ZodOptional<z.ZodEnum<{
@@ -46,6 +50,10 @@ export declare const configSchema: z.ZodObject<{
46
50
  packages: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
47
51
  "release-type": z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
48
52
  "package-name": z.ZodOptional<z.ZodString>;
53
+ "release-mode": z.ZodOptional<z.ZodEnum<{
54
+ external: "external";
55
+ versionary: "versionary";
56
+ }>>;
49
57
  "changelog-file": z.ZodOptional<z.ZodString>;
50
58
  "changelog-format": z.ZodOptional<z.ZodEnum<{
51
59
  "markdown-changelog": "markdown-changelog";
@@ -83,6 +83,7 @@ const packageSchema = z
83
83
  .union([z.string().min(1), z.array(z.string().min(1)).min(1)])
84
84
  .optional(),
85
85
  "package-name": z.string().optional(),
86
+ "release-mode": z.enum(["versionary", "external"]).optional(),
86
87
  "changelog-file": z.string().optional(),
87
88
  "changelog-format": z.enum(["markdown-changelog", "r-news"]).optional(),
88
89
  "release-draft": z.boolean().optional(),
@@ -110,6 +111,10 @@ export const configSchema = z
110
111
  version: z.literal(1),
111
112
  "review-mode": z.enum(["direct", "pr"]).optional(),
112
113
  "release-mode": z.enum(["versionary", "external"]).optional(),
114
+ "release-pr-checks": z
115
+ .enum(["run", "skip"])
116
+ .optional()
117
+ .describe("Whether CI integration runs checks on Versionary release PRs."),
113
118
  "version-file": z.string().optional(),
114
119
  "changelog-file": z.string().optional(),
115
120
  "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";
@@ -1,5 +1,6 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { loadConfig } from "../config/load-config.js";
3
+ import { hasExternalReleaseMode } from "./mode.js";
3
4
  import { createReleasePlan } from "./plan.js";
4
5
  import { buildReleaseTargets, isReleaseCommitMessage, preparePendingReleasePr, prepareReleasePr, } from "./pr.js";
5
6
  import { runReleaseDetailed, } from "./release.js";
@@ -44,11 +45,12 @@ export async function runDirectRelease(cwd = process.cwd(), options = {}) {
44
45
  const releaseContext = isReleaseCommitMessage(git(cwd, "log", "-1", "--pretty=%B")) ||
45
46
  hasReleaseStateChangeAtHead(cwd);
46
47
  if (!releaseContext) {
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) {
48
+ const external = hasExternalReleaseMode(loadConfig(cwd).config);
49
+ const pending = hasFullyUntaggedPendingRelease(cwd);
50
+ if (external &&
51
+ !pending &&
52
+ readExternalReleaseTargets(cwd).length > 0 &&
53
+ !createReleasePlan(cwd).nextVersion) {
52
54
  return runReleaseDetailed(cwd, options);
53
55
  }
54
56
  const plan = pending ? undefined : createReleasePlan(cwd);
@@ -0,0 +1,4 @@
1
+ import type { VersionaryConfig } from "../types/config.js";
2
+ export declare function resolveTargetReleaseMode(config: VersionaryConfig, packagePath: string): "versionary" | "external";
3
+ export declare function hasExternalReleaseMode(config: VersionaryConfig): boolean;
4
+ export declare function hasManagedReleaseMode(config: VersionaryConfig): boolean;
@@ -0,0 +1,15 @@
1
+ export function resolveTargetReleaseMode(config, packagePath) {
2
+ return (config.packages?.[packagePath]?.["release-mode"] ??
3
+ config["release-mode"] ??
4
+ "versionary");
5
+ }
6
+ export function hasExternalReleaseMode(config) {
7
+ return (Object.keys(config.packages ?? {}).length > 0
8
+ ? Object.keys(config.packages ?? {})
9
+ : ["."]).some((packagePath) => resolveTargetReleaseMode(config, packagePath) === "external");
10
+ }
11
+ export function hasManagedReleaseMode(config) {
12
+ return (Object.keys(config.packages ?? {}).length > 0
13
+ ? Object.keys(config.packages ?? {})
14
+ : ["."]).some((packagePath) => resolveTargetReleaseMode(config, packagePath) === "versionary");
15
+ }
@@ -7,7 +7,7 @@ import { resolvePackageStrategyContext } from "../strategy/package-context.js";
7
7
  import { resolveVersionStrategy } from "../strategy/resolve.js";
8
8
  import { releaseTypeBetween, resolveReleaseAsOverride } from "./release-as.js";
9
9
  import { bumpVersion, maxReleaseType } from "./semver.js";
10
- import { readBaselineSha, readReleaseTargets } from "./state.js";
10
+ import { readBaselineSha, readExternalReleaseWaitPaths, readReleaseTargets, } from "./state.js";
11
11
  function getMode(configMode) {
12
12
  return configMode ?? "independent";
13
13
  }
@@ -43,6 +43,7 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
43
43
  const loaded = loadConfig(cwd);
44
44
  const overrides = resolveCommitOverrides(cwd, options.commitOverrides ?? loaded.config["commit-overrides"] ?? {});
45
45
  const originalCommits = new Map();
46
+ const originalCommitPaths = new Map();
46
47
  // Keep the original revert relationships even when either commit is excluded.
47
48
  const effectiveCommits = (commits) => applyCommitOverrides(applyRevertSuppression(commits), overrides);
48
49
  const strategy = resolveVersionStrategy(loaded.config);
@@ -64,6 +65,11 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
64
65
  const allowStableMajor = resolveAllowStableMajor(loaded.config);
65
66
  const allowStableMajorForPath = (packagePath) => resolveAllowStableMajor(loaded.config, loaded.config.packages?.[packagePath]);
66
67
  const monorepoMode = getMode(loaded.config["monorepo-mode"]);
68
+ const waitingPaths = readExternalReleaseWaitPaths(cwd);
69
+ if (monorepoMode === "fixed" && waitingPaths.size > 0) {
70
+ for (const pkg of normalizedPackages)
71
+ waitingPaths.add(pkg.path);
72
+ }
67
73
  const buildPackagePlan = (pkg) => {
68
74
  const packageContext = resolvePackageStrategyContext(loaded.config, pkg.path, pkg.config);
69
75
  const currentVersionFile = path.join(cwd, packageContext.versionFile);
@@ -79,7 +85,10 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
79
85
  ];
80
86
  const isImplicitRoot = !hasPackages && pkg.path === ".";
81
87
  let parsedCommits;
82
- if (isImplicitRoot && excludePaths.length === 0) {
88
+ if (waitingPaths.has(pkg.path)) {
89
+ parsedCommits = [];
90
+ }
91
+ else if (isImplicitRoot && excludePaths.length === 0) {
83
92
  parsedCommits = getParsedCommitsSinceLastTag(cwd, baselineSha);
84
93
  }
85
94
  else {
@@ -89,6 +98,9 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
89
98
  }
90
99
  for (const commit of parsedCommits) {
91
100
  originalCommits.set(commit.hash, commit);
101
+ const paths = originalCommitPaths.get(commit.hash) ?? new Set();
102
+ paths.add(pkg.path);
103
+ originalCommitPaths.set(commit.hash, paths);
92
104
  overrides.get(commit.hash)?.report.packages.push(pkg.path);
93
105
  }
94
106
  parsedCommits = effectiveCommits(parsedCommits);
@@ -247,6 +259,28 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
247
259
  dependenciesByPath.set(dependentPath, new Set([pkgPlan.path]));
248
260
  }
249
261
  }
262
+ // A dependent cannot publish against a sibling version still awaiting acceptance.
263
+ for (let iteration = 0; iteration < workingPlans.length; iteration += 1) {
264
+ for (const [dependent, dependencies] of dependenciesByPath) {
265
+ if ([...dependencies].some((dependency) => waitingPaths.has(dependency)))
266
+ waitingPaths.add(dependent);
267
+ }
268
+ }
269
+ for (const pkg of workingPlans) {
270
+ if (waitingPaths.has(pkg.path)) {
271
+ pkg.nextVersion = null;
272
+ pkg.releaseType = null;
273
+ pkg.commits = [];
274
+ pkg.parsedCommits = [];
275
+ const context = strategyContextByPath.get(pkg.path);
276
+ if (context)
277
+ context.nextVersion = null;
278
+ }
279
+ }
280
+ for (const [hash, paths] of originalCommitPaths) {
281
+ if ([...paths].every((packagePath) => waitingPaths.has(packagePath)))
282
+ originalCommits.delete(hash);
283
+ }
250
284
  /**
251
285
  * Every package reachable by following dependency edges down from a
252
286
  * publishable package that is currently releasing. Staleness matters
@@ -331,7 +365,7 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
331
365
  const impacted = strategyGroup.strategy.propagateDependentPatchImpacts?.(cwd, strategyGroup.packages) ?? [];
332
366
  for (const impactedPath of impacted) {
333
367
  const target = workingPlanByPath.get(impactedPath);
334
- if (!target || target.nextVersion) {
368
+ if (!target || target.nextVersion || waitingPaths.has(target.path)) {
335
369
  continue;
336
370
  }
337
371
  forcePatchBump(target, "dependency-propagation");
@@ -344,7 +378,9 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
344
378
  // from the change existing, not from how it was labeled.
345
379
  const reachableDependencies = collectReleasingDependencyClosure();
346
380
  for (const candidate of workingPlans) {
347
- if (candidate.nextVersion || candidate.commits.length === 0) {
381
+ if (candidate.nextVersion ||
382
+ candidate.commits.length === 0 ||
383
+ waitingPaths.has(candidate.path)) {
348
384
  continue;
349
385
  }
350
386
  if (!reachableDependencies.has(candidate.path)) {
@@ -371,6 +407,8 @@ export function createReleasePlan(cwd = process.cwd(), options = {}) {
371
407
  }
372
408
  }
373
409
  const adjustedPackages = propagatedPackages.map((pkgPlan) => {
410
+ if (waitingPaths.has(pkgPlan.path))
411
+ return pkgPlan;
374
412
  if (pkgPlan.bumpReason === "release-as") {
375
413
  // An explicit override pins this package's version; do not let a
376
414
  // followed source recompute it out from under the requested version.
@@ -12,7 +12,7 @@ import { applyConfiguredArtifactRules } from "./artifact-rules.js";
12
12
  import { extractUnreleasedNotes, prependChangelog, renderReleaseNotesSection, renderReleasePlanChangelog, renderReviewRequestFooter, renderRNewsReleaseNotes, } from "./changelog.js";
13
13
  import { buildInitialReleaseCohorts, resolveSeparateReleaseBranch, resolveSeparateReleaseBranchPrefix, stabilizeReleaseCohorts, } from "./cohorts.js";
14
14
  import { createReleasePlan, getChangelogDefaults, resolvePackageDependencies, } from "./plan.js";
15
- import { hasFullyUntaggedPendingRelease, readPendingReleaseCohorts, readPendingReleaseTargets, writeBaselineSha, writePackageReleaseState, } from "./state.js";
15
+ import { hasFullyUntaggedPendingRelease, readPendingReleaseCohorts, writeBaselineSha, writePackageReleaseState, } from "./state.js";
16
16
  const SAFE_DIRTY_FILES = new Set([
17
17
  "pnpm-lock.yaml",
18
18
  "package-lock.json",
@@ -234,7 +234,7 @@ export function renderPendingReleaseReviewRequestBody(targets) {
234
234
  * changelog changes were already reviewed in the original release PR.
235
235
  */
236
236
  export function preparePendingReleasePr(cwd = process.cwd(), options = {}) {
237
- const targets = readPendingReleaseTargets(cwd);
237
+ const targets = readPendingReleaseCohorts(cwd).flatMap((cohort) => cohort.targets);
238
238
  if (!hasFullyUntaggedPendingRelease(cwd)) {
239
239
  throw new Error("No unpublished pending release found to recover.");
240
240
  }
@@ -7,7 +7,7 @@ export declare function extractReleaseNotes(content: string, version: string, ch
7
7
  export declare function extractClosingReferencesFromNotes(notes: string): number[];
8
8
  export declare function resolveTargetChangelogFile(config: VersionaryConfig, rootChangelogFile: string, targetPath: string): string;
9
9
  export declare function runRelease(cwd?: string): Promise<string>;
10
- export type RunReleaseResult = {
10
+ export type RunReleaseResult = ({
11
11
  action: "release-skipped";
12
12
  reason: string;
13
13
  } | ExternalReleaseResult | {
@@ -38,6 +38,9 @@ export type RunReleaseResult = {
38
38
  version: string;
39
39
  dependencies: string[];
40
40
  }[];
41
+ }) & {
42
+ releaseReady?: boolean;
43
+ externalReleaseTargets?: ExternalReleaseResult["releaseTargets"];
41
44
  };
42
45
  export type ExternalReleaseResult = {
43
46
  message: string;
@@ -54,6 +57,7 @@ export type ExternalReleaseResult = {
54
57
  } | {
55
58
  action: "release-waiting";
56
59
  });
60
+ export declare function describeExternalRelease(cwd: string, config: VersionaryConfig, options: RunReleaseOptions): RunReleaseResult;
57
61
  export interface RunReleaseOptions {
58
62
  logger?: VersionaryPluginContext["logger"];
59
63
  "dry-run"?: boolean;
@@ -5,10 +5,11 @@ import { loadConfig } from "../config/load-config.js";
5
5
  import { getScmClient } from "../scm/client.js";
6
6
  import { resolvePackageStrategyContext, resolveReleaseName, } from "../strategy/package-context.js";
7
7
  import { resolveVersionStrategy } from "../strategy/resolve.js";
8
+ import { hasManagedReleaseMode, resolveTargetReleaseMode } from "./mode.js";
8
9
  import { getChangelogDefaults } from "./plan.js";
9
10
  import { isReleaseCommitMessage } from "./pr.js";
10
11
  import { executeIdempotentReleaseTarget } from "./recovery.js";
11
- import { hasReleaseStateChangeAtHead, readExternalReleaseTargets, readPendingReleaseTargets, readRecordedPendingReleaseTargets, } from "./state.js";
12
+ import { hasLocalTag, hasReleaseStateChangeAtHead, readExternalReleaseTargets, readExternalReleaseWaitPaths, readPendingReleaseTargets, readRecordedPendingReleaseTargets, } from "./state.js";
12
13
  import { releaseTargetHandoff } from "./targets.js";
13
14
  function escapeRegExp(input) {
14
15
  return input.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
@@ -141,7 +142,7 @@ export async function runRelease(cwd = process.cwd()) {
141
142
  }
142
143
  return result.message;
143
144
  }
144
- function describeExternalRelease(cwd, config, options) {
145
+ export function describeExternalRelease(cwd, config, options) {
145
146
  const targets = readExternalReleaseTargets(cwd);
146
147
  if (targets.length === 0) {
147
148
  return {
@@ -188,9 +189,26 @@ function describeExternalRelease(cwd, config, options) {
188
189
  }
189
190
  export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
190
191
  const loaded = loadConfig(cwd);
191
- if (loaded.config["release-mode"] === "external") {
192
- return describeExternalRelease(cwd, loaded.config, options);
193
- }
192
+ const external = describeExternalRelease(cwd, loaded.config, options);
193
+ if (!hasManagedReleaseMode(loaded.config))
194
+ return external;
195
+ const waitingPaths = readExternalReleaseWaitPaths(cwd);
196
+ const managed = (target) => resolveTargetReleaseMode(loaded.config, target.path) === "versionary" &&
197
+ !waitingPaths.has(target.path);
198
+ const pendingManaged = readPendingReleaseTargets(cwd).filter((target) => managed(target) && !hasLocalTag(cwd, target.tag));
199
+ if (pendingManaged.length === 0 && external.action !== "release-skipped")
200
+ return external;
201
+ const externalHandoff = external.action === "release-ready" || external.action === "release-waiting"
202
+ ? {
203
+ externalReleaseTargets: external.releaseTargets,
204
+ releaseReady: external.action === "release-ready",
205
+ }
206
+ : external.action === "release-dry-run"
207
+ ? {
208
+ externalReleaseTargets: external.releaseTargets,
209
+ releaseReady: false,
210
+ }
211
+ : {};
194
212
  const commitMessage = getHeadCommitMessage(cwd);
195
213
  if (!isReleaseCommitMessage(commitMessage) &&
196
214
  !hasReleaseStateChangeAtHead(cwd)) {
@@ -205,7 +223,7 @@ export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
205
223
  defaultChangelogFormat: strategy.getDefaultChangelogFormat?.(),
206
224
  });
207
225
  const referenceCommentMode = loaded.config["release-reference-comments"] ?? "off";
208
- const releaseTargets = readPendingReleaseTargets(cwd);
226
+ const releaseTargets = readPendingReleaseTargets(cwd).filter(managed);
209
227
  if (loaded.config["separate-release-prs"] && releaseTargets.length === 0) {
210
228
  return {
211
229
  action: "release-skipped",
@@ -218,7 +236,14 @@ export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
218
236
  // tagging the root package.
219
237
  const recordedTargets = releaseTargets.length > 0
220
238
  ? releaseTargets
221
- : readRecordedPendingReleaseTargets(cwd);
239
+ : readRecordedPendingReleaseTargets(cwd).filter(managed);
240
+ if (recordedTargets.length === 0 &&
241
+ readRecordedPendingReleaseTargets(cwd).length > 0) {
242
+ return {
243
+ action: "release-skipped",
244
+ reason: "No Versionary-managed release targets found.",
245
+ };
246
+ }
222
247
  const version = recordedTargets.length === 0
223
248
  ? strategy.readVersion(cwd, loaded.config)
224
249
  : undefined;
@@ -241,6 +266,7 @@ export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
241
266
  version: target.version,
242
267
  })),
243
268
  releaseTargets: releaseTargetPlan,
269
+ ...externalHandoff,
244
270
  message: `Dry run: would publish releases ${targetList.join(", ")}`,
245
271
  };
246
272
  }
@@ -298,6 +324,7 @@ export async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
298
324
  const published = releases.map((outcome) => `${outcome.tag}: ${outcome.url} (tag=${outcome.tagStatus}, metadata=${outcome.metadataStatus})`);
299
325
  return {
300
326
  action: "release-published",
327
+ ...externalHandoff,
301
328
  releases,
302
329
  releaseTargets: releaseTargetPlan,
303
330
  message: `Published releases ${published.join(", ")}`,
@@ -13,11 +13,14 @@ 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 readPendingExternalReleaseTargets(cwd?: string): ReleaseTargetState[];
17
+ export declare function readExternalReleaseWaitPaths(cwd?: string): Set<string>;
16
18
  export declare function readExternalReleaseTargets(cwd?: string): (ReleaseTargetState & {
17
19
  sha: string;
18
20
  })[];
19
21
  export declare function readRecordedPendingReleaseTargets(cwd?: string): ReleaseTargetState[];
20
22
  export declare function readPendingReleaseCohorts(cwd?: string): PendingReleaseCohort[];
23
+ export declare function hasLocalTag(cwd: string, tag: string): boolean;
21
24
  /**
22
25
  * Pending targets remain in the manifest after publishing, so the tag set is
23
26
  * the durable evidence that the pending release actually completed.
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { loadConfig } from "../config/load-config.js";
6
+ import { resolveTargetReleaseMode } from "./mode.js";
6
7
  const MANIFEST_VERSION_KEY = "manifest-version";
7
8
  const BASELINE_SHA_KEY = "baseline-sha";
8
9
  const RELEASE_TARGETS_KEY = "release-targets";
@@ -140,10 +141,26 @@ export function readPendingReleaseTargets(cwd = process.cwd()) {
140
141
  allowPartiallyTagged: true,
141
142
  }).flatMap((cohort) => cohort.targets);
142
143
  }
144
+ export function readPendingExternalReleaseTargets(cwd = process.cwd()) {
145
+ const { config } = loadConfig(cwd);
146
+ return readPendingReleaseTargets(cwd).filter((target) => resolveTargetReleaseMode(config, target.path) === "external" &&
147
+ !hasLocalTag(cwd, target.tag));
148
+ }
149
+ export function readExternalReleaseWaitPaths(cwd = process.cwd()) {
150
+ const targets = readPendingReleaseTargets(cwd);
151
+ const waiting = new Set(readPendingExternalReleaseTargets(cwd).map((target) => target.path));
152
+ for (let iteration = 0; iteration < targets.length; iteration += 1) {
153
+ for (const target of targets) {
154
+ if (!hasLocalTag(cwd, target.tag) &&
155
+ target.dependencies?.some((dependency) => waiting.has(dependency))) {
156
+ waiting.add(target.path);
157
+ }
158
+ }
159
+ }
160
+ return waiting;
161
+ }
143
162
  export function readExternalReleaseTargets(cwd = process.cwd()) {
144
- return readPendingReleaseTargets(cwd)
145
- .filter((target) => !hasLocalTag(cwd, target.tag))
146
- .map((target) => {
163
+ return readPendingExternalReleaseTargets(cwd).map((target) => {
147
164
  const sidecar = path.join(getPackageStateDirectory(cwd), packageStateFileName(target.path));
148
165
  const statePath = fs.existsSync(sidecar)
149
166
  ? sidecar
@@ -206,9 +223,13 @@ export function readRecordedPendingReleaseTargets(cwd = process.cwd()) {
206
223
  }).flatMap((cohort) => cohort.targets);
207
224
  }
208
225
  export function readPendingReleaseCohorts(cwd = process.cwd()) {
209
- return collectPendingReleaseCohorts(cwd, {});
226
+ return collectPendingReleaseCohorts(cwd, {
227
+ excludeExternal: true,
228
+ excludedPaths: readExternalReleaseWaitPaths(cwd),
229
+ });
210
230
  }
211
231
  function collectPendingReleaseCohorts(cwd, options) {
232
+ const { config } = loadConfig(cwd);
212
233
  const filePath = getBaselineStatePath(cwd);
213
234
  const packageStates = readPackageStates(cwd);
214
235
  const sidecarPaths = new Set(packageStates.map((state) => state.path));
@@ -216,6 +237,12 @@ function collectPendingReleaseCohorts(cwd, options) {
216
237
  // The baseline separates completed releases from the next release on it.
217
238
  const byBranch = new Map();
218
239
  const addTargets = (branch, baselineSha, targets) => {
240
+ if (options.excludeExternal) {
241
+ targets = targets.filter((target) => resolveTargetReleaseMode(config, target.path) === "versionary" &&
242
+ !options.excludedPaths?.has(target.path));
243
+ }
244
+ if (targets.length === 0)
245
+ return;
219
246
  const byBaseline = byBranch.get(branch) ??
220
247
  new Map();
221
248
  byBaseline.set(baselineSha, [
@@ -267,7 +294,7 @@ function collectPendingReleaseCohorts(cwd, options) {
267
294
  }
268
295
  return pending.sort((a, b) => a.branch.localeCompare(b.branch));
269
296
  }
270
- function hasLocalTag(cwd, tag) {
297
+ export function hasLocalTag(cwd, tag) {
271
298
  try {
272
299
  execFileSync("git", ["show-ref", "--verify", "--quiet", `refs/tags/${tag}`], {
273
300
  cwd,
@@ -19,6 +19,7 @@ export interface VersionaryArtifactRule {
19
19
  "expected-matches"?: number;
20
20
  }
21
21
  export interface VersionaryPackage {
22
+ "release-mode"?: "versionary" | "external";
22
23
  "release-type"?: string | string[];
23
24
  "package-name"?: string;
24
25
  "changelog-file"?: string;
@@ -36,6 +37,7 @@ export interface VersionaryConfig {
36
37
  version: 1;
37
38
  "review-mode"?: "direct" | "pr";
38
39
  "release-mode"?: "versionary" | "external";
40
+ "release-pr-checks"?: "run" | "skip";
39
41
  "version-file"?: string;
40
42
  "changelog-file"?: string;
41
43
  "changelog-format"?: VersionaryChangelogFormat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versionary",
3
- "version": "1.8.0",
3
+ "version": "1.10.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",