publish-start.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. const skipNotes = process.env["KILO_SKIP_NOTES"] === "1" // kilocode_change
  30. if (skipNotes) console.log("changelog skipped: KILO_SKIP_NOTES=1") // kilocode_change
  31. if (!Script.preview && !skipNotes) {
  32. const previous = await getLatestRelease()
  33. notes = await buildNotes(previous, "HEAD")
  34. // notes.unshift(highlightsTemplate)
  35. }
  36. const pkgjsons = await Array.fromAsync(
  37. new Bun.Glob("**/package.json").scan({
  38. absolute: true,
  39. }),
  40. ).then((arr) => arr.filter((x) => !x.includes("node_modules") && !x.includes("dist")))
  41. for (const file of pkgjsons) {
  42. let pkg = await Bun.file(file).text()
  43. pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
  44. console.log("updated:", file)
  45. await Bun.file(file).write(pkg)
  46. }
  47. const extensionToml = new URL("../packages/extensions/zed/extension.toml", import.meta.url).pathname
  48. let toml = await Bun.file(extensionToml).text()
  49. toml = toml.replace(/^version = "[^"]+"/m, `version = "${Script.version}"`)
  50. toml = toml.replaceAll(/releases\/download\/v[^/]+\//g, `releases/download/v${Script.version}/`)
  51. console.log("updated:", extensionToml)
  52. await Bun.file(extensionToml).write(toml)
  53. await $`bun install`
  54. console.log("\n=== opencode ===\n")
  55. await import(`../packages/opencode/script/legacy-publish.ts`)
  56. console.log("\n=== sdk ===\n")
  57. await import(`../packages/sdk/js/script/publish.ts`)
  58. console.log("\n=== plugin ===\n")
  59. await import(`../packages/plugin/script/publish.ts`)
  60. const dir = new URL("..", import.meta.url).pathname
  61. process.chdir(dir)
  62. let output = `version=${Script.version}\n`
  63. if (!Script.preview) {
  64. await $`git commit -am "release: v${Script.version}"`
  65. await $`git tag v${Script.version}`
  66. await $`git fetch origin`
  67. await $`git cherry-pick HEAD..origin/main`.nothrow()
  68. await $`git push origin HEAD --tags --no-verify --force-with-lease`
  69. await new Promise((resolve) => setTimeout(resolve, 5_000))
  70. // kilocode_change start - skip draft flag when KILO_SKIP_NOTES=1 (used by publish-stable.yml which doesn't have a publish-complete step)
  71. const draftFlag = skipNotes ? [] : ["-d"]
  72. await $`gh release create v${Script.version} ${draftFlag} --title "v${Script.version}" --notes ${notes.join("\n") || "No notable changes"} ./packages/opencode/dist/archives/*.zip ./packages/opencode/dist/archives/*.tar.gz`
  73. // kilocode_change end
  74. const release = await $`gh release view v${Script.version} --json id,tagName`.json()
  75. output += `release=${release.id}\n`
  76. output += `tag=${release.tagName}\n`
  77. }
  78. if (process.env.GITHUB_OUTPUT) {
  79. await Bun.write(process.env.GITHUB_OUTPUT, output)
  80. }