mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
136 lines
4.8 KiB
TypeScript
Executable file
136 lines
4.8 KiB
TypeScript
Executable file
#!/usr/bin/env bun
|
|
|
|
import { Script } from "@opencode/script"
|
|
import { $ } from "bun"
|
|
import os from "os"
|
|
import path from "path"
|
|
import { fileURLToPath } from "url"
|
|
|
|
console.log("=== publishing ===\n")
|
|
|
|
const dir = fileURLToPath(new URL("..", import.meta.url))
|
|
process.chdir(dir)
|
|
const tag = `v${Script.version}`
|
|
|
|
const pkgjsons = await Array.fromAsync(
|
|
new Bun.Glob("**/package.json").scan({
|
|
absolute: true,
|
|
}),
|
|
).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
|
|
|
|
async function prepareReleaseFiles() {
|
|
for (const file of pkgjsons) {
|
|
let pkg = await Bun.file(file).text()
|
|
pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
|
|
console.log("updated:", file)
|
|
await Bun.file(file).write(pkg)
|
|
}
|
|
|
|
await $`bun install`
|
|
}
|
|
|
|
async function writeChangelog() {
|
|
const notes = process.env["OPENCODE_RELEASE_NOTES"]?.trim()
|
|
if (!notes) return
|
|
const file = Bun.file("CHANGELOG.md")
|
|
const text = await file.text()
|
|
const lines = text.split("\n")
|
|
if (lines.some((line) => line === `## ${tag}` || line.startsWith(`## ${tag} `))) return
|
|
const index = lines.findIndex((line) => line.startsWith("## "))
|
|
const head = (index === -1 ? lines : lines.slice(0, index)).join("\n").trimEnd()
|
|
const rest = index === -1 ? "" : lines.slice(index).join("\n")
|
|
const entry = `## ${tag} — ${new Date().toISOString().slice(0, 10)}\n\n${notes}\n`
|
|
await file.write(`${head}\n\n${entry}${rest ? `\n${rest}` : ""}`)
|
|
}
|
|
|
|
if (Script.release && !Script.preview) {
|
|
await $`git fetch origin --tags`
|
|
await $`git switch --detach`
|
|
}
|
|
|
|
await prepareReleaseFiles()
|
|
|
|
if (Script.release) await $`bun ./packages/desktop/scripts/publish.ts --dry-run`
|
|
|
|
console.log("\n=== schema ===\n")
|
|
await $`bun ./packages/schema/script/publish.ts`
|
|
|
|
console.log("\n=== codemode ===\n")
|
|
await $`bun ./packages/codemode/script/publish.ts`
|
|
|
|
console.log("\n=== theme ===\n")
|
|
await $`bun ./packages/theme/script/publish.ts`
|
|
|
|
console.log("\n=== ai ===\n")
|
|
await $`bun ./packages/ai/script/publish.ts`
|
|
|
|
console.log("\n=== util ===\n")
|
|
await $`bun ./packages/util/script/publish.ts`
|
|
|
|
console.log("\n=== protocol ===\n")
|
|
await $`bun ./packages/protocol/script/publish.ts`
|
|
|
|
console.log("\n=== client ===\n")
|
|
await $`bun ./packages/client/script/publish.ts`
|
|
|
|
console.log("\n=== cli ===\n")
|
|
await $`bun ./packages/cli/script/publish.ts`
|
|
|
|
console.log("\n=== plugin ===\n")
|
|
await $`bun ./packages/plugin/script/publish.ts`
|
|
|
|
console.log("\n=== plugin-browser ===\n")
|
|
await $`bun ./packages/plugin-browser/script/publish.ts`
|
|
|
|
console.log("\n=== core ===\n")
|
|
await $`bun ./packages/core/script/publish.ts`
|
|
|
|
console.log("\n=== simulation ===\n")
|
|
await $`bun ./packages/simulation/script/publish.ts`
|
|
|
|
console.log("\n=== server ===\n")
|
|
await $`bun ./packages/server/script/publish.ts`
|
|
|
|
console.log("\n=== sdk ===\n")
|
|
await $`bun ./packages/sdk/script/publish.ts`
|
|
|
|
console.log("\n=== ui ===\n")
|
|
await $`bun ./packages/ui/script/publish.ts`
|
|
|
|
if (Script.release && !Script.preview) {
|
|
if ((await $`git diff --quiet`.nothrow()).exitCode !== 0) await $`git commit -am "release: ${tag}"`
|
|
await $`git tag -d ${tag}`.nothrow()
|
|
await $`git tag ${tag}`
|
|
await $`git push origin refs/tags/${tag} --force-with-lease --no-verify`
|
|
await new Promise((resolve) => setTimeout(resolve, 5_000))
|
|
await $`git fetch origin`
|
|
await $`git checkout -B dev origin/dev`
|
|
await prepareReleaseFiles()
|
|
await writeChangelog()
|
|
if ((await $`git diff --quiet`.nothrow()).exitCode !== 0) {
|
|
// The release already published this code; a push-triggered dev publish of a version bump is wasted work.
|
|
await $`git commit -am ${`sync release versions for ${tag} [skip ci]`}`
|
|
await $`git push origin HEAD:dev --no-verify`
|
|
}
|
|
}
|
|
|
|
if (Script.release) {
|
|
console.log("\n=== desktop ===\n")
|
|
await $`bun ./packages/desktop/scripts/publish.ts`
|
|
}
|
|
|
|
// Gated by the OPENCODE_V2_GITHUB_RELEASES repository variable so the V1/V2 rollout controls when this starts.
|
|
// See docs/release/v1-v2-isolation.md.
|
|
if (Script.release && !Script.preview && process.env["OPENCODE_GITHUB_RELEASE"] === "true") {
|
|
console.log("\n=== github release ===\n")
|
|
// OpenCode 1 clients and installers resolve updates through GitHub's Latest release, so V2 releases
|
|
// never take that flag and carry no assets. The publish workflow verifies Latest afterwards.
|
|
const notes = process.env["OPENCODE_RELEASE_NOTES"]?.trim() ?? ""
|
|
const file = path.join(os.tmpdir(), `opencode-release-notes-${tag}.md`)
|
|
await Bun.write(file, notes)
|
|
if ((await $`gh release view ${tag} --json tagName`.quiet().nothrow()).exitCode === 0) {
|
|
await $`gh release edit ${tag} --title ${tag} --draft=false --prerelease=false --latest=false ${notes ? ["--notes-file", file] : []}`
|
|
} else {
|
|
await $`gh release create ${tag} --verify-tag --title ${tag} --notes-file ${file} --latest=false`
|
|
}
|
|
}
|