opencode/script/publish.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-07-25 03:51:33 +08:00
#!/usr/bin/env bun
import { $ } from "bun"
2025-07-31 13:00:29 +08:00
const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
const version = snapshot
? `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
: process.env["OPENCODE_VERSION"]
if (!version) {
throw new Error("OPENCODE_VERSION is required")
}
process.env["OPENCODE_VERSION"] = version
2025-07-25 03:51:33 +08:00
2025-08-03 06:50:19 +08:00
const pkgjsons = await Array.fromAsync(
new Bun.Glob("**/package.json").scan({
absolute: true,
}),
)
const tree = await $`git add . && git write-tree`.text().then((x) => x.trim())
for await (const file of new Bun.Glob("**/package.json").scan({
absolute: true,
})) {
let pkg = await Bun.file(file).text()
pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${version}"`)
await Bun.file(file).write(pkg)
}
2025-08-03 06:54:57 +08:00
await import(`../packages/opencode/script/publish.ts`)
2025-07-31 21:46:36 +08:00
await import(`../packages/sdk/js/script/publish.ts`)
2025-08-03 06:50:19 +08:00
await import(`../packages/plugin/script/publish.ts`)
2025-07-31 13:42:52 +08:00
// await import(`../packages/sdk/stainless/generate.ts`)
2025-07-25 03:51:33 +08:00
2025-07-31 13:00:29 +08:00
if (!snapshot) {
2025-08-01 07:57:07 +08:00
await $`git commit -am "release: v${version}"`
2025-07-31 13:00:29 +08:00
await $`git tag v${version}`
2025-08-03 06:50:19 +08:00
await $`git push origin HEAD --tags --no-verify`
2025-07-31 13:00:29 +08:00
}
if (snapshot) {
2025-08-03 06:54:57 +08:00
await $`git checkout -b snapshot-${version}`
2025-07-31 13:00:29 +08:00
await $`git commit --allow-empty -m "Snapshot release v${version}"`
await $`git tag v${version}`
2025-08-03 06:50:19 +08:00
await $`git push origin v${version} --no-verify`
2025-08-03 06:54:57 +08:00
await $`git checkout dev`
await $`git branch -D snapshot-${version}`
2025-08-03 06:50:19 +08:00
for await (const file of new Bun.Glob("**/package.json").scan({
absolute: true,
})) {
$`await git checkout ${tree} ${file}`
}
2025-07-31 13:00:29 +08:00
}