versionary 0.7.0 → 0.8.1
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/dist/action/index.d.ts +1 -0
- package/dist/action/index.js +121 -0
- package/dist/app/release/pr.d.ts +1 -1
- package/dist/app/release/pr.js +7 -2
- package/dist/app/release/release.js +4 -4
- package/dist/cli/index.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_child_process_1 = require("node:child_process");
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
function getInput(name) {
|
|
7
|
+
const canonical = `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
|
|
8
|
+
const underscoreAlias = canonical.replace(/-/g, "_");
|
|
9
|
+
return (process.env[canonical] ??
|
|
10
|
+
process.env[underscoreAlias] ??
|
|
11
|
+
process.env[`INPUT_${name.toUpperCase()}`] ??
|
|
12
|
+
"").trim();
|
|
13
|
+
}
|
|
14
|
+
function runGit(cwd, args) {
|
|
15
|
+
return (0, node_child_process_1.execFileSync)("git", args, {
|
|
16
|
+
cwd,
|
|
17
|
+
encoding: "utf8",
|
|
18
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19
|
+
}).trim();
|
|
20
|
+
}
|
|
21
|
+
function hasGitConfig(cwd, key) {
|
|
22
|
+
try {
|
|
23
|
+
runGit(cwd, ["config", key]);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function hasOriginRemote(cwd) {
|
|
31
|
+
try {
|
|
32
|
+
runGit(cwd, ["remote", "get-url", "origin"]);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function setOutput(name, value) {
|
|
40
|
+
const outputPath = process.env.GITHUB_OUTPUT;
|
|
41
|
+
if (!outputPath) {
|
|
42
|
+
throw new Error("GITHUB_OUTPUT is not set.");
|
|
43
|
+
}
|
|
44
|
+
const delimiter = `versionary-${(0, node_crypto_1.randomUUID)()}`;
|
|
45
|
+
(0, node_fs_1.appendFileSync)(outputPath, `${name}<<${delimiter}\n${value}\n${delimiter}\n`, "utf8");
|
|
46
|
+
}
|
|
47
|
+
function main() {
|
|
48
|
+
const token = getInput("token") || getInput("github-token");
|
|
49
|
+
if (!token) {
|
|
50
|
+
throw new Error("Input required and not supplied: token (or deprecated github-token).");
|
|
51
|
+
}
|
|
52
|
+
const versionaryVersion = getInput("versionary-version") || "0.7.0";
|
|
53
|
+
const cwd = getInput("working-directory") || ".";
|
|
54
|
+
process.chdir(cwd);
|
|
55
|
+
if (!hasGitConfig(cwd, "user.name")) {
|
|
56
|
+
runGit(cwd, ["config", "user.name", "github-actions[bot]"]);
|
|
57
|
+
}
|
|
58
|
+
if (!hasGitConfig(cwd, "user.email")) {
|
|
59
|
+
runGit(cwd, [
|
|
60
|
+
"config",
|
|
61
|
+
"user.email",
|
|
62
|
+
"41898282+github-actions[bot]@users.noreply.github.com",
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
if (hasOriginRemote(cwd)) {
|
|
66
|
+
const serverUrl = process.env.GITHUB_SERVER_URL ?? "https://github.com";
|
|
67
|
+
const repository = process.env.GITHUB_REPOSITORY;
|
|
68
|
+
if (!repository) {
|
|
69
|
+
throw new Error("GITHUB_REPOSITORY is not set.");
|
|
70
|
+
}
|
|
71
|
+
const base = serverUrl.replace(/^https?:\/\//u, "");
|
|
72
|
+
const encodedToken = encodeURIComponent(token);
|
|
73
|
+
runGit(cwd, [
|
|
74
|
+
"remote",
|
|
75
|
+
"set-url",
|
|
76
|
+
"origin",
|
|
77
|
+
`https://x-access-token:${encodedToken}@${base}/${repository}.git`,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
const raw = (0, node_child_process_1.execFileSync)("npx", ["--yes", `versionary@${versionaryVersion}`, "run", "--json"], {
|
|
81
|
+
cwd,
|
|
82
|
+
encoding: "utf8",
|
|
83
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
84
|
+
env: {
|
|
85
|
+
...process.env,
|
|
86
|
+
GITHUB_TOKEN: token,
|
|
87
|
+
},
|
|
88
|
+
}).trim();
|
|
89
|
+
if (!raw) {
|
|
90
|
+
throw new Error("Versionary returned empty JSON output.");
|
|
91
|
+
}
|
|
92
|
+
process.stdout.write(`${raw}\n`);
|
|
93
|
+
let payload;
|
|
94
|
+
try {
|
|
95
|
+
payload = JSON.parse(raw);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new Error(`Failed parsing Versionary JSON output: ${error instanceof Error ? error.message : String(error)}`);
|
|
99
|
+
}
|
|
100
|
+
const tagNames = Array.isArray(payload.tagNames)
|
|
101
|
+
? payload.tagNames.filter((value) => typeof value === "string")
|
|
102
|
+
: [];
|
|
103
|
+
const firstTag = tagNames[0] ?? "";
|
|
104
|
+
const releaseCreated = payload.releaseCreated === true || tagNames.length > 0 ? "true" : "false";
|
|
105
|
+
setOutput("action", payload.action ?? "");
|
|
106
|
+
setOutput("message", payload.message ?? "");
|
|
107
|
+
setOutput("release_created", releaseCreated);
|
|
108
|
+
setOutput("tag_name", firstTag);
|
|
109
|
+
setOutput("tag_names", JSON.stringify(tagNames));
|
|
110
|
+
setOutput("review_url", payload.reviewUrl ?? "");
|
|
111
|
+
setOutput("branch", payload.branch ?? "");
|
|
112
|
+
setOutput("title", payload.title ?? "");
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
main();
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
119
|
+
process.stderr.write(`${message}\n`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
package/dist/app/release/pr.d.ts
CHANGED
|
@@ -20,4 +20,4 @@ export declare function openOrUpdateSimpleReviewRequest(cwd: string, branch: str
|
|
|
20
20
|
logger?: VersionaryPluginContext["logger"];
|
|
21
21
|
}): Promise<string>;
|
|
22
22
|
export declare function pushReleaseBranch(cwd: string, branch: string): void;
|
|
23
|
-
export declare function isReleaseCommitMessage(
|
|
23
|
+
export declare function isReleaseCommitMessage(commitMessage: string): boolean;
|
package/dist/app/release/pr.js
CHANGED
|
@@ -30,6 +30,7 @@ const SAFE_DIRTY_FILES = new Set([
|
|
|
30
30
|
"bun.lockb",
|
|
31
31
|
"npm-shrinkwrap.json",
|
|
32
32
|
]);
|
|
33
|
+
const VERSIONARY_RELEASE_TRAILER = "Versionary-Release: true";
|
|
33
34
|
function listTrackedDirtyFiles(cwd) {
|
|
34
35
|
const status = (0, node_child_process_1.execFileSync)("git", ["status", "--porcelain", "--untracked-files=no"], {
|
|
35
36
|
cwd,
|
|
@@ -236,7 +237,7 @@ function prepareSimpleReleasePr(cwd = process.cwd(), options = {}) {
|
|
|
236
237
|
cwd,
|
|
237
238
|
stdio: ["ignore", "pipe", "ignore"],
|
|
238
239
|
});
|
|
239
|
-
(0, node_child_process_1.execFileSync)("git", ["commit", "-m", title], {
|
|
240
|
+
(0, node_child_process_1.execFileSync)("git", ["commit", "-m", title, "-m", VERSIONARY_RELEASE_TRAILER], {
|
|
240
241
|
cwd,
|
|
241
242
|
stdio: ["ignore", "pipe", "ignore"],
|
|
242
243
|
});
|
|
@@ -327,6 +328,10 @@ function pushReleaseBranch(cwd, branch) {
|
|
|
327
328
|
stdio: ["ignore", "pipe", "ignore"],
|
|
328
329
|
});
|
|
329
330
|
}
|
|
330
|
-
function isReleaseCommitMessage(
|
|
331
|
+
function isReleaseCommitMessage(commitMessage) {
|
|
332
|
+
if (/^Versionary-Release:\s*true$/imu.test(commitMessage)) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
const subject = commitMessage.split("\n")[0]?.trim() ?? "";
|
|
331
336
|
return /^chore\(release\):\s+(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+)(?:,\s+(?:v\d+\.\d+\.\d+|\S+-v\d+\.\d+\.\d+))*(?:\s+\(#\d+\))?$/u.test(subject);
|
|
332
337
|
}
|
|
@@ -15,8 +15,8 @@ const runtime_js_1 = require("../../plugins/runtime.js");
|
|
|
15
15
|
const pr_js_1 = require("./pr.js");
|
|
16
16
|
const recovery_js_1 = require("./recovery.js");
|
|
17
17
|
const state_js_1 = require("./state.js");
|
|
18
|
-
function
|
|
19
|
-
return (0, node_child_process_1.execFileSync)("git", ["log", "-1", "--pretty=%
|
|
18
|
+
function getHeadCommitMessage(cwd) {
|
|
19
|
+
return (0, node_child_process_1.execFileSync)("git", ["log", "-1", "--pretty=%B"], {
|
|
20
20
|
cwd,
|
|
21
21
|
encoding: "utf8",
|
|
22
22
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -54,8 +54,8 @@ async function runSimpleRelease(cwd = process.cwd()) {
|
|
|
54
54
|
return result.message;
|
|
55
55
|
}
|
|
56
56
|
async function runSimpleReleaseDetailed(cwd = process.cwd(), options = {}) {
|
|
57
|
-
const
|
|
58
|
-
if (!(0, pr_js_1.isReleaseCommitMessage)(
|
|
57
|
+
const commitMessage = getHeadCommitMessage(cwd);
|
|
58
|
+
if (!(0, pr_js_1.isReleaseCommitMessage)(commitMessage)) {
|
|
59
59
|
return {
|
|
60
60
|
action: "release-skipped",
|
|
61
61
|
reason: "No release commit context detected; skipping release stage.",
|
package/dist/cli/index.js
CHANGED
|
@@ -33,11 +33,11 @@ async function main() {
|
|
|
33
33
|
const flags = parseFlags(args);
|
|
34
34
|
const logger = flags.json ? undefined : console;
|
|
35
35
|
if (!command || command === "run") {
|
|
36
|
-
const
|
|
36
|
+
const commitMessage = (0, node_child_process_1.execFileSync)("git", ["log", "-1", "--pretty=%B"], {
|
|
37
37
|
encoding: "utf8",
|
|
38
38
|
stdio: ["ignore", "pipe", "ignore"],
|
|
39
39
|
}).trim();
|
|
40
|
-
if ((0, pr_js_1.isReleaseCommitMessage)(
|
|
40
|
+
if ((0, pr_js_1.isReleaseCommitMessage)(commitMessage)) {
|
|
41
41
|
if (flags.json) {
|
|
42
42
|
const release = await (0, release_js_1.runSimpleReleaseDetailed)(process.cwd(), {
|
|
43
43
|
logger,
|