publish.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env bun
  2. import { Script } from "@opencode-ai/script"
  3. import { $ } from "bun"
  4. import { fileURLToPath } from "url"
  5. import { UpdateArtifact } from "./update-artifact"
  6. console.log("=== publishing ===\n")
  7. const dir = fileURLToPath(new URL("..", import.meta.url))
  8. process.chdir(dir)
  9. const tag = `v${Script.version}`
  10. const pkgjsons = await Array.fromAsync(
  11. new Bun.Glob("**/package.json").scan({
  12. absolute: true,
  13. }),
  14. ).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
  15. async function prepareReleaseFiles() {
  16. for (const file of pkgjsons) {
  17. let pkg = await Bun.file(file).text()
  18. pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
  19. console.log("updated:", file)
  20. await Bun.file(file).write(pkg)
  21. }
  22. await $`bun install`
  23. }
  24. if (Script.release && !Script.preview) {
  25. await $`git fetch origin --tags`
  26. await $`git switch --detach`
  27. }
  28. await prepareReleaseFiles()
  29. console.log("\n=== schema ===\n")
  30. await $`bun ./packages/schema/script/publish.ts`
  31. console.log("\n=== theme ===\n")
  32. await $`bun ./packages/theme/script/publish.ts`
  33. console.log("\n=== ai ===\n")
  34. await $`bun ./packages/ai/script/publish.ts`
  35. console.log("\n=== util ===\n")
  36. await $`bun ./packages/util/script/publish.ts`
  37. console.log("\n=== protocol ===\n")
  38. await $`bun ./packages/protocol/script/publish.ts`
  39. console.log("\n=== client ===\n")
  40. await $`bun ./packages/client/script/publish.ts`
  41. console.log("\n=== cli ===\n")
  42. await $`bun ./packages/cli/script/publish.ts`
  43. console.log("\n=== plugin ===\n")
  44. await $`bun ./packages/plugin/script/publish.ts`
  45. console.log("\n=== ui ===\n")
  46. await $`bun ./packages/ui/script/publish.ts`
  47. if (Script.release) {
  48. await $`bun ./packages/desktop/scripts/finalize-latest-json.ts`
  49. await $`bun ./packages/desktop/scripts/finalize-latest-yml.ts`
  50. }
  51. if (Script.release && !Script.preview) {
  52. await $`git commit -am "release: ${tag}"`
  53. await $`git tag -d ${tag}`.nothrow()
  54. await $`git tag ${tag}`
  55. await $`git push origin refs/tags/${tag} --force-with-lease --no-verify`
  56. await new Promise((resolve) => setTimeout(resolve, 5_000))
  57. await $`git fetch origin`
  58. await $`git checkout -B dev origin/dev`
  59. await prepareReleaseFiles()
  60. await $`git commit -am "sync release versions for ${tag}"`
  61. await $`git push origin HEAD:dev --no-verify`
  62. }
  63. if (Script.release) {
  64. await $`gh release edit ${tag} --draft=false --repo ${process.env.GH_REPO}`
  65. const repo = process.env.GH_REPO
  66. if (!repo) throw new Error("GH_REPO is required")
  67. await UpdateArtifact.publish({
  68. channel: Script.channel,
  69. name: "desktop",
  70. distribution: "github",
  71. version: Script.version,
  72. metadata: await UpdateArtifact.desktopMetadata(Script.version, repo),
  73. })
  74. }