Skip to content

Commit 289783f

Browse files
committed
ci: version stuff
1 parent 4c464cf commit 289783f

7 files changed

Lines changed: 19 additions & 19 deletions

File tree

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
./script/publish.ts
5959
env:
6060
OPENCODE_BUMP: ${{ inputs.bump }}
61-
OPENCODE_TAG: latest
61+
OPENCODE_CHANNEL: latest
6262
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
6363
AUR_KEY: ${{ secrets.AUR_KEY }}
6464
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

packages/opencode/script/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ for (const [os, arch] of targets) {
4949
entrypoints: ["./src/index.ts"],
5050
define: {
5151
OPENCODE_VERSION: `'${Script.version}'`,
52+
OPENCODE_CHANNEL: `'${Script.channel}'`,
5253
OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
5354
},
5455
})

packages/opencode/script/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
3636
),
3737
)
3838
for (const [name] of Object.entries(binaries)) {
39-
await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${Script.tag}`
39+
await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${Script.channel}`
4040
}
41-
await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${Script.tag}`
41+
await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${Script.channel}`
4242

4343
if (!Script.preview) {
4444
for (const key of Object.keys(binaries)) {

packages/opencode/src/cli/cmd/tui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const TuiCommand = cmd({
157157

158158
;(async () => {
159159
if (Installation.isDev()) return
160-
if (Installation.isSnapshot()) return
160+
if (Installation.isPreview()) return
161161
const config = await Config.global()
162162
if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return
163163
const latest = await Installation.latest().catch(() => {})

packages/opencode/src/installation/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Log } from "../util/log"
77

88
declare global {
99
const OPENCODE_VERSION: string
10+
const OPENCODE_CHANNEL: string
1011
}
1112

1213
export namespace Installation {
@@ -40,7 +41,7 @@ export namespace Installation {
4041
}
4142
}
4243

43-
export function isSnapshot() {
44+
export function isPreview() {
4445
return VERSION.startsWith("0.0.0")
4546
}
4647

@@ -137,17 +138,15 @@ export namespace Installation {
137138
}
138139

139140
export const VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "dev"
140-
export const USER_AGENT = `opencode/${VERSION}`
141+
export const CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "dev"
142+
export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}`
141143

142144
export async function latest() {
143-
return fetch("https://api.github.com/repos/sst/opencode/releases/latest")
144-
.then((res) => res.json())
145-
.then((data) => {
146-
if (typeof data.tag_name !== "string") {
147-
log.error("GitHub API error", data)
148-
throw new Error("failed to fetch latest version")
149-
}
150-
return data.tag_name.slice(1) as string
145+
return fetch(`https://registry.npmjs.org/opencode-ai/${CHANNEL}`)
146+
.then((res) => {
147+
if (!res.ok) throw new Error(res.statusText)
148+
return res.json()
151149
})
150+
.then((data: any) => data.version)
152151
}
153152
}

packages/opencode/src/share/share.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export namespace Share {
6767

6868
export const URL =
6969
process.env["OPENCODE_API"] ??
70-
(Installation.isSnapshot() || Installation.isDev() ? "https://api.dev.opencode.ai" : "https://api.opencode.ai")
70+
(Installation.isPreview() || Installation.isDev() ? "https://api.dev.opencode.ai" : "https://api.opencode.ai")
7171

7272
export async function create(sessionID: string) {
7373
return fetch(`${URL}/share_create`, {

packages/script/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ if (process.versions.bun !== "1.3.0") {
44
throw new Error("This script requires bun@1.3.0")
55
}
66

7-
const TAG = process.env["OPENCODE_TAG"] ?? (await $`git branch --show-current`.text().then((x) => x.trim()))
8-
const IS_PREVIEW = TAG !== "latest"
7+
const CHANNEL = process.env["OPENCODE_CHANNEL"] ?? (await $`git branch --show-current`.text().then((x) => x.trim()))
8+
const IS_PREVIEW = CHANNEL !== "latest"
99
const VERSION = await (async () => {
1010
if (IS_PREVIEW) return `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
1111
const version = await fetch("https://registry.npmjs.org/opencode-ai/latest")
@@ -22,8 +22,8 @@ const VERSION = await (async () => {
2222
})()
2323

2424
export const Script = {
25-
get tag() {
26-
return TAG
25+
get channel() {
26+
return CHANNEL
2727
},
2828
get version() {
2929
return VERSION

0 commit comments

Comments
 (0)