publish.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. await $`bun install`
  26. console.log("\n=== opencode ===\n")
  27. await import(`../packages/opencode/script/publish.ts`)
  28. console.log("\n=== sdk ===\n")
  29. await import(`../packages/sdk/js/script/publish.ts`)
  30. console.log("\n=== plugin ===\n")
  31. await import(`../packages/plugin/script/publish.ts`)
  32. if (!snapshot) {
  33. await $`git commit -am "release: v${version}"`
  34. await $`git tag v${version}`
  35. await $`git push origin HEAD --tags --no-verify`
  36. }
  37. if (snapshot) {
  38. await $`git checkout -b snapshot-${version}`
  39. await $`git commit --allow-empty -m "Snapshot release v${version}"`
  40. await $`git tag v${version}`
  41. await $`git push origin v${version} --no-verify`
  42. await $`git checkout dev`
  43. await $`git branch -D snapshot-${version}`
  44. for (const file of pkgjsons) {
  45. await $`git checkout ${tree} ${file}`
  46. }
  47. }