Skip to content

Commit 252f379

Browse files
committed
feat: enhance publish-proguard-plugin script to create GitHub releases
- Added functionality to read package information from package.json. - Implemented logic to create a GitHub release if it does not already exist. - Improved error handling for release creation process. - Exited gracefully based on the presence of GitHub Actions environment variables.
1 parent a183469 commit 252f379

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

scripts/publish-proguard-plugin.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { spawnSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
23
import { join } from "node:path";
34

45
if (!process.env.REPOSITORY_TOKEN) {
@@ -16,4 +17,67 @@ const result = spawnSync(gradlew, ["publish"], {
1617
shell: false,
1718
});
1819

19-
process.exit(result.status ?? 1);
20+
if (result.status !== 0) {
21+
process.exit(result.status ?? 1);
22+
}
23+
24+
const pkg = JSON.parse(
25+
readFileSync(join(pluginDir, "package.json"), "utf8"),
26+
) as { name: string; version: string };
27+
const tag = `${pkg.name}@${pkg.version}`;
28+
29+
if (process.env.GITHUB_ACTIONS !== "true") {
30+
process.exit(0);
31+
}
32+
33+
const ghEnv = {
34+
...process.env,
35+
GH_TOKEN: process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? "",
36+
};
37+
38+
if (!ghEnv.GH_TOKEN) {
39+
process.exit(0);
40+
}
41+
42+
const view = spawnSync("gh", ["release", "view", tag], {
43+
env: ghEnv,
44+
stdio: "pipe",
45+
});
46+
if (view.status === 0) {
47+
process.exit(0);
48+
}
49+
50+
const createArgs = [
51+
"release",
52+
"create",
53+
tag,
54+
"--title",
55+
`${pkg.name} ${pkg.version} (Gradle)`,
56+
"--notes",
57+
"Gradle plugin published to Maven. Two coordinates are normal: the `proguard-plugin` jar and the plugin marker for `dev.faststats.proguard-mappings-upload` (required for the `plugins { id(...) }` block).",
58+
];
59+
if (process.env.GITHUB_SHA) {
60+
createArgs.push("--target", process.env.GITHUB_SHA);
61+
}
62+
63+
const created = spawnSync("gh", createArgs, {
64+
env: ghEnv,
65+
stdio: ["inherit", "inherit", "pipe"],
66+
encoding: "utf8",
67+
});
68+
69+
if (created.status !== 0) {
70+
const err = created.stderr ?? "";
71+
if (
72+
err.includes("already_exists") ||
73+
err.toLowerCase().includes("already exists")
74+
) {
75+
process.exit(0);
76+
}
77+
if (err) {
78+
console.error(err);
79+
}
80+
process.exit(created.status ?? 1);
81+
}
82+
83+
process.exit(0);

0 commit comments

Comments
 (0)