publish-registries.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import { Script } from "@opencode-ai/script"
  4. if (!Script.preview) {
  5. // Calculate SHA values
  6. const arm64Sha = await $`sha256sum ./dist/opencode-linux-arm64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
  7. const x64Sha = await $`sha256sum ./dist/opencode-linux-x64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
  8. const macX64Sha = await $`sha256sum ./dist/opencode-darwin-x64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
  9. const macArm64Sha = await $`sha256sum ./dist/opencode-darwin-arm64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
  10. const [pkgver, _subver = ""] = Script.version.split(/(-.*)/, 2)
  11. // arch
  12. const binaryPkgbuild = [
  13. "# Maintainer: dax",
  14. "# Maintainer: adam",
  15. "",
  16. "pkgname='opencode-bin'",
  17. `pkgver=${pkgver}`,
  18. `_subver=${_subver}`,
  19. "options=('!debug' '!strip')",
  20. "pkgrel=1",
  21. "pkgdesc='The AI coding agent built for the terminal.'",
  22. "url='https://github.com/anomalyco/opencode'",
  23. "arch=('aarch64' 'x86_64')",
  24. "license=('MIT')",
  25. "provides=('opencode')",
  26. "conflicts=('opencode')",
  27. "depends=('ripgrep')",
  28. "",
  29. `source_aarch64=("\${pkgname}_\${pkgver}_aarch64.tar.gz::https://github.com/anomalyco/opencode/releases/download/v\${pkgver}\${_subver}/opencode-linux-arm64.tar.gz")`,
  30. `sha256sums_aarch64=('${arm64Sha}')`,
  31. `source_x86_64=("\${pkgname}_\${pkgver}_x86_64.tar.gz::https://github.com/anomalyco/opencode/releases/download/v\${pkgver}\${_subver}/opencode-linux-x64.tar.gz")`,
  32. `sha256sums_x86_64=('${x64Sha}')`,
  33. "",
  34. "package() {",
  35. ' install -Dm755 ./opencode "${pkgdir}/usr/bin/opencode"',
  36. "}",
  37. "",
  38. ].join("\n")
  39. // Source-based PKGBUILD for opencode
  40. const sourcePkgbuild = [
  41. "# Maintainer: dax",
  42. "# Maintainer: adam",
  43. "",
  44. "pkgname='opencode'",
  45. `pkgver=${pkgver}`,
  46. `_subver=${_subver}`,
  47. "options=('!debug' '!strip')",
  48. "pkgrel=1",
  49. "pkgdesc='The AI coding agent built for the terminal.'",
  50. "url='https://github.com/anomalyco/opencode'",
  51. "arch=('aarch64' 'x86_64')",
  52. "license=('MIT')",
  53. "provides=('opencode')",
  54. "conflicts=('opencode-bin')",
  55. "depends=('ripgrep')",
  56. "makedepends=('git' 'bun' 'go')",
  57. "",
  58. `source=("opencode-\${pkgver}.tar.gz::https://github.com/anomalyco/opencode/archive/v\${pkgver}\${_subver}.tar.gz")`,
  59. `sha256sums=('SKIP')`,
  60. "",
  61. "build() {",
  62. ` cd "opencode-\${pkgver}"`,
  63. ` bun install`,
  64. " cd ./packages/opencode",
  65. ` OPENCODE_CHANNEL=latest OPENCODE_VERSION=${pkgver} bun run ./script/build.ts --single`,
  66. "}",
  67. "",
  68. "package() {",
  69. ` cd "opencode-\${pkgver}/packages/opencode"`,
  70. ' mkdir -p "${pkgdir}/usr/bin"',
  71. ' target_arch="x64"',
  72. ' case "$CARCH" in',
  73. ' x86_64) target_arch="x64" ;;',
  74. ' aarch64) target_arch="arm64" ;;',
  75. ' *) printf "unsupported architecture: %s\\n" "$CARCH" >&2 ; return 1 ;;',
  76. " esac",
  77. ' libc=""',
  78. " if command -v ldd >/dev/null 2>&1; then",
  79. " if ldd --version 2>&1 | grep -qi musl; then",
  80. ' libc="-musl"',
  81. " fi",
  82. " fi",
  83. ' if [ -z "$libc" ] && ls /lib/ld-musl-* >/dev/null 2>&1; then',
  84. ' libc="-musl"',
  85. " fi",
  86. ' base=""',
  87. ' if [ "$target_arch" = "x64" ]; then',
  88. " if ! grep -qi avx2 /proc/cpuinfo 2>/dev/null; then",
  89. ' base="-baseline"',
  90. " fi",
  91. " fi",
  92. ' bin="dist/opencode-linux-${target_arch}${base}${libc}/bin/opencode"',
  93. ' if [ ! -f "$bin" ]; then',
  94. ' printf "unable to find binary for %s%s%s\\n" "$target_arch" "$base" "$libc" >&2',
  95. " return 1",
  96. " fi",
  97. ' install -Dm755 "$bin" "${pkgdir}/usr/bin/opencode"',
  98. "}",
  99. "",
  100. ].join("\n")
  101. for (const [pkg, pkgbuild] of [
  102. ["opencode-bin", binaryPkgbuild],
  103. ["opencode", sourcePkgbuild],
  104. ]) {
  105. for (let i = 0; i < 30; i++) {
  106. try {
  107. await $`rm -rf ./dist/aur-${pkg}`
  108. await $`git clone ssh://[email protected]/${pkg}.git ./dist/aur-${pkg}`
  109. await $`cd ./dist/aur-${pkg} && git checkout master`
  110. await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(pkgbuild)
  111. await $`cd ./dist/aur-${pkg} && makepkg --printsrcinfo > .SRCINFO`
  112. await $`cd ./dist/aur-${pkg} && git add PKGBUILD .SRCINFO`
  113. await $`cd ./dist/aur-${pkg} && git commit -m "Update to v${Script.version}"`
  114. await $`cd ./dist/aur-${pkg} && git push`
  115. break
  116. } catch (e) {
  117. continue
  118. }
  119. }
  120. }
  121. // Homebrew formula
  122. const homebrewFormula = [
  123. "# typed: false",
  124. "# frozen_string_literal: true",
  125. "",
  126. "# This file was generated by GoReleaser. DO NOT EDIT.",
  127. "class Opencode < Formula",
  128. ` desc "The AI coding agent built for the terminal."`,
  129. ` homepage "https://github.com/anomalyco/opencode"`,
  130. ` version "${Script.version.split("-")[0]}"`,
  131. "",
  132. ` depends_on "ripgrep"`,
  133. "",
  134. " on_macos do",
  135. " if Hardware::CPU.intel?",
  136. ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-darwin-x64.zip"`,
  137. ` sha256 "${macX64Sha}"`,
  138. "",
  139. " def install",
  140. ' bin.install "opencode"',
  141. " end",
  142. " end",
  143. " if Hardware::CPU.arm?",
  144. ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-darwin-arm64.zip"`,
  145. ` sha256 "${macArm64Sha}"`,
  146. "",
  147. " def install",
  148. ' bin.install "opencode"',
  149. " end",
  150. " end",
  151. " end",
  152. "",
  153. " on_linux do",
  154. " if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?",
  155. ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-linux-x64.tar.gz"`,
  156. ` sha256 "${x64Sha}"`,
  157. " def install",
  158. ' bin.install "opencode"',
  159. " end",
  160. " end",
  161. " if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?",
  162. ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-linux-arm64.tar.gz"`,
  163. ` sha256 "${arm64Sha}"`,
  164. " def install",
  165. ' bin.install "opencode"',
  166. " end",
  167. " end",
  168. " end",
  169. "end",
  170. "",
  171. "",
  172. ].join("\n")
  173. await $`rm -rf ./dist/homebrew-tap`
  174. await $`git clone https://${process.env["GITHUB_TOKEN"]}@github.com/sst/homebrew-tap.git ./dist/homebrew-tap`
  175. await Bun.file("./dist/homebrew-tap/opencode.rb").write(homebrewFormula)
  176. await $`cd ./dist/homebrew-tap && git add opencode.rb`
  177. await $`cd ./dist/homebrew-tap && git commit -m "Update to v${Script.version}"`
  178. await $`cd ./dist/homebrew-tap && git push`
  179. }