Skip to content

Commit b5f70e7

Browse files
committed
chore: update dependencies and add changelog functionality
- Added @types/node dependency to package.json and bun.lock. - Updated @types/node version in bun.lock. - Changed changelog configuration to use @changesets/changelog-github. - Introduced scripts for parsing changelog sections and syncing ProGuard version. - Created initial CHANGELOG.md for the ProGuard plugin.
1 parent 252f379 commit b5f70e7

File tree

8 files changed

+113
-29
lines changed

8 files changed

+113
-29
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
33
"changelog": [
4-
"@changesets/cli/changelog",
4+
"@changesets/changelog-github",
55
{
66
"repo": "faststats-dev/sourcemaps"
77
}

bun.lock

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
"lint": "turbo run lint",
1111
"test": "turbo run test",
1212
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
13-
"check-types": "turbo run check-types",
13+
"check-types": "tsc --noEmit -p scripts/tsconfig.json && turbo run check-types",
1414
"ci": "turbo run lint check-types test build",
1515
"ci:version": "changeset version && bun update && bun run sync-proguard-version",
1616
"ci:publish": "changeset publish && bun scripts/publish-proguard-plugin.ts"
1717
},
1818
"devDependencies": {
19+
"@types/node": "^22.15.3",
1920
"@biomejs/biome": "2.4.10",
2021
"turbo": "^2.9.3",
2122
"typescript": "6.0.2",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @faststats/proguard-mappings-upload-plugin
2+
3+
## 0.1.0
4+
5+
### Patch Changes
6+
7+
- Initial Gradle plugin for uploading ProGuard/R8 mapping files to the FastStats sourcemaps API

scripts/parse-changelog-section.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { readFileSync } from "node:fs";
2+
3+
export function getChangelogSectionForVersion(
4+
changelogPath: string,
5+
version: string,
6+
): string | null {
7+
let text: string;
8+
try {
9+
text = readFileSync(changelogPath, "utf8");
10+
} catch {
11+
return null;
12+
}
13+
const esc = version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14+
const header = new RegExp(`^## ${esc}\\s*$`, "m");
15+
const m = text.match(header);
16+
if (m === null || m.index === undefined) {
17+
return null;
18+
}
19+
const start = m.index + m[0].length;
20+
const rest = text.slice(start);
21+
const next = rest.search(/^## [0-9]/m);
22+
const body = (next === -1 ? rest : rest.slice(0, next)).trim();
23+
return body.length ? body : null;
24+
}

scripts/publish-proguard-plugin.ts

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { spawnSync } from "node:child_process";
2-
import { readFileSync } from "node:fs";
3-
import { join } from "node:path";
2+
import { randomBytes } from "node:crypto";
3+
import { readFileSync, unlinkSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { dirname, join } from "node:path";
6+
import { fileURLToPath } from "node:url";
7+
import { getChangelogSectionForVersion } from "./parse-changelog-section.js";
8+
9+
const scriptDir = dirname(fileURLToPath(import.meta.url));
10+
11+
const GRADLE_PLUGIN_ID = "dev.faststats.proguard-mappings-upload";
412

513
if (!process.env.REPOSITORY_TOKEN) {
614
console.log("Skipping Gradle plugin publish (REPOSITORY_TOKEN unset)");
715
process.exit(0);
816
}
917

10-
const pluginDir = join(import.meta.dir, "..", "packages", "proguard-plugin");
18+
const pluginDir = join(scriptDir, "..", "packages", "proguard-plugin");
1119
const gradlew = join(pluginDir, "gradlew");
1220

1321
const result = spawnSync(gradlew, ["publish"], {
@@ -23,8 +31,20 @@ if (result.status !== 0) {
2331

2432
const pkg = JSON.parse(
2533
readFileSync(join(pluginDir, "package.json"), "utf8"),
26-
) as { name: string; version: string };
27-
const tag = `${pkg.name}@${pkg.version}`;
34+
) as { version: string };
35+
36+
const tag = `${GRADLE_PLUGIN_ID}@${pkg.version}`;
37+
const title = `${GRADLE_PLUGIN_ID} ${pkg.version}`;
38+
39+
const changelogPath = join(pluginDir, "CHANGELOG.md");
40+
const changelogBody = getChangelogSectionForVersion(changelogPath, pkg.version);
41+
42+
if (!changelogBody) {
43+
console.error(
44+
`No ## ${pkg.version} section in ${changelogPath}. Run changeset version so Changesets updates the changelog.`,
45+
);
46+
process.exit(1);
47+
}
2848

2949
if (process.env.GITHUB_ACTIONS !== "true") {
3050
process.exit(0);
@@ -47,37 +67,51 @@ if (view.status === 0) {
4767
process.exit(0);
4868
}
4969

70+
const notesPath = join(
71+
tmpdir(),
72+
`gh-release-notes-${randomBytes(8).toString("hex")}.md`,
73+
);
74+
writeFileSync(notesPath, changelogBody, "utf8");
75+
5076
const createArgs = [
5177
"release",
5278
"create",
5379
tag,
5480
"--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).",
81+
title,
82+
"--notes-file",
83+
notesPath,
5884
];
5985
if (process.env.GITHUB_SHA) {
6086
createArgs.push("--target", process.env.GITHUB_SHA);
6187
}
6288

63-
const created = spawnSync("gh", createArgs, {
64-
env: ghEnv,
65-
stdio: ["inherit", "inherit", "pipe"],
66-
encoding: "utf8",
67-
});
89+
try {
90+
const created = spawnSync("gh", createArgs, {
91+
env: ghEnv,
92+
stdio: ["inherit", "inherit", "pipe"],
93+
encoding: "utf8",
94+
});
6895

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);
96+
if (created.status !== 0) {
97+
const err = created.stderr ?? "";
98+
if (
99+
err.includes("already_exists") ||
100+
err.toLowerCase().includes("already exists")
101+
) {
102+
process.exit(0);
103+
}
104+
if (err) {
105+
console.error(err);
106+
}
107+
process.exit(created.status ?? 1);
76108
}
77-
if (err) {
78-
console.error(err);
109+
} finally {
110+
try {
111+
unlinkSync(notesPath);
112+
} catch {
113+
// ignore
79114
}
80-
process.exit(created.status ?? 1);
81115
}
82116

83117
process.exit(0);

scripts/sync-proguard-version.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { readFileSync, writeFileSync } from "node:fs";
2-
import { join } from "node:path";
2+
import { dirname, join } from "node:path";
3+
import { fileURLToPath } from "node:url";
34

4-
const root = join(import.meta.dir, "..");
5+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
56
const pkgPath = join(root, "packages/proguard-plugin/package.json");
67
const gradlePropsPath = join(
78
root,

scripts/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler",
6+
"noEmit": true,
7+
"strict": true,
8+
"types": ["node"],
9+
"skipLibCheck": true
10+
},
11+
"include": ["./**/*.ts"]
12+
}

0 commit comments

Comments
 (0)