publish.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 commit --allow-empty -m "Snapshot release v${version}"`
  35. await $`git tag v${version}`
  36. await $`git push origin v${version} --no-verify`
  37. await $`git reset --soft HEAD~1`
  38. for await (const file of new Bun.Glob("**/package.json").scan({
  39. absolute: true,
  40. })) {
  41. $`await git checkout ${tree} ${file}`
  42. }
  43. }