ci: version stuff

This commit is contained in:
Dax Raad
2025-10-14 14:51:35 -04:00
parent 4c464cf4c0
commit 289783f627
7 changed files with 19 additions and 19 deletions

View File

@@ -58,7 +58,7 @@ jobs:
./script/publish.ts ./script/publish.ts
env: env:
OPENCODE_BUMP: ${{ inputs.bump }} OPENCODE_BUMP: ${{ inputs.bump }}
OPENCODE_TAG: latest OPENCODE_CHANNEL: latest
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
AUR_KEY: ${{ secrets.AUR_KEY }} AUR_KEY: ${{ secrets.AUR_KEY }}
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }} NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

View File

@@ -49,6 +49,7 @@ for (const [os, arch] of targets) {
entrypoints: ["./src/index.ts"], entrypoints: ["./src/index.ts"],
define: { define: {
OPENCODE_VERSION: `'${Script.version}'`, OPENCODE_VERSION: `'${Script.version}'`,
OPENCODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`, OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
}, },
}) })

View File

@@ -36,9 +36,9 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
), ),
) )
for (const [name] of Object.entries(binaries)) { for (const [name] of Object.entries(binaries)) {
await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${Script.tag}` await $`cd dist/${name} && chmod 777 -R . && bun publish --access public --tag ${Script.channel}`
} }
await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${Script.tag}` await $`cd ./dist/${pkg.name} && bun publish --access public --tag ${Script.channel}`
if (!Script.preview) { if (!Script.preview) {
for (const key of Object.keys(binaries)) { for (const key of Object.keys(binaries)) {

View File

@@ -157,7 +157,7 @@ export const TuiCommand = cmd({
;(async () => { ;(async () => {
if (Installation.isDev()) return if (Installation.isDev()) return
if (Installation.isSnapshot()) return if (Installation.isPreview()) return
const config = await Config.global() const config = await Config.global()
if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return if (config.autoupdate === false || Flag.OPENCODE_DISABLE_AUTOUPDATE) return
const latest = await Installation.latest().catch(() => {}) const latest = await Installation.latest().catch(() => {})

View File

@@ -7,6 +7,7 @@ import { Log } from "../util/log"
declare global { declare global {
const OPENCODE_VERSION: string const OPENCODE_VERSION: string
const OPENCODE_CHANNEL: string
} }
export namespace Installation { export namespace Installation {
@@ -40,7 +41,7 @@ export namespace Installation {
} }
} }
export function isSnapshot() { export function isPreview() {
return VERSION.startsWith("0.0.0") return VERSION.startsWith("0.0.0")
} }
@@ -137,17 +138,15 @@ export namespace Installation {
} }
export const VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "dev" export const VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "dev"
export const USER_AGENT = `opencode/${VERSION}` export const CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "dev"
export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}`
export async function latest() { export async function latest() {
return fetch("https://api.github.com/repos/sst/opencode/releases/latest") return fetch(`https://registry.npmjs.org/opencode-ai/${CHANNEL}`)
.then((res) => res.json()) .then((res) => {
.then((data) => { if (!res.ok) throw new Error(res.statusText)
if (typeof data.tag_name !== "string") { return res.json()
log.error("GitHub API error", data)
throw new Error("failed to fetch latest version")
}
return data.tag_name.slice(1) as string
}) })
.then((data: any) => data.version)
} }
} }

View File

@@ -67,7 +67,7 @@ export namespace Share {
export const URL = export const URL =
process.env["OPENCODE_API"] ?? process.env["OPENCODE_API"] ??
(Installation.isSnapshot() || Installation.isDev() ? "https://api.dev.opencode.ai" : "https://api.opencode.ai") (Installation.isPreview() || Installation.isDev() ? "https://api.dev.opencode.ai" : "https://api.opencode.ai")
export async function create(sessionID: string) { export async function create(sessionID: string) {
return fetch(`${URL}/share_create`, { return fetch(`${URL}/share_create`, {

View File

@@ -4,8 +4,8 @@ if (process.versions.bun !== "1.3.0") {
throw new Error("This script requires bun@1.3.0") throw new Error("This script requires bun@1.3.0")
} }
const TAG = process.env["OPENCODE_TAG"] ?? (await $`git branch --show-current`.text().then((x) => x.trim())) const CHANNEL = process.env["OPENCODE_CHANNEL"] ?? (await $`git branch --show-current`.text().then((x) => x.trim()))
const IS_PREVIEW = TAG !== "latest" const IS_PREVIEW = CHANNEL !== "latest"
const VERSION = await (async () => { const VERSION = await (async () => {
if (IS_PREVIEW) return `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}` 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") const version = await fetch("https://registry.npmjs.org/opencode-ai/latest")
@@ -22,8 +22,8 @@ const VERSION = await (async () => {
})() })()
export const Script = { export const Script = {
get tag() { get channel() {
return TAG return CHANNEL
}, },
get version() { get version() {
return VERSION return VERSION