-
Notifications
You must be signed in to change notification settings - Fork 1
/
bumpversion.ts
executable file
·54 lines (42 loc) · 1.74 KB
/
bumpversion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write
const dec = (data: BufferSource) => new TextDecoder().decode(data).trim();
const enc = (data: object) =>
new TextEncoder().encode(JSON.stringify(data, null, 2));
const run = (...args: ConstructorParameters<typeof Deno.Command>) =>
new Deno.Command(...args).output()
.then((data: { stdout: BufferSource }) => dec(data.stdout));
const git = (...args: string[]) => run("git", { args });
const convco = (...args: string[]) => run("convco", { args });
const convcoNextVersion = () => convco("version", "--bump", "HEAD");
interface DenoJson extends Record<string, unknown> {
version: string;
}
async function readDeno(): Promise<DenoJson> {
const content = await Deno.readFile("./deno.json").then(dec);
return JSON.parse(content);
}
async function setVersion(newVersion: string, json: DenoJson) {
const newJson = structuredClone(json);
newJson.version = newVersion;
await Deno.writeFile("./deno.json", enc(newJson));
}
const denoData = await readDeno();
const current_branch = await git("rev-parse", "--abbrev-ref", "HEAD");
const release_branch = "main";
if (import.meta.main) {
if (current_branch != release_branch) {
console.error(`can only bump version on ${release_branch}`);
Deno.exit(1);
} else {
const next_version = await convcoNextVersion();
await setVersion(next_version, denoData);
await run("deno", { args: ["fmt"] });
await git("add", "deno.json", "deno.lock");
await git("commit", "-m", "chore: bump version");
await git("tag", `v${next_version}`);
await convco("changelog", "-o", "CHANGELOG.md");
await run("deno", { args: ["fmt"] });
await git("add", "CHANGELOG.md");
await git("commit", "-m", "chore: changelog");
}
}