publish.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
  4. const version = snapshot
  5. ? `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
  6. : process.env["OPENCODE_VERSION"]
  7. if (!version) {
  8. throw new Error("OPENCODE_VERSION is required")
  9. }
  10. process.env["OPENCODE_VERSION"] = version
  11. const pkgjsons = await Array.fromAsync(
  12. new Bun.Glob("**/package.json").scan({
  13. absolute: true,
  14. }),
  15. )
  16. const tree = await $`git add . && git write-tree`.text().then((x) => x.trim())
  17. for await (const file of new Bun.Glob("**/package.json").scan({
  18. absolute: true,
  19. })) {
  20. let pkg = await Bun.file(file).text()
  21. pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${version}"`)
  22. await Bun.file(file).write(pkg)
  23. }
  24. await import(`../packages/opencode/script/publish.ts`)
  25. await import(`../packages/sdk/js/script/publish.ts`)
  26. await import(`../packages/plugin/script/publish.ts`)
  27. // await import(`../packages/sdk/stainless/generate.ts`)
  28. if (!snapshot) {
  29. await $`git commit -am "release: v${version}"`
  30. await $`git tag v${version}`
  31. await $`git push origin HEAD --tags --no-verify`
  32. }
  33. if (snapshot) {
  34. await $`git checkout -b snapshot-${version}`
  35. await $`git commit --allow-empty -m "Snapshot release v${version}"`
  36. await $`git tag v${version}`
  37. await $`git push origin v${version} --no-verify`
  38. await $`git checkout dev`
  39. await $`git branch -D snapshot-${version}`
  40. for await (const file of new Bun.Glob("**/package.json").scan({
  41. absolute: true,
  42. })) {
  43. $`await git checkout ${tree} ${file}`
  44. }
  45. }