The best way to control Claude Code, Codex and more from any computer or phone

main
ts 67 lines 2.45 KB
Raw
1 // Prepends the release notes for a tag to CHANGELOG.md. Idempotent: a tag
2 // that already has a heading in CHANGELOG.md is skipped.
3 //
4 // The notes cover the commits since the previous tag, up to the tag if it
5 // exists yet, otherwise HEAD. Reads `ALCHEMY_REPO` (`<owner>/<repo>`) for the
6 // changelog's links.
7 //
8 // Usage: node scripts/release/release-notes.ts <tag>
9 import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
10 import * as NodeServices from "@effect/platform-node/NodeServices";
11 import { Argument, Command } from "effect/cli";
12 import * as Console from "effect/Console";
13 import * as Effect from "effect/Effect";
14 import * as FileSystem from "effect/FileSystem";
15 import * as Path from "effect/Path";
16 import { ChildProcess } from "effect/process";
17 import { ChildProcessSpawner } from "effect/process/ChildProcessSpawner";
18 import { generate } from "./changelog.ts";
19 import { repository } from "./config.ts";
20
21 /** Whether `tag` exists locally. */
22 const tagExists = Effect.fn(function* (tag: string) {
23 const spawner = yield* ChildProcessSpawner;
24 const exitCode = yield* Effect.scoped(
25 Effect.gen(function* () {
26 const handle = yield* spawner.spawn(
27 ChildProcess.make("git", ["rev-parse", "--verify", `refs/tags/${tag}`], {
28 stdout: "ignore",
29 stderr: "ignore",
30 }),
31 );
32 return yield* handle.exitCode;
33 }),
34 );
35 return Number(exitCode) === 0;
36 });
37
38 const command = Command.make(
39 "release-notes",
40 {
41 tag: Argument.String("tag").pipe(Argument.withDescription("Release tag, e.g. v2.0.0-beta.13")),
42 },
43 Effect.fn(function* ({ tag }) {
44 const fs = yield* FileSystem.FileSystem;
45 const path = yield* Path.Path;
46 const changelogPath = path.resolve("CHANGELOG.md");
47
48 const existing = (yield* fs.exists(changelogPath))
49 ? yield* fs.readFileString(changelogPath)
50 : "";
51 if (existing.includes(`## ${tag}\n`)) {
52 yield* Console.log(`${tag} already in CHANGELOG.md, skipping`);
53 return;
54 }
55
56 const to = (yield* tagExists(tag)) ? tag : "HEAD";
57 yield* Console.log(`Generating release notes for ${tag} (using ${to})`);
58 const { md } = yield* generate({ to, repo: yield* repository });
59
60 yield* fs.writeFileString(changelogPath, `## ${tag}\n\n${md}\n\n---\n\n${existing}`);
61 }),
62 ).pipe(Command.withDescription("Prepend the release notes for a tag to CHANGELOG.md"));
63
64 Command.run(command, { version: "0.0.0" }).pipe(
65 Effect.provide(NodeServices.layer),
66 NodeRuntime.runMain,
67 );