diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/package.json | 3 | ||||
| -rwxr-xr-x | packages/opencode/script/build.ts | 12 | ||||
| -rwxr-xr-x | packages/opencode/script/publish.ts | 48 | ||||
| -rw-r--r-- | packages/script/package.json | 10 | ||||
| -rw-r--r-- | packages/script/src/index.ts | 35 | ||||
| -rw-r--r-- | packages/script/tsconfig.json | 8 |
6 files changed, 80 insertions, 36 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 16f643edd..a5dc4d044 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -28,7 +28,8 @@ "@types/yargs": "17.0.33", "typescript": "catalog:", "vscode-languageserver-types": "3.17.5", - "zod-to-json-schema": "3.24.5" + "zod-to-json-schema": "3.24.5", + "@opencode-ai/script": "workspace:*" }, "dependencies": { "@clack/prompts": "1.0.0-alpha.1", diff --git a/packages/opencode/script/build.ts b/packages/opencode/script/build.ts index 4c4bc7825..860147f06 100755 --- a/packages/opencode/script/build.ts +++ b/packages/opencode/script/build.ts @@ -5,6 +5,7 @@ process.chdir(dir) import { $ } from "bun" import pkg from "../package.json" +import { Script } from "@opencode-ai/script" const GOARCH: Record<string, string> = { arm64: "arm64", @@ -25,12 +26,11 @@ const targets = [ await $`rm -rf dist` const binaries: Record<string, string> = {} -const version = process.env["OPENCODE_VERSION"] ?? "dev" for (const [os, arch] of targets) { console.log(`building ${os}-${arch}`) const name = `${pkg.name}-${os}-${arch}` await $`mkdir -p dist/${name}/bin` - await $`CGO_ENABLED=0 GOOS=${os} GOARCH=${GOARCH[arch]} go build -ldflags="-s -w -X main.Version=${version}" -o ../opencode/dist/${name}/bin/tui ../tui/cmd/opencode/main.go` + await $`CGO_ENABLED=0 GOOS=${os} GOARCH=${GOARCH[arch]} go build -ldflags="-s -w -X main.Version=${Script.version}" -o ../opencode/dist/${name}/bin/tui ../tui/cmd/opencode/main.go` .cwd("../tui") .quiet() @@ -43,12 +43,12 @@ for (const [os, arch] of targets) { compile: { target: `bun-${os}-${arch}` as any, outfile: `dist/${name}/bin/opencode`, - execArgv: [`--user-agent=opencode/${version}`, `--env-file=""`, `--`], + execArgv: [`--user-agent=opencode/${Script.version}`, `--env-file=""`, `--`], windows: {}, }, entrypoints: ["./src/index.ts"], define: { - OPENCODE_VERSION: `'${version}'`, + OPENCODE_VERSION: `'${Script.version}'`, OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`, }, }) @@ -57,7 +57,7 @@ for (const [os, arch] of targets) { JSON.stringify( { name, - version, + version: Script.version, os: [os === "windows" ? "win32" : os], cpu: [arch], }, @@ -65,7 +65,7 @@ for (const [os, arch] of targets) { 2, ), ) - binaries[name] = version + binaries[name] = Script.version } export { binaries } diff --git a/packages/opencode/script/publish.ts b/packages/opencode/script/publish.ts index 948dcf252..e58956350 100755 --- a/packages/opencode/script/publish.ts +++ b/packages/opencode/script/publish.ts @@ -1,20 +1,10 @@ #!/usr/bin/env bun -const dir = new URL("..", import.meta.url).pathname -process.chdir(dir) import { $ } from "bun" - import pkg from "../package.json" +import { Script } from "@opencode-ai/script" -const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true" -let version = process.env["OPENCODE_VERSION"] -const tag = process.env["OPENCODE_TAG"] ?? (snapshot ? "snapshot" : "latest") -if (!version && snapshot) { - version = `0.0.0-${tag}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}` - process.env["OPENCODE_VERSION"] = version -} -if (!version) throw new Error("OPENCODE_VERSION is required") - -console.log(`publishing ${version}`) +const dir = new URL("..", import.meta.url).pathname +process.chdir(dir) const { binaries } = await import("./build.ts") { @@ -38,7 +28,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write( preinstall: "node ./preinstall.mjs", postinstall: "node ./postinstall.mjs", }, - version, + version: Script.version, optionalDependencies: binaries, }, null, @@ -46,11 +36,11 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write( ), ) for (const [name] of Object.entries(binaries)) { - await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${tag}` + await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${Script.tag}` } -await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${tag}` +await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${Script.tag}` -if (!snapshot) { +if (!Script.preview) { for (const key of Object.keys(binaries)) { await $`cd dist/${key}/bin && zip -r ../../${key}.zip *` } @@ -67,7 +57,7 @@ if (!snapshot) { "# Maintainer: adam", "", "pkgname='opencode-bin'", - `pkgver=${version.split("-")[0]}`, + `pkgver=${Script.version.split("-")[0]}`, "options=('!debug' '!strip')", "pkgrel=1", "pkgdesc='The AI coding agent built for the terminal.'", @@ -78,10 +68,10 @@ if (!snapshot) { "conflicts=('opencode')", "depends=('fzf' 'ripgrep')", "", - `source_aarch64=("\${pkgname}_\${pkgver}_aarch64.zip::https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-arm64.zip")`, + `source_aarch64=("\${pkgname}_\${pkgver}_aarch64.zip::https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-arm64.zip")`, `sha256sums_aarch64=('${arm64Sha}')`, "", - `source_x86_64=("\${pkgname}_\${pkgver}_x86_64.zip::https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-x64.zip")`, + `source_x86_64=("\${pkgname}_\${pkgver}_x86_64.zip::https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-x64.zip")`, `sha256sums_x86_64=('${x64Sha}')`, "", "package() {", @@ -96,7 +86,7 @@ if (!snapshot) { "# Maintainer: adam", "", "pkgname='opencode'", - `pkgver=${version.split("-")[0]}`, + `pkgver=${Script.version.split("-")[0]}`, "options=('!debug' '!strip')", "pkgrel=1", "pkgdesc='The AI coding agent built for the terminal.'", @@ -108,7 +98,7 @@ if (!snapshot) { "depends=('fzf' 'ripgrep')", "makedepends=('git' 'bun-bin' 'go')", "", - `source=("opencode-\${pkgver}.tar.gz::https://github.com/sst/opencode/archive/v${version}.tar.gz")`, + `source=("opencode-\${pkgver}.tar.gz::https://github.com/sst/opencode/archive/v${Script.version}.tar.gz")`, `sha256sums=('SKIP')`, "", "build() {", @@ -139,7 +129,7 @@ if (!snapshot) { 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${version}"` + await $`cd ./dist/aur-${pkg} && git commit -m "Update to v${Script.version}"` await $`cd ./dist/aur-${pkg} && git push` break } catch (e) { @@ -157,11 +147,11 @@ if (!snapshot) { "class Opencode < Formula", ` desc "The AI coding agent built for the terminal."`, ` homepage "https://github.com/sst/opencode"`, - ` version "${version.split("-")[0]}"`, + ` version "${Script.version.split("-")[0]}"`, "", " on_macos do", " if Hardware::CPU.intel?", - ` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-darwin-x64.zip"`, + ` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-darwin-x64.zip"`, ` sha256 "${macX64Sha}"`, "", " def install", @@ -169,7 +159,7 @@ if (!snapshot) { " end", " end", " if Hardware::CPU.arm?", - ` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-darwin-arm64.zip"`, + ` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-darwin-arm64.zip"`, ` sha256 "${macArm64Sha}"`, "", " def install", @@ -180,14 +170,14 @@ if (!snapshot) { "", " on_linux do", " if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?", - ` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-x64.zip"`, + ` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-x64.zip"`, ` sha256 "${x64Sha}"`, " def install", ' bin.install "opencode"', " end", " end", " if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?", - ` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-arm64.zip"`, + ` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-arm64.zip"`, ` sha256 "${arm64Sha}"`, " def install", ' bin.install "opencode"', @@ -203,6 +193,6 @@ if (!snapshot) { 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${version}"` + await $`cd ./dist/homebrew-tap && git commit -m "Update to v${Script.version}"` await $`cd ./dist/homebrew-tap && git push` } diff --git a/packages/script/package.json b/packages/script/package.json new file mode 100644 index 000000000..2791305f3 --- /dev/null +++ b/packages/script/package.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/package", + "name": "@opencode-ai/script", + "devDependencies": { + "@types/bun": "catalog:" + }, + "exports": { + ".": "./src/index.ts" + } +} diff --git a/packages/script/src/index.ts b/packages/script/src/index.ts new file mode 100644 index 000000000..4237a76a2 --- /dev/null +++ b/packages/script/src/index.ts @@ -0,0 +1,35 @@ +import { $ } from "bun" + +if (process.versions.bun !== "1.3.0") { + throw new Error("This script requires [email protected]") +} + +const TAG = process.env["OPENCODE_TAG"] ?? (await $`git branch --show-current`.text().then((x) => x.trim())) +const IS_PREVIEW = TAG !== "latest" +const VERSION = await (async () => { + if (IS_PREVIEW) return `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}` + const version = await fetch("https://registry.npmjs.org/opencode-ai/latest") + .then((res) => { + if (!res.ok) throw new Error(res.statusText) + return res.json() + }) + .then((data: any) => data.version) + const [major, minor, patch] = version.split(".").map((x: string) => Number(x) || 0) + const t = process.env["OPENCODE_BUMP"]?.toLowerCase() + if (t === "major") return `${major + 1}.0.0` + if (t === "minor") return `${major}.${minor + 1}.0` + return `${major}.${minor}.${patch + 1}` +})() + +export const Script = { + get tag() { + return TAG + }, + get version() { + return VERSION + }, + get preview() { + return IS_PREVIEW + }, +} +console.log(`opencode script`, JSON.stringify(Script, null, 2)) diff --git a/packages/script/tsconfig.json b/packages/script/tsconfig.json new file mode 100644 index 000000000..00ef12546 --- /dev/null +++ b/packages/script/tsconfig.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "@tsconfig/bun/tsconfig.json", + "compilerOptions": { + "lib": ["ESNext", "DOM", "DOM.Iterable"], + "noUncheckedIndexedAccess": false + } +} |
