publish.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. console.log("=== publishing ===\n")
  4. const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
  5. const version = snapshot
  6. ? `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
  7. : process.env["OPENCODE_VERSION"]
  8. if (!version) {
  9. throw new Error("OPENCODE_VERSION is required")
  10. }
  11. process.env["OPENCODE_VERSION"] = version
  12. console.log("version:", version)
  13. const pkgjsons = await Array.fromAsync(
  14. new Bun.Glob("**/package.json").scan({
  15. absolute: true,
  16. }),
  17. ).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
  18. const tree = await $`git add . && git write-tree`.text().then((x) => x.trim())
  19. for (const file of pkgjsons) {
  20. let pkg = await Bun.file(file).text()
  21. pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${version}"`)
  22. console.log("updated:", file)
  23. await Bun.file(file).write(pkg)
  24. }
  25. console.log("\n=== opencode ===\n")
  26. await import(`../packages/opencode/script/publish.ts`)
  27. console.log("\n=== sdk ===\n")
  28. await import(`../packages/sdk/js/script/publish.ts`)
  29. console.log("\n=== plugin ===\n")
  30. await import(`../packages/plugin/script/publish.ts`)
  31. if (!snapshot) {
  32. await $`git commit -am "release: v${version}"`
  33. await $`git tag v${version}`
  34. await $`git push origin HEAD --tags --no-verify`
  35. }
  36. if (snapshot) {
  37. await $`git checkout -b snapshot-${version}`
  38. await $`git commit --allow-empty -m "Snapshot release v${version}"`
  39. await $`git tag v${version}`
  40. await $`git push origin v${version} --no-verify`
  41. await $`git checkout dev`
  42. await $`git branch -D snapshot-${version}`
  43. for (const file of pkgjsons) {
  44. await $`git checkout ${tree} ${file}`
  45. }
  46. }