publish-start.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import { Script } from "@opencode-ai/script"
  4. import { buildNotes, getLatestRelease } from "./changelog"
  5. const highlightsTemplate = `## Highlights
  6. <!--
  7. Add highlights before publishing. Delete this section if no highlights.
  8. - For multiple highlights, use multiple <highlight> tags
  9. - Highlights with the same source attribute get grouped together
  10. -->
  11. <!--
  12. <highlight source="SourceName (TUI/Desktop/Web/Core)">
  13. <h2>Feature title goes here</h2>
  14. <p short="Short description used for Desktop Recap">
  15. Full description of the feature or change
  16. </p>
  17. https://github.com/user-attachments/assets/uuid-for-video (you will want to drag & drop the video or picture)
  18. <img
  19. width="1912"
  20. height="1164"
  21. alt="image"
  22. src="https://github.com/user-attachments/assets/uuid-for-image"
  23. />
  24. </highlight>
  25. -->
  26. `
  27. let notes: string[] = []
  28. console.log("=== publishing ===\n")
  29. if (!Script.preview) {
  30. const previous = await getLatestRelease()
  31. notes = await buildNotes(previous, "HEAD")
  32. notes.unshift(highlightsTemplate)
  33. }
  34. const pkgjsons = await Array.fromAsync(
  35. new Bun.Glob("**/package.json").scan({
  36. absolute: true,
  37. }),
  38. ).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
  39. for (const file of pkgjsons) {
  40. let pkg = await Bun.file(file).text()
  41. pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
  42. console.log("updated:", file)
  43. await Bun.file(file).write(pkg)
  44. }
  45. const extensionToml = new URL("../packages/extensions/zed/extension.toml", import.meta.url).pathname
  46. let toml = await Bun.file(extensionToml).text()
  47. toml = toml.replace(/^version = "[^"]+"/m, `version = "${Script.version}"`)
  48. toml = toml.replaceAll(/releases\/download\/v[^/]+\//g, `releases/download/v${Script.version}/`)
  49. console.log("updated:", extensionToml)
  50. await Bun.file(extensionToml).write(toml)
  51. await $`bun install`
  52. console.log("\n=== opencode ===\n")
  53. await import(`../packages/opencode/script/publish.ts`)
  54. console.log("\n=== sdk ===\n")
  55. await import(`../packages/sdk/js/script/publish.ts`)
  56. console.log("\n=== plugin ===\n")
  57. await import(`../packages/plugin/script/publish.ts`)
  58. const dir = new URL("..", import.meta.url).pathname
  59. process.chdir(dir)
  60. let output = `version=${Script.version}\n`
  61. if (!Script.preview) {
  62. await $`git commit -am "release: v${Script.version}"`
  63. await $`git tag v${Script.version}`
  64. await $`git fetch origin`
  65. await $`git cherry-pick HEAD..origin/dev`.nothrow()
  66. await $`git push origin HEAD --tags --no-verify --force-with-lease`
  67. await new Promise((resolve) => setTimeout(resolve, 5_000))
  68. await $`gh release create v${Script.version} -d --title "v${Script.version}" --notes ${notes.join("\n") || "No notable changes"} ./packages/opencode/dist/*.zip ./packages/opencode/dist/*.tar.gz`
  69. const release = await $`gh release view v${Script.version} --json id,tagName`.json()
  70. output += `release=${release.id}\n`
  71. output += `tag=${release.tagName}\n`
  72. }
  73. if (process.env.GITHUB_OUTPUT) {
  74. await Bun.write(process.env.GITHUB_OUTPUT, output)
  75. }