opencode/packages/desktop/scripts/beta-notes.ts
Dax Raad 776186fda2
Some checks are pending
deploy / deploy (push) Waiting to run
publish / version (push) Waiting to run
publish / build-cli (push) Blocked by required conditions
publish / build-cli-beta (darwin-arm64) (push) Blocked by required conditions
publish / build-cli-beta (darwin-x64-baseline) (push) Blocked by required conditions
publish / build-cli-beta (linux-arm64) (push) Blocked by required conditions
publish / build-cli-beta (linux-x64-baseline) (push) Blocked by required conditions
publish / build-cli-beta (windows-arm64) (push) Blocked by required conditions
publish / build-cli-beta (windows-x64-baseline) (push) Blocked by required conditions
publish / sign-cli-macos (push) Blocked by required conditions
publish / build-node-app-archive (push) Blocked by required conditions
publish / build-node-cli (map[bun_install_flags:--cpu=* host:blacksmith-4vcpu-windows-2025 target:windows-arm64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404 target:linux-x64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404-arm target:linux-arm64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:blacksmith-4vcpu-windows-2025 target:windows-x64]) (push) Blocked by required conditions
publish / build-node-cli (map[host:macos-26 target:darwin-arm64]) (push) Blocked by required conditions
publish / sign-cli-windows (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:${{ (github.ref_name == 'beta' && '--os=darwin --cpu=*') || '--os=darwin --cpu=x64' }} cli:darwin-x64-baseline host:${{ (github.ref_name == 'beta' && 'macos-26') || 'macos-26-intel' }} platform_flag:--mac --x64 tar… (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--cpu=* cli:windows-arm64 host:${{ (github.ref_name == 'beta' && 'blacksmith-4vcpu-windows-2025') || 'windows-2025' }} platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Blocked by required conditions
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 cli:darwin-arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Blocked by required conditions
publish / build-electron (map[cli:linux-arm64 host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[cli:linux-x64-baseline host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Blocked by required conditions
publish / build-electron (map[cli:windows-x64-baseline host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Blocked by required conditions
publish / publish (push) Blocked by required conditions
publish / notify-discord-v2 (push) Blocked by required conditions
feat(desktop): show beta changes after updates
Beta builds embed their commit and the feat, fix and perf commits among their newest 200. The app remembers the commit of the build the user last saw and, after an update, shows the changes since then in a What's new in beta dialog. No network calls and no update service changes. The first update after rollout only records the commit.
2026-10-19 11:07:37 -04:00

90 lines
3 KiB
TypeScript

// The user-facing changes compiled into a beta build: the build's commit, the newest commits of its history, and the
// feat, fix and perf commits among them. electron.vite.config.ts embeds them in the renderer as
// import.meta.env.OPENCODE_BETA_NOTES; the updater's "What's new in beta" dialog lists the ones after the commit of the
// build the user saw last.
// Usage: bun scripts/beta-notes.ts [head]
export * as BetaNotes from "./beta-notes"
import { execFileSync } from "node:child_process"
export type BetaNote = {
type: "feat" | "fix" | "perf"
scope?: string
summary: string
breaking?: true
pr?: number
sha: string
}
/** How many commits of history a build carries. A previous build further back shows the newest notes instead. */
const LIMIT = 200
/** Commits are identified by this many hex digits, enough to be unique in this repository. */
const SHORT = 12
const KEPT = new Set(["feat", "fix", "perf"])
const FIELD = "\x1f"
const RECORD = "\x1e"
/**
* Reads the commit `head` resolves to (GITHUB_SHA in CI) and its newest commits, newest first: every commit's short
* sha, merges included so a previous build at a merge is found, and the notes of the non-merge feat, fix and perf ones.
*/
export function embed(input: { head?: string; cwd?: string } = {}) {
// electron-vite loads its config, which calls this, in Node, so this cannot use Bun's shell.
const git = (...args: string[]) => execFileSync("git", args, { cwd: input.cwd, encoding: "utf8" })
const sha = git("rev-parse", input.head ?? process.env.GITHUB_SHA ?? "HEAD").trim()
const log = git("log", "--topo-order", `--max-count=${LIMIT}`, `--format=%H${FIELD}%P${FIELD}%s${RECORD}`, sha)
const records = log
.split(RECORD)
.map((record) => record.trim().split(FIELD))
.filter((fields) => fields.length === 3 && fields[0])
return {
sha,
commits: records.map(([commit]) => commit!.slice(0, SHORT)),
notes: records.flatMap(([commit, parents, subject]): BetaNote[] => {
// A merge commit repeats the commits it merges.
if (parents!.trim().split(/\s+/).length > 1) return []
const note = parseSubject(subject!)
return note ? [{ ...note, sha: commit!.slice(0, SHORT) }] : []
}),
}
}
/** Parses a conventional commit header `type(scope)!: summary (#123)`; anything else is not a note. */
export function parseSubject(subject: string) {
const match = subject.trim().match(/^(\w+)(?:\(([^)]*)\))?(!)?:\s*(.+)$/)
const type = match?.[1]?.toLowerCase()
if (!match || !type || !isKept(type)) return undefined
const pr = match[4]!.match(/\s*\(#(\d+)\)\s*$/)
const summary = (pr ? match[4]!.slice(0, pr.index) : match[4]!).trim()
if (!summary) return undefined
const note: Omit<BetaNote, "sha"> = { type, summary }
const scope = match[2]?.trim()
if (scope) note.scope = scope
if (match[3]) note.breaking = true
if (pr) note.pr = Number(pr[1])
return note
}
function isKept(type: string): type is BetaNote["type"] {
return KEPT.has(type)
}
if (import.meta.main) console.log(JSON.stringify(embed({ head: process.argv[2] }), null, 2))