publish.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 = `
  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. console.log("=== publishing ===\n")
  28. const pkgjsons = await Array.fromAsync(
  29. new Bun.Glob("**/package.json").scan({
  30. absolute: true,
  31. }),
  32. ).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
  33. for (const file of pkgjsons) {
  34. let pkg = await Bun.file(file).text()
  35. pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
  36. console.log("updated:", file)
  37. await Bun.file(file).write(pkg)
  38. }
  39. const extensionToml = new URL("../packages/extensions/zed/extension.toml", import.meta.url).pathname
  40. let toml = await Bun.file(extensionToml).text()
  41. toml = toml.replace(/^version = "[^"]+"/m, `version = "${Script.version}"`)
  42. toml = toml.replaceAll(/releases\/download\/v[^/]+\//g, `releases/download/v${Script.version}/`)
  43. console.log("updated:", extensionToml)
  44. await Bun.file(extensionToml).write(toml)
  45. await $`bun install`
  46. await import(`../packages/sdk/js/script/build.ts`)
  47. if (Script.release) {
  48. const previous = await getLatestRelease()
  49. const notes = await buildNotes(previous, "HEAD")
  50. // notes.unshift(highlightsTemplate)
  51. await $`git commit -am "release: v${Script.version}"`
  52. await $`git tag v${Script.version}`
  53. await $`git fetch origin`
  54. await $`git cherry-pick HEAD..origin/dev`.nothrow()
  55. await $`git push origin HEAD --tags --no-verify --force-with-lease`
  56. await new Promise((resolve) => setTimeout(resolve, 5_000))
  57. await $`gh release edit v${Script.version} --draft=false --title "v${Script.version}" --notes ${notes.join("\n") || "No notable changes"}`
  58. }
  59. console.log("\n=== cli ===\n")
  60. await import(`../packages/opencode/script/publish.ts`)
  61. console.log("\n=== sdk ===\n")
  62. await import(`../packages/sdk/js/script/publish.ts`)
  63. console.log("\n=== plugin ===\n")
  64. await import(`../packages/plugin/script/publish.ts`)
  65. const dir = new URL("..", import.meta.url).pathname
  66. process.chdir(dir)