ci: stuff

This commit is contained in:
Dax Raad
2025-10-14 14:34:19 -04:00
parent 717b544633
commit 0c022ef39d
11 changed files with 107 additions and 74 deletions

View File

@@ -2,34 +2,13 @@
import { $ } from "bun"
import { createOpencode } from "@opencode-ai/sdk"
if (process.versions.bun !== "1.3.0") {
throw new Error("This script requires bun@1.3.0")
}
import { Script } from "@opencode-ai/script"
const notes = [] as string[]
console.log("=== publishing ===\n")
const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
const version = await (async () => {
if (snapshot) return `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
if (process.env["OPENCODE_VERSION"]) return process.env["OPENCODE_VERSION"]
const npmVersion = await fetch("https://registry.npmjs.org/opencode-ai/latest")
.then((res) => {
if (!res.ok) throw new Error(res.statusText)
return res.json()
})
.then((data: any) => data.version)
const [major, minor, patch] = npmVersion.split(".").map((x: string) => Number(x) || 0)
const t = process.env["OPENCODE_BUMP"]?.toLowerCase()
if (t === "major") return `${major + 1}.0.0`
if (t === "minor") return `${major}.${minor + 1}.0`
return `${major}.${minor}.${patch + 1}`
})()
process.env["OPENCODE_VERSION"] = version
console.log("version:", version)
if (!snapshot) {
if (!Script.preview) {
const previous = await fetch("https://registry.npmjs.org/opencode-ai/latest")
.then((res) => {
if (!res.ok) throw new Error(res.statusText)
@@ -98,7 +77,7 @@ const pkgjsons = await Array.fromAsync(
const tree = await $`git add . && git write-tree`.text().then((x) => x.trim())
for (const file of pkgjsons) {
let pkg = await Bun.file(file).text()
pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${version}"`)
pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
console.log("updated:", file)
await Bun.file(file).write(pkg)
}
@@ -116,22 +95,22 @@ await import(`../packages/plugin/script/publish.ts`)
const dir = new URL("..", import.meta.url).pathname
process.chdir(dir)
if (!snapshot) {
await $`git commit -am "release: v${version}"`
await $`git tag v${version}`
if (!Script.preview) {
await $`git commit -am "release: v${Script.version}"`
await $`git tag v${Script.version}`
await $`git fetch origin`
await $`git cherry-pick HEAD..origin/dev`.nothrow()
await $`git push origin HEAD --tags --no-verify --force`
await $`gh release create v${version} --title "v${version}" --notes ${notes.join("\n") ?? "No notable changes"} ./packages/opencode/dist/*.zip`
await $`gh release create v${Script.version} --title "v${Script.version}" --notes ${notes.join("\n") ?? "No notable changes"} ./packages/opencode/dist/*.zip`
}
if (snapshot) {
await $`git checkout -b snapshot-${version}`
await $`git commit --allow-empty -m "Snapshot release v${version}"`
await $`git tag v${version}`
await $`git push origin v${version} --no-verify`
if (Script.preview) {
await $`git checkout -b snapshot-${Script.version}`
await $`git commit --allow-empty -m "Snapshot release v${Script.version}"`
await $`git tag v${Script.version}`
await $`git push origin v${Script.version} --no-verify`
await $`git checkout dev`
await $`git branch -D snapshot-${version}`
await $`git branch -D snapshot-${Script.version}`
for (const file of pkgjsons) {
await $`git checkout ${tree} ${file}`
}