versionary 0.26.1 → 0.28.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
@@ -172,6 +172,9 @@ For a quick trial, use:
172
172
  - `off` (default): do not post comments
173
173
  - `best-effort`: post comments and continue on API/permission failures
174
174
  - `strict`: fail release if comment posting fails
175
+ - comments are authored by the account that owns the configured token; see
176
+ [Comment and commit author identity](#comment-and-commit-author-identity)
177
+ to post them under a bot identity
175
178
  - optional monorepo planning with `monorepo-mode` and `packages`:
176
179
  - `independent` computes package bumps per path
177
180
  - `fixed` computes one shared bump across configured package paths
@@ -416,6 +419,33 @@ the composite action. This means release-branch force-pushes are attributed to
416
419
  that token and can trigger downstream workflows when using a PAT/App token.
417
420
  (`github-token` remains as a deprecated alias for backward compatibility.)
418
421
 
422
+ #### Comment and commit author identity
423
+
424
+ Two distinct identities are at play; keep them apart.
425
+
426
+ **Release-reference comments, the GitHub Release, and the tag/branch push** are
427
+ attributed to the account that owns the token you provide. There is no GitHub
428
+ API to set a custom author independent of the token, so this identity always
429
+ follows the token's account:
430
+
431
+ - the workflow's default `GITHUB_TOKEN` acts as `github-actions[bot]` — the
432
+ common case, and what most `semantic-release` setups show
433
+ - a **personal access token (PAT)** acts as your own user
434
+ - a **dedicated bot user account** acts as that account (for example
435
+ `semantic-release`'s own `@semantic-release-bot`): create a separate GitHub
436
+ user, generate a PAT for it, and store it as the release token
437
+ - a **GitHub App installation token** (e.g. minted with
438
+ `actions/create-github-app-token`) acts as `<app-name>[bot]`
439
+
440
+ **The release commit's committer** comes from git's `user.name`/`user.email`,
441
+ not the token. When neither is configured (e.g. a bare CI runner), Versionary
442
+ defaults it to `github-actions[bot]`, so no `git config` step is needed in your
443
+ workflow; an existing identity (local, global, or the one the GitHub Action
444
+ wrapper sets) is left untouched.
445
+
446
+ The release-reference comment body itself is signed by Versionary regardless of
447
+ which account posts it.
448
+
419
449
  Action outputs:
420
450
 
421
451
  - `action`: `noop`, `pr-prepared`, `release-published`, `release-skipped`
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Default committer identity Versionary uses when a repository has no
3
+ * `user.name`/`user.email` configured (for example a bare CI runner).
4
+ *
5
+ * This intentionally mirrors the GitHub Action entrypoint
6
+ * (`src/action/index.ts`), which is a standalone bundle and cannot import this
7
+ * module, so release commits are attributed to the same bot regardless of how
8
+ * Versionary is invoked (composite action vs. running the CLI from source).
9
+ */
10
+ export declare const DEFAULT_GIT_AUTHOR_NAME = "github-actions[bot]";
11
+ export declare const DEFAULT_GIT_AUTHOR_EMAIL = "41898282+github-actions[bot]@users.noreply.github.com";
12
+ /**
13
+ * Ensure git has a committer identity before Versionary creates release
14
+ * commits. This only fills the gap: if `user.name`/`user.email` already resolve
15
+ * (local, global, or system config), they are left untouched. Otherwise a
16
+ * repository-local default is set so `git commit` does not fail with
17
+ * "Please tell me who you are".
18
+ */
19
+ export declare function ensureGitIdentity(cwd: string): void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_GIT_AUTHOR_EMAIL = exports.DEFAULT_GIT_AUTHOR_NAME = void 0;
4
+ exports.ensureGitIdentity = ensureGitIdentity;
5
+ const node_child_process_1 = require("node:child_process");
6
+ /**
7
+ * Default committer identity Versionary uses when a repository has no
8
+ * `user.name`/`user.email` configured (for example a bare CI runner).
9
+ *
10
+ * This intentionally mirrors the GitHub Action entrypoint
11
+ * (`src/action/index.ts`), which is a standalone bundle and cannot import this
12
+ * module, so release commits are attributed to the same bot regardless of how
13
+ * Versionary is invoked (composite action vs. running the CLI from source).
14
+ */
15
+ exports.DEFAULT_GIT_AUTHOR_NAME = "github-actions[bot]";
16
+ exports.DEFAULT_GIT_AUTHOR_EMAIL = "41898282+github-actions[bot]@users.noreply.github.com";
17
+ function hasGitConfig(cwd, key) {
18
+ try {
19
+ (0, node_child_process_1.execFileSync)("git", ["config", key], {
20
+ cwd,
21
+ stdio: ["ignore", "pipe", "ignore"],
22
+ });
23
+ return true;
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
29
+ /**
30
+ * Ensure git has a committer identity before Versionary creates release
31
+ * commits. This only fills the gap: if `user.name`/`user.email` already resolve
32
+ * (local, global, or system config), they are left untouched. Otherwise a
33
+ * repository-local default is set so `git commit` does not fail with
34
+ * "Please tell me who you are".
35
+ */
36
+ function ensureGitIdentity(cwd) {
37
+ if (!hasGitConfig(cwd, "user.name")) {
38
+ (0, node_child_process_1.execFileSync)("git", ["config", "user.name", exports.DEFAULT_GIT_AUTHOR_NAME], {
39
+ cwd,
40
+ stdio: ["ignore", "pipe", "ignore"],
41
+ });
42
+ }
43
+ if (!hasGitConfig(cwd, "user.email")) {
44
+ (0, node_child_process_1.execFileSync)("git", ["config", "user.email", exports.DEFAULT_GIT_AUTHOR_EMAIL], {
45
+ cwd,
46
+ stdio: ["ignore", "pipe", "ignore"],
47
+ });
48
+ }
49
+ }
@@ -226,7 +226,7 @@ function prependChangelog(cwd, changelogFile, section, format = "markdown-change
226
226
  }
227
227
  const heading = "# Changelog\n\n";
228
228
  const bodyWithoutHeading = existing.replace(/^# Changelog\s*/u, "");
229
- const separator = existing.length > 0 ? "\n" : "";
229
+ const separator = bodyWithoutHeading.length > 0 ? "\n\n" : "";
230
230
  const next = `${`${heading}${section}${separator}${bodyWithoutHeading}`.trimEnd()}\n`;
231
231
  node_fs_1.default.writeFileSync(changelogPath, next, "utf8");
232
232
  }
@@ -19,6 +19,7 @@ const node_child_process_1 = require("node:child_process");
19
19
  const node_fs_1 = __importDefault(require("node:fs"));
20
20
  const node_path_1 = __importDefault(require("node:path"));
21
21
  const load_config_js_1 = require("../config/load-config.js");
22
+ const identity_js_1 = require("../git/identity.js");
22
23
  const client_js_1 = require("../scm/client.js");
23
24
  const package_context_js_1 = require("../strategy/package-context.js");
24
25
  const artifact_rules_js_1 = require("./artifact-rules.js");
@@ -156,13 +157,6 @@ function fetchRemoteReleaseBranch(cwd, branch) {
156
157
  });
157
158
  return remoteRef;
158
159
  }
159
- function resolveReleaseName(cwd, packagePath, packageConfig, strategy, strategyConfig) {
160
- const configuredName = packageConfig["package-name"]?.trim();
161
- if (configuredName) {
162
- return configuredName;
163
- }
164
- return strategy.readPackageName?.(cwd, strategyConfig) ?? packagePath;
165
- }
166
160
  function buildReleaseTargets(cwd, plan, loadedConfig) {
167
161
  const releaseTargets = plan.packages
168
162
  ? plan.packages
@@ -177,7 +171,7 @@ function buildReleaseTargets(cwd, plan, loadedConfig) {
177
171
  }
178
172
  const packageConfig = loadedConfig.packages?.[pkg.path] ?? {};
179
173
  const packageContext = (0, package_context_js_1.resolvePackageStrategyContext)(loadedConfig, pkg.path, packageConfig);
180
- const releaseName = resolveReleaseName(cwd, pkg.path, packageConfig, packageContext.strategy, packageContext.config);
174
+ const releaseName = (0, package_context_js_1.resolveReleaseName)(cwd, pkg.path, packageConfig, packageContext.strategy, packageContext.config);
181
175
  const tagPrefix = normalizeReleaseNameForTag(releaseName);
182
176
  return {
183
177
  path: pkg.path,
@@ -210,7 +204,7 @@ function buildPackageReleaseMetadata(cwd, plan, loadedConfig) {
210
204
  }
211
205
  const packageConfig = loadedConfig.packages?.[pkg.path] ?? {};
212
206
  const packageContext = (0, package_context_js_1.resolvePackageStrategyContext)(loadedConfig, pkg.path, packageConfig);
213
- const releaseName = resolveReleaseName(cwd, pkg.path, packageConfig, packageContext.strategy, packageContext.config);
207
+ const releaseName = (0, package_context_js_1.resolveReleaseName)(cwd, pkg.path, packageConfig, packageContext.strategy, packageContext.config);
214
208
  metadataByPath[pkg.path] = {
215
209
  releaseName,
216
210
  tagPrefix: normalizeReleaseNameForTag(releaseName),
@@ -349,6 +343,7 @@ function prepareReleasePr(cwd = process.cwd(), options = {}) {
349
343
  cwd,
350
344
  stdio: ["ignore", "pipe", "ignore"],
351
345
  });
346
+ (0, identity_js_1.ensureGitIdentity)(cwd);
352
347
  (0, node_child_process_1.execFileSync)("git", ["commit", "-m", title, "-m", VERSIONARY_RELEASE_TRAILER], {
353
348
  cwd,
354
349
  stdio: ["ignore", "pipe", "ignore"],
@@ -387,7 +382,7 @@ function renderSimpleReviewRequestBody(version, previousVersion, commits, plan =
387
382
  }
388
383
  const packageConfig = loadedConfig.packages?.[packagePath] ?? {};
389
384
  const packageContext = (0, package_context_js_1.resolvePackageStrategyContext)(loadedConfig, packagePath, packageConfig);
390
- const releaseName = resolveReleaseName(cwd, packagePath, packageConfig, packageContext.strategy, packageContext.config);
385
+ const releaseName = (0, package_context_js_1.resolveReleaseName)(cwd, packagePath, packageConfig, packageContext.strategy, packageContext.config);
391
386
  return normalizeReleaseNameForTag(releaseName);
392
387
  };
393
388
  if (plan?.packages && plan.packages.length > 1) {
@@ -1,5 +1,6 @@
1
1
  import type { VersionaryConfig } from "../types/config.js";
2
2
  import type { VersionaryPluginContext } from "../types/plugins.js";
3
+ export declare function resolveTargetPackageName(cwd: string, config: VersionaryConfig, targetPath: string): string | undefined;
3
4
  export declare function extractReleaseNotes(content: string, version: string, changelogFormat: "markdown-changelog" | "r-news"): string;
4
5
  export declare function extractClosingReferencesFromNotes(notes: string): number[];
5
6
  export declare function resolveTargetChangelogFile(config: VersionaryConfig, rootChangelogFile: string, targetPath: string): string;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveTargetPackageName = resolveTargetPackageName;
6
7
  exports.extractReleaseNotes = extractReleaseNotes;
7
8
  exports.extractClosingReferencesFromNotes = extractClosingReferencesFromNotes;
8
9
  exports.resolveTargetChangelogFile = resolveTargetChangelogFile;
@@ -15,6 +16,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
15
16
  const node_path_1 = __importDefault(require("node:path"));
16
17
  const load_config_js_1 = require("../config/load-config.js");
17
18
  const client_js_1 = require("../scm/client.js");
19
+ const package_context_js_1 = require("../strategy/package-context.js");
18
20
  const resolve_js_1 = require("../strategy/resolve.js");
19
21
  const plan_js_1 = require("./plan.js");
20
22
  const pr_js_1 = require("./pr.js");
@@ -23,6 +25,15 @@ const state_js_1 = require("./state.js");
23
25
  function escapeRegExp(input) {
24
26
  return input.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
25
27
  }
28
+ function resolveTargetPackageName(cwd, config, targetPath) {
29
+ const packageConfig = config.packages?.[targetPath] ?? {};
30
+ const { strategy, config: strategyConfig } = (0, package_context_js_1.resolvePackageStrategyContext)(config, targetPath, packageConfig);
31
+ const resolved = (0, package_context_js_1.resolveReleaseName)(cwd, targetPath, packageConfig, strategy, strategyConfig);
32
+ if (!resolved || resolved === targetPath) {
33
+ return undefined;
34
+ }
35
+ return resolved;
36
+ }
26
37
  function extractReleaseNotes(content, version, changelogFormat) {
27
38
  const lines = content.split("\n");
28
39
  const shortVersion = version.replace(/\.\d+$/u, "");
@@ -172,12 +183,12 @@ async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
172
183
  }
173
184
  const scmClient = (0, client_js_1.getScmClient)();
174
185
  const releases = [];
175
- const referencesByTag = new Map();
186
+ const referenceReleases = [];
176
187
  for (const target of targets) {
177
188
  const targetChangelogFile = resolveTargetChangelogFile(loaded.config, changelogFile, target.path);
178
189
  const targetChangelogFormat = resolveTargetChangelogFormat(loaded.config, target.path);
179
190
  const releaseNotes = readReleaseNotes(cwd, target.version, targetChangelogFile, targetChangelogFormat);
180
- referencesByTag.set(target.tag, extractClosingReferencesFromNotes(releaseNotes));
191
+ const references = extractClosingReferencesFromNotes(releaseNotes);
181
192
  const outcome = await (0, recovery_js_1.executeIdempotentReleaseTarget)(cwd, {
182
193
  tag: target.tag,
183
194
  version: target.version,
@@ -197,21 +208,27 @@ async function runReleaseDetailed(cwd = process.cwd(), options = {}) {
197
208
  tagStatus: outcome.tagStatus,
198
209
  metadataStatus: outcome.metadataStatus,
199
210
  });
200
- const references = referencesByTag.get(outcome.tag) ?? [];
201
- if (references.length > 0 &&
202
- referenceCommentMode !== "off" &&
203
- scmClient.createReleaseReferenceComments) {
204
- await scmClient.createReleaseReferenceComments({
211
+ if (references.length > 0) {
212
+ referenceReleases.push({
213
+ name: resolveTargetPackageName(cwd, loaded.config, target.path),
214
+ tag: outcome.tag,
205
215
  version: target.version,
206
216
  releaseUrl: outcome.url,
207
217
  references,
208
- mode: referenceCommentMode,
209
- }, {
210
- cwd,
211
- logger: options.logger,
212
218
  });
213
219
  }
214
220
  }
221
+ if (referenceReleases.length > 0 &&
222
+ referenceCommentMode !== "off" &&
223
+ scmClient.createReleaseReferenceComments) {
224
+ await scmClient.createReleaseReferenceComments({
225
+ releases: referenceReleases,
226
+ mode: referenceCommentMode,
227
+ }, {
228
+ cwd,
229
+ logger: options.logger,
230
+ });
231
+ }
215
232
  const published = releases.map((outcome) => `${outcome.tag}: ${outcome.url} (tag=${outcome.tagStatus}, metadata=${outcome.metadataStatus})`);
216
233
  return {
217
234
  action: "release-published",
@@ -86,6 +86,42 @@ async function ensureLabels(octokit, repo, pullNumber, labels, branchContext) {
86
86
  throw new Error(`Failed applying labels to pull request #${pullNumber}: [${repoRef(repo)} base=${branchContext.baseBranch} head=${branchContext.headBranch}] ${message}`);
87
87
  }
88
88
  }
89
+ function groupReleasesByIssue(releases) {
90
+ const byIssue = new Map();
91
+ for (const release of releases) {
92
+ for (const reference of release.references) {
93
+ const bucket = byIssue.get(reference) ?? [];
94
+ if (!bucket.some((entry) => entry.tag === release.tag)) {
95
+ bucket.push(release);
96
+ }
97
+ byIssue.set(reference, bucket);
98
+ }
99
+ }
100
+ for (const bucket of byIssue.values()) {
101
+ bucket.sort((a, b) => a.tag.localeCompare(b.tag));
102
+ }
103
+ return new Map([...byIssue.entries()].sort(([a], [b]) => a - b));
104
+ }
105
+ function renderReleaseLink(release) {
106
+ if (release.name) {
107
+ return `[\`${release.name}\` v${release.version}](${release.releaseUrl})`;
108
+ }
109
+ return `[version ${release.version}](${release.releaseUrl})`;
110
+ }
111
+ function renderReleaseReferenceCommentBody(releases) {
112
+ const footer = "Released by [Versionary](https://github.com/jolars/versionary).";
113
+ if (releases.length === 1) {
114
+ const release = releases[0];
115
+ if (!release) {
116
+ throw new Error("Expected at least one release for comment body.");
117
+ }
118
+ return `This is included in ${renderReleaseLink(release)}. :tada:\n\n${footer}`;
119
+ }
120
+ const bullets = releases
121
+ .map((release) => `- ${renderReleaseLink(release)}`)
122
+ .join("\n");
123
+ return `This is included in the following releases: :tada:\n\n${bullets}\n\n${footer}`;
124
+ }
89
125
  function createGitHubPlugin() {
90
126
  return {
91
127
  name: "github",
@@ -275,13 +311,11 @@ function createGitHubPlugin() {
275
311
  async createReleaseReferenceComments(input, context) {
276
312
  const repo = getRepoFromEnv();
277
313
  const octokit = new rest_1.Octokit({ auth: getGitHubToken() });
278
- const uniqueReferences = [...new Set(input.references)].sort((a, b) => a - b);
279
- const commented = [];
280
314
  const mode = input.mode ?? "best-effort";
281
- for (const reference of uniqueReferences) {
282
- const body = reference >= 1_000_000_000
283
- ? `This pull request is included in [version ${input.version}](${input.releaseUrl}).`
284
- : `This issue has been resolved in [version ${input.version}](${input.releaseUrl}).`;
315
+ const releasesByIssue = groupReleasesByIssue(input.releases);
316
+ const commented = [];
317
+ for (const [reference, releases] of releasesByIssue) {
318
+ const body = renderReleaseReferenceCommentBody(releases);
285
319
  try {
286
320
  await octokit.issues.createComment({
287
321
  owner: repo.owner,
@@ -41,10 +41,15 @@ export interface ScmReleaseMetadataResult {
41
41
  url: string;
42
42
  status?: "created" | "exists";
43
43
  }
44
- export interface ScmReleaseReferenceCommentsInput {
44
+ export interface ScmReleaseReferenceCommentsRelease {
45
+ name?: string;
46
+ tag: string;
45
47
  version: string;
46
48
  releaseUrl: string;
47
49
  references: number[];
50
+ }
51
+ export interface ScmReleaseReferenceCommentsInput {
52
+ releases: ScmReleaseReferenceCommentsRelease[];
48
53
  mode?: "best-effort" | "strict";
49
54
  }
50
55
  export interface ScmReleaseReferenceCommentsResult {
@@ -1,5 +1,6 @@
1
1
  import type { VersionaryConfig, VersionaryPackage } from "../types/config.js";
2
2
  import type { VersionStrategy } from "./types.js";
3
+ export declare function resolveReleaseName(cwd: string, packagePath: string, packageConfig: VersionaryPackage, strategy: VersionStrategy, strategyConfig: VersionaryConfig): string;
3
4
  export declare function resolvePackageStrategyContext(rootConfig: VersionaryConfig, packagePath: string, packageConfig: VersionaryPackage): {
4
5
  strategy: VersionStrategy;
5
6
  config: VersionaryConfig;
@@ -3,9 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveReleaseName = resolveReleaseName;
6
7
  exports.resolvePackageStrategyContext = resolvePackageStrategyContext;
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
9
  const resolve_js_1 = require("./resolve.js");
10
+ function resolveReleaseName(cwd, packagePath, packageConfig, strategy, strategyConfig) {
11
+ const configuredName = packageConfig["package-name"]?.trim();
12
+ if (configuredName) {
13
+ return configuredName;
14
+ }
15
+ return strategy.readPackageName?.(cwd, strategyConfig) ?? packagePath;
16
+ }
9
17
  function withVersionFile(config, versionFile) {
10
18
  return {
11
19
  ...config,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versionary",
3
- "version": "0.26.1",
3
+ "version": "0.28.0",
4
4
  "description": "Automatic release framework based on conventional commits and semantic versioning",
5
5
  "keywords": [
6
6
  "releasing",