Skip to content

Commit 0c022ef

Browse files
committed
ci: stuff
1 parent 717b544 commit 0c022ef

File tree

11 files changed

+106
-73
lines changed

11 files changed

+106
-73
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
./script/publish.ts
5959
env:
6060
OPENCODE_BUMP: ${{ inputs.bump }}
61+
OPENCODE_TAG: latest
6162
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
6263
AUR_KEY: ${{ secrets.AUR_KEY }}
6364
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/snapshot.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,5 @@ jobs:
3030
run: |
3131
./packages/opencode/script/publish.ts
3232
env:
33-
OPENCODE_SNAPSHOT: true
34-
OPENCODE_TAG: ${{ github.ref_name }}
3533
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
3634
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

bun.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"turbo": "2.5.6"
4949
},
5050
"dependencies": {
51-
"@opencode-ai/sdk": "workspace:*"
51+
"@opencode-ai/sdk": "workspace:*",
52+
"@opencode-ai/script": "workspace:*"
5253
},
5354
"repository": {
5455
"type": "git",

packages/opencode/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"@types/yargs": "17.0.33",
2929
"typescript": "catalog:",
3030
"vscode-languageserver-types": "3.17.5",
31-
"zod-to-json-schema": "3.24.5"
31+
"zod-to-json-schema": "3.24.5",
32+
"@opencode-ai/script": "workspace:*"
3233
},
3334
"dependencies": {
3435
"@clack/prompts": "1.0.0-alpha.1",

packages/opencode/script/build.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ process.chdir(dir)
55
import { $ } from "bun"
66

77
import pkg from "../package.json"
8+
import { Script } from "@opencode-ai/script"
89

910
const GOARCH: Record<string, string> = {
1011
arm64: "arm64",
@@ -25,12 +26,11 @@ const targets = [
2526
await $`rm -rf dist`
2627

2728
const binaries: Record<string, string> = {}
28-
const version = process.env["OPENCODE_VERSION"] ?? "dev"
2929
for (const [os, arch] of targets) {
3030
console.log(`building ${os}-${arch}`)
3131
const name = `${pkg.name}-${os}-${arch}`
3232
await $`mkdir -p dist/${name}/bin`
33-
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`
33+
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`
3434
.cwd("../tui")
3535
.quiet()
3636

@@ -43,12 +43,12 @@ for (const [os, arch] of targets) {
4343
compile: {
4444
target: `bun-${os}-${arch}` as any,
4545
outfile: `dist/${name}/bin/opencode`,
46-
execArgv: [`--user-agent=opencode/${version}`, `--env-file=""`, `--`],
46+
execArgv: [`--user-agent=opencode/${Script.version}`, `--env-file=""`, `--`],
4747
windows: {},
4848
},
4949
entrypoints: ["./src/index.ts"],
5050
define: {
51-
OPENCODE_VERSION: `'${version}'`,
51+
OPENCODE_VERSION: `'${Script.version}'`,
5252
OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
5353
},
5454
})
@@ -57,15 +57,15 @@ for (const [os, arch] of targets) {
5757
JSON.stringify(
5858
{
5959
name,
60-
version,
60+
version: Script.version,
6161
os: [os === "windows" ? "win32" : os],
6262
cpu: [arch],
6363
},
6464
null,
6565
2,
6666
),
6767
)
68-
binaries[name] = version
68+
binaries[name] = Script.version
6969
}
7070

7171
export { binaries }

packages/opencode/script/publish.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
#!/usr/bin/env bun
2-
const dir = new URL("..", import.meta.url).pathname
3-
process.chdir(dir)
42
import { $ } from "bun"
5-
63
import pkg from "../package.json"
4+
import { Script } from "@opencode-ai/script"
75

8-
const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
9-
let version = process.env["OPENCODE_VERSION"]
10-
const tag = process.env["OPENCODE_TAG"] ?? (snapshot ? "snapshot" : "latest")
11-
if (!version && snapshot) {
12-
version = `0.0.0-${tag}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
13-
process.env["OPENCODE_VERSION"] = version
14-
}
15-
if (!version) throw new Error("OPENCODE_VERSION is required")
16-
17-
console.log(`publishing ${version}`)
6+
const dir = new URL("..", import.meta.url).pathname
7+
process.chdir(dir)
188

199
const { binaries } = await import("./build.ts")
2010
{
@@ -38,19 +28,19 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
3828
preinstall: "node ./preinstall.mjs",
3929
postinstall: "node ./postinstall.mjs",
4030
},
41-
version,
31+
version: Script.version,
4232
optionalDependencies: binaries,
4333
},
4434
null,
4535
2,
4636
),
4737
)
4838
for (const [name] of Object.entries(binaries)) {
49-
await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${tag}`
39+
await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${Script.tag}`
5040
}
51-
await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${tag}`
41+
await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${Script.tag}`
5242

53-
if (!snapshot) {
43+
if (!Script.preview) {
5444
for (const key of Object.keys(binaries)) {
5545
await $`cd dist/${key}/bin && zip -r ../../${key}.zip *`
5646
}
@@ -67,7 +57,7 @@ if (!snapshot) {
6757
"# Maintainer: adam",
6858
"",
6959
"pkgname='opencode-bin'",
70-
`pkgver=${version.split("-")[0]}`,
60+
`pkgver=${Script.version.split("-")[0]}`,
7161
"options=('!debug' '!strip')",
7262
"pkgrel=1",
7363
"pkgdesc='The AI coding agent built for the terminal.'",
@@ -78,10 +68,10 @@ if (!snapshot) {
7868
"conflicts=('opencode')",
7969
"depends=('fzf' 'ripgrep')",
8070
"",
81-
`source_aarch64=("\${pkgname}_\${pkgver}_aarch64.zip::https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-arm64.zip")`,
71+
`source_aarch64=("\${pkgname}_\${pkgver}_aarch64.zip::https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-arm64.zip")`,
8272
`sha256sums_aarch64=('${arm64Sha}')`,
8373
"",
84-
`source_x86_64=("\${pkgname}_\${pkgver}_x86_64.zip::https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-x64.zip")`,
74+
`source_x86_64=("\${pkgname}_\${pkgver}_x86_64.zip::https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-x64.zip")`,
8575
`sha256sums_x86_64=('${x64Sha}')`,
8676
"",
8777
"package() {",
@@ -96,7 +86,7 @@ if (!snapshot) {
9686
"# Maintainer: adam",
9787
"",
9888
"pkgname='opencode'",
99-
`pkgver=${version.split("-")[0]}`,
89+
`pkgver=${Script.version.split("-")[0]}`,
10090
"options=('!debug' '!strip')",
10191
"pkgrel=1",
10292
"pkgdesc='The AI coding agent built for the terminal.'",
@@ -108,7 +98,7 @@ if (!snapshot) {
10898
"depends=('fzf' 'ripgrep')",
10999
"makedepends=('git' 'bun-bin' 'go')",
110100
"",
111-
`source=("opencode-\${pkgver}.tar.gz::https://github.com/sst/opencode/archive/v${version}.tar.gz")`,
101+
`source=("opencode-\${pkgver}.tar.gz::https://github.com/sst/opencode/archive/v${Script.version}.tar.gz")`,
112102
`sha256sums=('SKIP')`,
113103
"",
114104
"build() {",
@@ -139,7 +129,7 @@ if (!snapshot) {
139129
await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(pkgbuild)
140130
await $`cd ./dist/aur-${pkg} && makepkg --printsrcinfo > .SRCINFO`
141131
await $`cd ./dist/aur-${pkg} && git add PKGBUILD .SRCINFO`
142-
await $`cd ./dist/aur-${pkg} && git commit -m "Update to v${version}"`
132+
await $`cd ./dist/aur-${pkg} && git commit -m "Update to v${Script.version}"`
143133
await $`cd ./dist/aur-${pkg} && git push`
144134
break
145135
} catch (e) {
@@ -157,19 +147,19 @@ if (!snapshot) {
157147
"class Opencode < Formula",
158148
` desc "The AI coding agent built for the terminal."`,
159149
` homepage "https://github.com/sst/opencode"`,
160-
` version "${version.split("-")[0]}"`,
150+
` version "${Script.version.split("-")[0]}"`,
161151
"",
162152
" on_macos do",
163153
" if Hardware::CPU.intel?",
164-
` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-darwin-x64.zip"`,
154+
` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-darwin-x64.zip"`,
165155
` sha256 "${macX64Sha}"`,
166156
"",
167157
" def install",
168158
' bin.install "opencode"',
169159
" end",
170160
" end",
171161
" if Hardware::CPU.arm?",
172-
` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-darwin-arm64.zip"`,
162+
` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-darwin-arm64.zip"`,
173163
` sha256 "${macArm64Sha}"`,
174164
"",
175165
" def install",
@@ -180,14 +170,14 @@ if (!snapshot) {
180170
"",
181171
" on_linux do",
182172
" if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?",
183-
` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-x64.zip"`,
173+
` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-x64.zip"`,
184174
` sha256 "${x64Sha}"`,
185175
" def install",
186176
' bin.install "opencode"',
187177
" end",
188178
" end",
189179
" if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?",
190-
` url "https://github.com/sst/opencode/releases/download/v${version}/opencode-linux-arm64.zip"`,
180+
` url "https://github.com/sst/opencode/releases/download/v${Script.version}/opencode-linux-arm64.zip"`,
191181
` sha256 "${arm64Sha}"`,
192182
" def install",
193183
' bin.install "opencode"',
@@ -203,6 +193,6 @@ if (!snapshot) {
203193
await $`git clone https://${process.env["GITHUB_TOKEN"]}@github.com/sst/homebrew-tap.git ./dist/homebrew-tap`
204194
await Bun.file("./dist/homebrew-tap/opencode.rb").write(homebrewFormula)
205195
await $`cd ./dist/homebrew-tap && git add opencode.rb`
206-
await $`cd ./dist/homebrew-tap && git commit -m "Update to v${version}"`
196+
await $`cd ./dist/homebrew-tap && git commit -m "Update to v${Script.version}"`
207197
await $`cd ./dist/homebrew-tap && git push`
208198
}

packages/script/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://json.schemastore.org/package",
3+
"name": "@opencode-ai/script",
4+
"devDependencies": {
5+
"@types/bun": "catalog:"
6+
},
7+
"exports": {
8+
".": "./src/index.ts"
9+
}
10+
}

packages/script/src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { $ } from "bun"
2+
3+
if (process.versions.bun !== "1.3.0") {
4+
throw new Error("This script requires bun@1.3.0")
5+
}
6+
7+
const TAG = process.env["OPENCODE_TAG"] ?? (await $`git branch --show-current`.text().then((x) => x.trim()))
8+
const IS_PREVIEW = TAG !== "latest"
9+
const VERSION = await (async () => {
10+
if (IS_PREVIEW) return `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
11+
const version = await fetch("https://registry.npmjs.org/opencode-ai/latest")
12+
.then((res) => {
13+
if (!res.ok) throw new Error(res.statusText)
14+
return res.json()
15+
})
16+
.then((data: any) => data.version)
17+
const [major, minor, patch] = version.split(".").map((x: string) => Number(x) || 0)
18+
const t = process.env["OPENCODE_BUMP"]?.toLowerCase()
19+
if (t === "major") return `${major + 1}.0.0`
20+
if (t === "minor") return `${major}.${minor + 1}.0`
21+
return `${major}.${minor}.${patch + 1}`
22+
})()
23+
24+
export const Script = {
25+
get tag() {
26+
return TAG
27+
},
28+
get version() {
29+
return VERSION
30+
},
31+
get preview() {
32+
return IS_PREVIEW
33+
},
34+
}
35+
console.log(`opencode script`, JSON.stringify(Script, null, 2))

packages/script/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "@tsconfig/bun/tsconfig.json",
4+
"compilerOptions": {
5+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
6+
"noUncheckedIndexedAccess": false
7+
}
8+
}

0 commit comments

Comments
 (0)