The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Command from "effect/cli/Command" |
| 2 | import * as Flag from "effect/cli/Flag" |
| 3 | import * as Config from "effect/Config" |
| 4 | import * as Console from "effect/Console" |
| 5 | import * as Effect from "effect/Effect" |
| 6 | import * as Layer from "effect/Layer" |
| 7 | import * as Option from "effect/Option" |
| 8 | import * as Semver from "semver" |
| 9 | import type { ReleasePackage } from "./NpmPromote.ts" |
| 10 | import { NpmPromoteError } from "./NpmPromoteError.ts" |
| 11 | import { Alerts, layerDryRun, promoteRelease, Website } from "./Release.ts" |
| 12 | import * as Workspace from "./Workspace.ts" |
| 13 | |
| 14 | const dryRun = Flag.Boolean("dry-run").pipe( |
| 15 | Flag.withDescription("Print what would change without moving dist-tags, deploying, or touching GitHub issues"), |
| 16 | Flag.withDefault(false) |
| 17 | ) |
| 18 | |
| 19 | const overdueAfterHours = Flag.Int("overdue-after-hours").pipe( |
| 20 | Flag.withDescription("Open a tracking issue when a version bump is still unpromoted after this many hours"), |
| 21 | Flag.withDefault(12) |
| 22 | ) |
| 23 | |
| 24 | const githubConfig = Config.all({ |
| 25 | github: Config.all({ |
| 26 | repository: Config.String("GITHUB_REPOSITORY"), |
| 27 | token: Config.Redacted("GITHUB_TOKEN") |
| 28 | }), |
| 29 | dispatchToken: Config.Redacted("WEBSITE_DISPATCH_TOKEN") |
| 30 | }) |
| 31 | |
| 32 | const format = (pkg: ReleasePackage) => `${pkg.name}@${pkg.version}` |
| 33 | |
| 34 | const run = Effect.fnUntraced(function*(options: { |
| 35 | readonly dryRun: boolean |
| 36 | readonly overdueAfterHours: number |
| 37 | }) { |
| 38 | const workspace = yield* Workspace.releasePackages(process.cwd()) |
| 39 | const effect = workspace.find((pkg) => pkg.name === "effect") |
| 40 | if (effect === undefined) { |
| 41 | return yield* new NpmPromoteError({ message: "The workspace has no public effect package" }) |
| 42 | } |
| 43 | |
| 44 | // Never point latest at a prerelease. Pre mode releases keep their own dist-tag. |
| 45 | const prereleases = workspace.filter((pkg) => Semver.prerelease(pkg.version) !== null) |
| 46 | if (prereleases.length > 0) { |
| 47 | yield* Console.log(`Skipping promotion of prerelease versions: ${prereleases.map(format).join(", ")}`) |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | const bump = yield* Workspace.versionBump(effect.directory) |
| 52 | if (Option.isNone(bump)) { |
| 53 | return yield* new NpmPromoteError({ message: "Could not find the commit that bumped the effect version" }) |
| 54 | } |
| 55 | |
| 56 | // Real runs need GitHub to record deploys and track overdue releases, so missing configuration fails up front. |
| 57 | const services = options.dryRun ? layerDryRun : yield* githubConfig.pipe( |
| 58 | Effect.map(({ dispatchToken, github }) => |
| 59 | Layer.mergeAll(Website.layerGitHub(github, dispatchToken), Alerts.layerGitHub(github)) |
| 60 | ), |
| 61 | Effect.mapError((cause) => |
| 62 | new NpmPromoteError({ |
| 63 | message: "GITHUB_REPOSITORY, GITHUB_TOKEN and WEBSITE_DISPATCH_TOKEN are required unless --dry-run is set", |
| 64 | cause |
| 65 | }) |
| 66 | ) |
| 67 | ) |
| 68 | |
| 69 | yield* promoteRelease({ |
| 70 | packages: workspace.map(({ name, version }): ReleasePackage => ({ name, version })), |
| 71 | bump: bump.value |
| 72 | }, options).pipe(Effect.provide(services)) |
| 73 | }) |
| 74 | |
| 75 | export const cli = Command.make("npm-promote", { dryRun, overdueAfterHours }).pipe( |
| 76 | Command.withDescription("Move the latest dist-tag to the staged release once every package is visible on npm"), |
| 77 | Command.withHandler(run) |
| 78 | ) |