|
@@ -7,12 +7,13 @@ import { fileURLToPath } from "url"
|
|
|
const dir = fileURLToPath(new URL("..", import.meta.url))
|
|
const dir = fileURLToPath(new URL("..", import.meta.url))
|
|
|
process.chdir(dir)
|
|
process.chdir(dir)
|
|
|
|
|
|
|
|
-const { binaries } = await import("./build.ts")
|
|
|
|
|
-{
|
|
|
|
|
- const name = `${pkg.name}-${process.platform}-${process.arch}`
|
|
|
|
|
- console.log(`smoke test: running dist/${name}/bin/opencode --version`)
|
|
|
|
|
- await $`./dist/${name}/bin/opencode --version`
|
|
|
|
|
|
|
+const binaries: Record<string, string> = {}
|
|
|
|
|
+for (const filepath of new Bun.Glob("*/package.json").scanSync({ cwd: "./dist" })) {
|
|
|
|
|
+ const pkg = await Bun.file(`./dist/${filepath}`).json()
|
|
|
|
|
+ binaries[pkg.name] = pkg.version
|
|
|
}
|
|
}
|
|
|
|
|
+console.log("binaries", binaries)
|
|
|
|
|
+const version = Object.values(binaries)[0]
|
|
|
|
|
|
|
|
await $`mkdir -p ./dist/${pkg.name}`
|
|
await $`mkdir -p ./dist/${pkg.name}`
|
|
|
await $`cp -r ./bin ./dist/${pkg.name}/bin`
|
|
await $`cp -r ./bin ./dist/${pkg.name}/bin`
|
|
@@ -28,7 +29,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
|
|
scripts: {
|
|
scripts: {
|
|
|
postinstall: "bun ./postinstall.mjs || node ./postinstall.mjs",
|
|
postinstall: "bun ./postinstall.mjs || node ./postinstall.mjs",
|
|
|
},
|
|
},
|
|
|
- version: Script.version,
|
|
|
|
|
|
|
+ version: version,
|
|
|
optionalDependencies: binaries,
|
|
optionalDependencies: binaries,
|
|
|
},
|
|
},
|
|
|
null,
|
|
null,
|
|
@@ -36,35 +37,203 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-const tags = [Script.channel]
|
|
|
|
|
-
|
|
|
|
|
const tasks = Object.entries(binaries).map(async ([name]) => {
|
|
const tasks = Object.entries(binaries).map(async ([name]) => {
|
|
|
if (process.platform !== "win32") {
|
|
if (process.platform !== "win32") {
|
|
|
await $`chmod -R 755 .`.cwd(`./dist/${name}`)
|
|
await $`chmod -R 755 .`.cwd(`./dist/${name}`)
|
|
|
}
|
|
}
|
|
|
await $`bun pm pack`.cwd(`./dist/${name}`)
|
|
await $`bun pm pack`.cwd(`./dist/${name}`)
|
|
|
- for (const tag of tags) {
|
|
|
|
|
- await $`npm publish *.tgz --access public --tag ${tag}`.cwd(`./dist/${name}`)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await $`npm publish *.tgz --access public --tag ${Script.channel}`.cwd(`./dist/${name}`)
|
|
|
})
|
|
})
|
|
|
await Promise.all(tasks)
|
|
await Promise.all(tasks)
|
|
|
-for (const tag of tags) {
|
|
|
|
|
- await $`cd ./dist/${pkg.name} && bun pm pack && npm publish *.tgz --access public --tag ${tag}`
|
|
|
|
|
-}
|
|
|
|
|
|
|
+await $`cd ./dist/${pkg.name} && bun pm pack && npm publish *.tgz --access public --tag ${Script.channel}`
|
|
|
|
|
|
|
|
|
|
+const image = "ghcr.io/anomalyco/opencode"
|
|
|
|
|
+const platforms = "linux/amd64,linux/arm64"
|
|
|
|
|
+const tags = [`${image}:${version}`, `${image}:${Script.channel}`]
|
|
|
|
|
+const tagFlags = tags.flatMap((t) => ["-t", t])
|
|
|
|
|
+await $`docker buildx build --platform ${platforms} ${tagFlags} --push .`
|
|
|
|
|
+
|
|
|
|
|
+// registries
|
|
|
if (!Script.preview) {
|
|
if (!Script.preview) {
|
|
|
- // Create archives for GitHub release
|
|
|
|
|
- for (const key of Object.keys(binaries)) {
|
|
|
|
|
- if (key.includes("linux")) {
|
|
|
|
|
- await $`tar -czf ../../${key}.tar.gz *`.cwd(`dist/${key}/bin`)
|
|
|
|
|
- } else {
|
|
|
|
|
- await $`zip -r ../../${key}.zip *`.cwd(`dist/${key}/bin`)
|
|
|
|
|
|
|
+ // Calculate SHA values
|
|
|
|
|
+ const arm64Sha = await $`sha256sum ./dist/opencode-linux-arm64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
|
|
|
|
|
+ const x64Sha = await $`sha256sum ./dist/opencode-linux-x64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
|
|
|
|
|
+ const macX64Sha = await $`sha256sum ./dist/opencode-darwin-x64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
|
|
|
|
|
+ const macArm64Sha = await $`sha256sum ./dist/opencode-darwin-arm64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
|
|
|
|
|
+
|
|
|
|
|
+ const [pkgver, _subver = ""] = Script.version.split(/(-.*)/, 2)
|
|
|
|
|
+
|
|
|
|
|
+ // arch
|
|
|
|
|
+ const binaryPkgbuild = [
|
|
|
|
|
+ "# Maintainer: dax",
|
|
|
|
|
+ "# Maintainer: adam",
|
|
|
|
|
+ "",
|
|
|
|
|
+ "pkgname='opencode-bin'",
|
|
|
|
|
+ `pkgver=${pkgver}`,
|
|
|
|
|
+ `_subver=${_subver}`,
|
|
|
|
|
+ "options=('!debug' '!strip')",
|
|
|
|
|
+ "pkgrel=1",
|
|
|
|
|
+ "pkgdesc='The AI coding agent built for the terminal.'",
|
|
|
|
|
+ "url='https://github.com/anomalyco/opencode'",
|
|
|
|
|
+ "arch=('aarch64' 'x86_64')",
|
|
|
|
|
+ "license=('MIT')",
|
|
|
|
|
+ "provides=('opencode')",
|
|
|
|
|
+ "conflicts=('opencode')",
|
|
|
|
|
+ "depends=('ripgrep')",
|
|
|
|
|
+ "",
|
|
|
|
|
+ `source_aarch64=("\${pkgname}_\${pkgver}_aarch64.tar.gz::https://github.com/anomalyco/opencode/releases/download/v\${pkgver}\${_subver}/opencode-linux-arm64.tar.gz")`,
|
|
|
|
|
+ `sha256sums_aarch64=('${arm64Sha}')`,
|
|
|
|
|
+
|
|
|
|
|
+ `source_x86_64=("\${pkgname}_\${pkgver}_x86_64.tar.gz::https://github.com/anomalyco/opencode/releases/download/v\${pkgver}\${_subver}/opencode-linux-x64.tar.gz")`,
|
|
|
|
|
+ `sha256sums_x86_64=('${x64Sha}')`,
|
|
|
|
|
+ "",
|
|
|
|
|
+ "package() {",
|
|
|
|
|
+ ' install -Dm755 ./opencode "${pkgdir}/usr/bin/opencode"',
|
|
|
|
|
+ "}",
|
|
|
|
|
+ "",
|
|
|
|
|
+ ].join("\n")
|
|
|
|
|
+
|
|
|
|
|
+ // Source-based PKGBUILD for opencode
|
|
|
|
|
+ const sourcePkgbuild = [
|
|
|
|
|
+ "# Maintainer: dax",
|
|
|
|
|
+ "# Maintainer: adam",
|
|
|
|
|
+ "",
|
|
|
|
|
+ "pkgname='opencode'",
|
|
|
|
|
+ `pkgver=${pkgver}`,
|
|
|
|
|
+ `_subver=${_subver}`,
|
|
|
|
|
+ "options=('!debug' '!strip')",
|
|
|
|
|
+ "pkgrel=1",
|
|
|
|
|
+ "pkgdesc='The AI coding agent built for the terminal.'",
|
|
|
|
|
+ "url='https://github.com/anomalyco/opencode'",
|
|
|
|
|
+ "arch=('aarch64' 'x86_64')",
|
|
|
|
|
+ "license=('MIT')",
|
|
|
|
|
+ "provides=('opencode')",
|
|
|
|
|
+ "conflicts=('opencode-bin')",
|
|
|
|
|
+ "depends=('ripgrep')",
|
|
|
|
|
+ "makedepends=('git' 'bun' 'go')",
|
|
|
|
|
+ "",
|
|
|
|
|
+ `source=("opencode-\${pkgver}.tar.gz::https://github.com/anomalyco/opencode/archive/v\${pkgver}\${_subver}.tar.gz")`,
|
|
|
|
|
+ `sha256sums=('SKIP')`,
|
|
|
|
|
+ "",
|
|
|
|
|
+ "build() {",
|
|
|
|
|
+ ` cd "opencode-\${pkgver}"`,
|
|
|
|
|
+ ` bun install`,
|
|
|
|
|
+ " cd ./packages/opencode",
|
|
|
|
|
+ ` OPENCODE_CHANNEL=latest OPENCODE_VERSION=${pkgver} bun run ./script/build.ts --single`,
|
|
|
|
|
+ "}",
|
|
|
|
|
+ "",
|
|
|
|
|
+ "package() {",
|
|
|
|
|
+ ` cd "opencode-\${pkgver}/packages/opencode"`,
|
|
|
|
|
+ ' mkdir -p "${pkgdir}/usr/bin"',
|
|
|
|
|
+ ' target_arch="x64"',
|
|
|
|
|
+ ' case "$CARCH" in',
|
|
|
|
|
+ ' x86_64) target_arch="x64" ;;',
|
|
|
|
|
+ ' aarch64) target_arch="arm64" ;;',
|
|
|
|
|
+ ' *) printf "unsupported architecture: %s\\n" "$CARCH" >&2 ; return 1 ;;',
|
|
|
|
|
+ " esac",
|
|
|
|
|
+ ' libc=""',
|
|
|
|
|
+ " if command -v ldd >/dev/null 2>&1; then",
|
|
|
|
|
+ " if ldd --version 2>&1 | grep -qi musl; then",
|
|
|
|
|
+ ' libc="-musl"',
|
|
|
|
|
+ " fi",
|
|
|
|
|
+ " fi",
|
|
|
|
|
+ ' if [ -z "$libc" ] && ls /lib/ld-musl-* >/dev/null 2>&1; then',
|
|
|
|
|
+ ' libc="-musl"',
|
|
|
|
|
+ " fi",
|
|
|
|
|
+ ' base=""',
|
|
|
|
|
+ ' if [ "$target_arch" = "x64" ]; then',
|
|
|
|
|
+ " if ! grep -qi avx2 /proc/cpuinfo 2>/dev/null; then",
|
|
|
|
|
+ ' base="-baseline"',
|
|
|
|
|
+ " fi",
|
|
|
|
|
+ " fi",
|
|
|
|
|
+ ' bin="dist/opencode-linux-${target_arch}${base}${libc}/bin/opencode"',
|
|
|
|
|
+ ' if [ ! -f "$bin" ]; then',
|
|
|
|
|
+ ' printf "unable to find binary for %s%s%s\\n" "$target_arch" "$base" "$libc" >&2',
|
|
|
|
|
+ " return 1",
|
|
|
|
|
+ " fi",
|
|
|
|
|
+ ' install -Dm755 "$bin" "${pkgdir}/usr/bin/opencode"',
|
|
|
|
|
+ "}",
|
|
|
|
|
+ "",
|
|
|
|
|
+ ].join("\n")
|
|
|
|
|
+
|
|
|
|
|
+ for (const [pkg, pkgbuild] of [
|
|
|
|
|
+ ["opencode-bin", binaryPkgbuild],
|
|
|
|
|
+ ["opencode", sourcePkgbuild],
|
|
|
|
|
+ ]) {
|
|
|
|
|
+ for (let i = 0; i < 30; i++) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await $`rm -rf ./dist/aur-${pkg}`
|
|
|
|
|
+ await $`git clone ssh://[email protected]/${pkg}.git ./dist/aur-${pkg}`
|
|
|
|
|
+ await $`cd ./dist/aur-${pkg} && git checkout master`
|
|
|
|
|
+ await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(pkgbuild)
|
|
|
|
|
+ await $`cd ./dist/aur-${pkg} && makepkg --printsrcinfo > .SRCINFO`
|
|
|
|
|
+ await $`cd ./dist/aur-${pkg} && git add PKGBUILD .SRCINFO`
|
|
|
|
|
+ await $`cd ./dist/aur-${pkg} && git commit -m "Update to v${Script.version}"`
|
|
|
|
|
+ await $`cd ./dist/aur-${pkg} && git push`
|
|
|
|
|
+ break
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const image = "ghcr.io/anomalyco/opencode"
|
|
|
|
|
- const platforms = "linux/amd64,linux/arm64"
|
|
|
|
|
- const tags = [`${image}:${Script.version}`, `${image}:latest`]
|
|
|
|
|
- const tagFlags = tags.flatMap((t) => ["-t", t])
|
|
|
|
|
- await $`docker buildx build --platform ${platforms} ${tagFlags} --push .`
|
|
|
|
|
|
|
+ // Homebrew formula
|
|
|
|
|
+ const homebrewFormula = [
|
|
|
|
|
+ "# typed: false",
|
|
|
|
|
+ "# frozen_string_literal: true",
|
|
|
|
|
+ "",
|
|
|
|
|
+ "# This file was generated by GoReleaser. DO NOT EDIT.",
|
|
|
|
|
+ "class Opencode < Formula",
|
|
|
|
|
+ ` desc "The AI coding agent built for the terminal."`,
|
|
|
|
|
+ ` homepage "https://github.com/anomalyco/opencode"`,
|
|
|
|
|
+ ` version "${Script.version.split("-")[0]}"`,
|
|
|
|
|
+ "",
|
|
|
|
|
+ ` depends_on "ripgrep"`,
|
|
|
|
|
+ "",
|
|
|
|
|
+ " on_macos do",
|
|
|
|
|
+ " if Hardware::CPU.intel?",
|
|
|
|
|
+ ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-darwin-x64.zip"`,
|
|
|
|
|
+ ` sha256 "${macX64Sha}"`,
|
|
|
|
|
+ "",
|
|
|
|
|
+ " def install",
|
|
|
|
|
+ ' bin.install "opencode"',
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " if Hardware::CPU.arm?",
|
|
|
|
|
+ ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-darwin-arm64.zip"`,
|
|
|
|
|
+ ` sha256 "${macArm64Sha}"`,
|
|
|
|
|
+ "",
|
|
|
|
|
+ " def install",
|
|
|
|
|
+ ' bin.install "opencode"',
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " end",
|
|
|
|
|
+ "",
|
|
|
|
|
+ " on_linux do",
|
|
|
|
|
+ " if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?",
|
|
|
|
|
+ ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-linux-x64.tar.gz"`,
|
|
|
|
|
+ ` sha256 "${x64Sha}"`,
|
|
|
|
|
+ " def install",
|
|
|
|
|
+ ' bin.install "opencode"',
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?",
|
|
|
|
|
+ ` url "https://github.com/anomalyco/opencode/releases/download/v${Script.version}/opencode-linux-arm64.tar.gz"`,
|
|
|
|
|
+ ` sha256 "${arm64Sha}"`,
|
|
|
|
|
+ " def install",
|
|
|
|
|
+ ' bin.install "opencode"',
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " end",
|
|
|
|
|
+ " end",
|
|
|
|
|
+ "end",
|
|
|
|
|
+ "",
|
|
|
|
|
+ "",
|
|
|
|
|
+ ].join("\n")
|
|
|
|
|
+
|
|
|
|
|
+ await $`rm -rf ./dist/homebrew-tap`
|
|
|
|
|
+ await $`git clone https://${process.env["GITHUB_TOKEN"]}@github.com/sst/homebrew-tap.git ./dist/homebrew-tap`
|
|
|
|
|
+ await Bun.file("./dist/homebrew-tap/opencode.rb").write(homebrewFormula)
|
|
|
|
|
+ await $`cd ./dist/homebrew-tap && git add opencode.rb`
|
|
|
|
|
+ await $`cd ./dist/homebrew-tap && git commit -m "Update to v${Script.version}"`
|
|
|
|
|
+ await $`cd ./dist/homebrew-tap && git push`
|
|
|
}
|
|
}
|