11#!/usr/bin/env bun
2- const dir = new URL ( ".." , import . meta. url ) . pathname
3- process . chdir ( dir )
42import { $ } from "bun"
5-
63import 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
199const { 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)
4838for ( 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}
0 commit comments