mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-19 16:54:22 +01:00
ci: stuff
This commit is contained in:
1
.github/workflows/publish.yml
vendored
1
.github/workflows/publish.yml
vendored
@@ -58,6 +58,7 @@ jobs:
|
|||||||
./script/publish.ts
|
./script/publish.ts
|
||||||
env:
|
env:
|
||||||
OPENCODE_BUMP: ${{ inputs.bump }}
|
OPENCODE_BUMP: ${{ inputs.bump }}
|
||||||
|
OPENCODE_TAG: 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 }}
|
||||||
|
|||||||
2
.github/workflows/snapshot.yml
vendored
2
.github/workflows/snapshot.yml
vendored
@@ -30,7 +30,5 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
./packages/opencode/script/publish.ts
|
./packages/opencode/script/publish.ts
|
||||||
env:
|
env:
|
||||||
OPENCODE_SNAPSHOT: true
|
|
||||||
OPENCODE_TAG: ${{ github.ref_name }}
|
|
||||||
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
|
||||||
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|||||||
10
bun.lock
10
bun.lock
@@ -4,6 +4,7 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "opencode",
|
"name": "opencode",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@opencode-ai/script": "workspace:*",
|
||||||
"@opencode-ai/sdk": "workspace:*",
|
"@opencode-ai/sdk": "workspace:*",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -209,6 +210,7 @@
|
|||||||
"@ai-sdk/amazon-bedrock": "2.2.10",
|
"@ai-sdk/amazon-bedrock": "2.2.10",
|
||||||
"@ai-sdk/google-vertex": "3.0.16",
|
"@ai-sdk/google-vertex": "3.0.16",
|
||||||
"@octokit/webhooks-types": "7.6.1",
|
"@octokit/webhooks-types": "7.6.1",
|
||||||
|
"@opencode-ai/script": "workspace:*",
|
||||||
"@parcel/watcher-win32-x64": "2.5.1",
|
"@parcel/watcher-win32-x64": "2.5.1",
|
||||||
"@standard-schema/spec": "1.0.0",
|
"@standard-schema/spec": "1.0.0",
|
||||||
"@tsconfig/bun": "catalog:",
|
"@tsconfig/bun": "catalog:",
|
||||||
@@ -233,6 +235,12 @@
|
|||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"packages/script": {
|
||||||
|
"name": "@opencode-ai/script",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/bun": "catalog:",
|
||||||
|
},
|
||||||
|
},
|
||||||
"packages/sdk/js": {
|
"packages/sdk/js": {
|
||||||
"name": "@opencode-ai/sdk",
|
"name": "@opencode-ai/sdk",
|
||||||
"version": "0.15.2",
|
"version": "0.15.2",
|
||||||
@@ -830,6 +838,8 @@
|
|||||||
|
|
||||||
"@opencode-ai/plugin": ["@opencode-ai/plugin@workspace:packages/plugin"],
|
"@opencode-ai/plugin": ["@opencode-ai/plugin@workspace:packages/plugin"],
|
||||||
|
|
||||||
|
"@opencode-ai/script": ["@opencode-ai/script@workspace:packages/script"],
|
||||||
|
|
||||||
"@opencode-ai/sdk": ["@opencode-ai/sdk@workspace:packages/sdk/js"],
|
"@opencode-ai/sdk": ["@opencode-ai/sdk@workspace:packages/sdk/js"],
|
||||||
|
|
||||||
"@opencode-ai/slack": ["@opencode-ai/slack@workspace:packages/slack"],
|
"@opencode-ai/slack": ["@opencode-ai/slack@workspace:packages/slack"],
|
||||||
|
|||||||
@@ -48,7 +48,8 @@
|
|||||||
"turbo": "2.5.6"
|
"turbo": "2.5.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@opencode-ai/sdk": "workspace:*"
|
"@opencode-ai/sdk": "workspace:*",
|
||||||
|
"@opencode-ai/script": "workspace:*"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
"@types/yargs": "17.0.33",
|
"@types/yargs": "17.0.33",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"vscode-languageserver-types": "3.17.5",
|
"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": {
|
"dependencies": {
|
||||||
"@clack/prompts": "1.0.0-alpha.1",
|
"@clack/prompts": "1.0.0-alpha.1",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ process.chdir(dir)
|
|||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
|
|
||||||
import pkg from "../package.json"
|
import pkg from "../package.json"
|
||||||
|
import { Script } from "@opencode-ai/script"
|
||||||
|
|
||||||
const GOARCH: Record<string, string> = {
|
const GOARCH: Record<string, string> = {
|
||||||
arm64: "arm64",
|
arm64: "arm64",
|
||||||
@@ -25,12 +26,11 @@ const targets = [
|
|||||||
await $`rm -rf dist`
|
await $`rm -rf dist`
|
||||||
|
|
||||||
const binaries: Record<string, string> = {}
|
const binaries: Record<string, string> = {}
|
||||||
const version = process.env["OPENCODE_VERSION"] ?? "dev"
|
|
||||||
for (const [os, arch] of targets) {
|
for (const [os, arch] of targets) {
|
||||||
console.log(`building ${os}-${arch}`)
|
console.log(`building ${os}-${arch}`)
|
||||||
const name = `${pkg.name}-${os}-${arch}`
|
const name = `${pkg.name}-${os}-${arch}`
|
||||||
await $`mkdir -p dist/${name}/bin`
|
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")
|
.cwd("../tui")
|
||||||
.quiet()
|
.quiet()
|
||||||
|
|
||||||
@@ -43,12 +43,12 @@ for (const [os, arch] of targets) {
|
|||||||
compile: {
|
compile: {
|
||||||
target: `bun-${os}-${arch}` as any,
|
target: `bun-${os}-${arch}` as any,
|
||||||
outfile: `dist/${name}/bin/opencode`,
|
outfile: `dist/${name}/bin/opencode`,
|
||||||
execArgv: [`--user-agent=opencode/${version}`, `--env-file=""`, `--`],
|
execArgv: [`--user-agent=opencode/${Script.version}`, `--env-file=""`, `--`],
|
||||||
windows: {},
|
windows: {},
|
||||||
},
|
},
|
||||||
entrypoints: ["./src/index.ts"],
|
entrypoints: ["./src/index.ts"],
|
||||||
define: {
|
define: {
|
||||||
OPENCODE_VERSION: `'${version}'`,
|
OPENCODE_VERSION: `'${Script.version}'`,
|
||||||
OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
|
OPENCODE_TUI_PATH: `'../../../dist/${name}/bin/tui'`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -57,7 +57,7 @@ for (const [os, arch] of targets) {
|
|||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
version,
|
version: Script.version,
|
||||||
os: [os === "windows" ? "win32" : os],
|
os: [os === "windows" ? "win32" : os],
|
||||||
cpu: [arch],
|
cpu: [arch],
|
||||||
},
|
},
|
||||||
@@ -65,7 +65,7 @@ for (const [os, arch] of targets) {
|
|||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
binaries[name] = version
|
binaries[name] = Script.version
|
||||||
}
|
}
|
||||||
|
|
||||||
export { binaries }
|
export { binaries }
|
||||||
|
|||||||
@@ -1,20 +1,10 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
|
import { $ } from "bun"
|
||||||
|
import pkg from "../package.json"
|
||||||
|
import { Script } from "@opencode-ai/script"
|
||||||
|
|
||||||
const dir = new URL("..", import.meta.url).pathname
|
const dir = new URL("..", import.meta.url).pathname
|
||||||
process.chdir(dir)
|
process.chdir(dir)
|
||||||
import { $ } from "bun"
|
|
||||||
|
|
||||||
import pkg from "../package.json"
|
|
||||||
|
|
||||||
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 { binaries } = await import("./build.ts")
|
const { binaries } = await import("./build.ts")
|
||||||
{
|
{
|
||||||
@@ -38,7 +28,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
|||||||
preinstall: "node ./preinstall.mjs",
|
preinstall: "node ./preinstall.mjs",
|
||||||
postinstall: "node ./postinstall.mjs",
|
postinstall: "node ./postinstall.mjs",
|
||||||
},
|
},
|
||||||
version,
|
version: Script.version,
|
||||||
optionalDependencies: binaries,
|
optionalDependencies: binaries,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
@@ -46,11 +36,11 @@ 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 ${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)) {
|
for (const key of Object.keys(binaries)) {
|
||||||
await $`cd dist/${key}/bin && zip -r ../../${key}.zip *`
|
await $`cd dist/${key}/bin && zip -r ../../${key}.zip *`
|
||||||
}
|
}
|
||||||
@@ -67,7 +57,7 @@ if (!snapshot) {
|
|||||||
"# Maintainer: adam",
|
"# Maintainer: adam",
|
||||||
"",
|
"",
|
||||||
"pkgname='opencode-bin'",
|
"pkgname='opencode-bin'",
|
||||||
`pkgver=${version.split("-")[0]}`,
|
`pkgver=${Script.version.split("-")[0]}`,
|
||||||
"options=('!debug' '!strip')",
|
"options=('!debug' '!strip')",
|
||||||
"pkgrel=1",
|
"pkgrel=1",
|
||||||
"pkgdesc='The AI coding agent built for the terminal.'",
|
"pkgdesc='The AI coding agent built for the terminal.'",
|
||||||
@@ -78,10 +68,10 @@ if (!snapshot) {
|
|||||||
"conflicts=('opencode')",
|
"conflicts=('opencode')",
|
||||||
"depends=('fzf' 'ripgrep')",
|
"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}')`,
|
`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}')`,
|
`sha256sums_x86_64=('${x64Sha}')`,
|
||||||
"",
|
"",
|
||||||
"package() {",
|
"package() {",
|
||||||
@@ -96,7 +86,7 @@ if (!snapshot) {
|
|||||||
"# Maintainer: adam",
|
"# Maintainer: adam",
|
||||||
"",
|
"",
|
||||||
"pkgname='opencode'",
|
"pkgname='opencode'",
|
||||||
`pkgver=${version.split("-")[0]}`,
|
`pkgver=${Script.version.split("-")[0]}`,
|
||||||
"options=('!debug' '!strip')",
|
"options=('!debug' '!strip')",
|
||||||
"pkgrel=1",
|
"pkgrel=1",
|
||||||
"pkgdesc='The AI coding agent built for the terminal.'",
|
"pkgdesc='The AI coding agent built for the terminal.'",
|
||||||
@@ -108,7 +98,7 @@ if (!snapshot) {
|
|||||||
"depends=('fzf' 'ripgrep')",
|
"depends=('fzf' 'ripgrep')",
|
||||||
"makedepends=('git' 'bun-bin' 'go')",
|
"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')`,
|
`sha256sums=('SKIP')`,
|
||||||
"",
|
"",
|
||||||
"build() {",
|
"build() {",
|
||||||
@@ -139,7 +129,7 @@ if (!snapshot) {
|
|||||||
await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(pkgbuild)
|
await Bun.file(`./dist/aur-${pkg}/PKGBUILD`).write(pkgbuild)
|
||||||
await $`cd ./dist/aur-${pkg} && makepkg --printsrcinfo > .SRCINFO`
|
await $`cd ./dist/aur-${pkg} && makepkg --printsrcinfo > .SRCINFO`
|
||||||
await $`cd ./dist/aur-${pkg} && git add PKGBUILD .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`
|
await $`cd ./dist/aur-${pkg} && git push`
|
||||||
break
|
break
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -157,11 +147,11 @@ if (!snapshot) {
|
|||||||
"class Opencode < Formula",
|
"class Opencode < Formula",
|
||||||
` desc "The AI coding agent built for the terminal."`,
|
` desc "The AI coding agent built for the terminal."`,
|
||||||
` homepage "https://github.com/sst/opencode"`,
|
` homepage "https://github.com/sst/opencode"`,
|
||||||
` version "${version.split("-")[0]}"`,
|
` version "${Script.version.split("-")[0]}"`,
|
||||||
"",
|
"",
|
||||||
" on_macos do",
|
" on_macos do",
|
||||||
" if Hardware::CPU.intel?",
|
" 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}"`,
|
` sha256 "${macX64Sha}"`,
|
||||||
"",
|
"",
|
||||||
" def install",
|
" def install",
|
||||||
@@ -169,7 +159,7 @@ if (!snapshot) {
|
|||||||
" end",
|
" end",
|
||||||
" end",
|
" end",
|
||||||
" if Hardware::CPU.arm?",
|
" 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}"`,
|
` sha256 "${macArm64Sha}"`,
|
||||||
"",
|
"",
|
||||||
" def install",
|
" def install",
|
||||||
@@ -180,14 +170,14 @@ if (!snapshot) {
|
|||||||
"",
|
"",
|
||||||
" on_linux do",
|
" on_linux do",
|
||||||
" if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?",
|
" 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}"`,
|
` sha256 "${x64Sha}"`,
|
||||||
" def install",
|
" def install",
|
||||||
' bin.install "opencode"',
|
' bin.install "opencode"',
|
||||||
" end",
|
" end",
|
||||||
" end",
|
" end",
|
||||||
" if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?",
|
" 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}"`,
|
` sha256 "${arm64Sha}"`,
|
||||||
" def install",
|
" def install",
|
||||||
' bin.install "opencode"',
|
' 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 $`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 Bun.file("./dist/homebrew-tap/opencode.rb").write(homebrewFormula)
|
||||||
await $`cd ./dist/homebrew-tap && git add opencode.rb`
|
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`
|
await $`cd ./dist/homebrew-tap && git push`
|
||||||
}
|
}
|
||||||
|
|||||||
10
packages/script/package.json
Normal file
10
packages/script/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/package",
|
||||||
|
"name": "@opencode-ai/script",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/bun": "catalog:"
|
||||||
|
},
|
||||||
|
"exports": {
|
||||||
|
".": "./src/index.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
35
packages/script/src/index.ts
Normal file
35
packages/script/src/index.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { $ } from "bun"
|
||||||
|
|
||||||
|
if (process.versions.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 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))
|
||||||
8
packages/script/tsconfig.json
Normal file
8
packages/script/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
|
"extends": "@tsconfig/bun/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
||||||
|
"noUncheckedIndexedAccess": false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,34 +2,13 @@
|
|||||||
|
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
import { createOpencode } from "@opencode-ai/sdk"
|
import { createOpencode } from "@opencode-ai/sdk"
|
||||||
if (process.versions.bun !== "1.3.0") {
|
import { Script } from "@opencode-ai/script"
|
||||||
throw new Error("This script requires bun@1.3.0")
|
|
||||||
}
|
|
||||||
|
|
||||||
const notes = [] as string[]
|
const notes = [] as string[]
|
||||||
|
|
||||||
console.log("=== publishing ===\n")
|
console.log("=== publishing ===\n")
|
||||||
|
|
||||||
const snapshot = process.env["OPENCODE_SNAPSHOT"] === "true"
|
if (!Script.preview) {
|
||||||
const version = await (async () => {
|
|
||||||
if (snapshot) return `0.0.0-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
|
|
||||||
if (process.env["OPENCODE_VERSION"]) return process.env["OPENCODE_VERSION"]
|
|
||||||
const npmVersion = 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] = npmVersion.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}`
|
|
||||||
})()
|
|
||||||
process.env["OPENCODE_VERSION"] = version
|
|
||||||
console.log("version:", version)
|
|
||||||
|
|
||||||
if (!snapshot) {
|
|
||||||
const previous = await fetch("https://registry.npmjs.org/opencode-ai/latest")
|
const previous = await fetch("https://registry.npmjs.org/opencode-ai/latest")
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) throw new Error(res.statusText)
|
if (!res.ok) throw new Error(res.statusText)
|
||||||
@@ -98,7 +77,7 @@ const pkgjsons = await Array.fromAsync(
|
|||||||
const tree = await $`git add . && git write-tree`.text().then((x) => x.trim())
|
const tree = await $`git add . && git write-tree`.text().then((x) => x.trim())
|
||||||
for (const file of pkgjsons) {
|
for (const file of pkgjsons) {
|
||||||
let pkg = await Bun.file(file).text()
|
let pkg = await Bun.file(file).text()
|
||||||
pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${version}"`)
|
pkg = pkg.replaceAll(/"version": "[^"]+"/g, `"version": "${Script.version}"`)
|
||||||
console.log("updated:", file)
|
console.log("updated:", file)
|
||||||
await Bun.file(file).write(pkg)
|
await Bun.file(file).write(pkg)
|
||||||
}
|
}
|
||||||
@@ -116,22 +95,22 @@ await import(`../packages/plugin/script/publish.ts`)
|
|||||||
const dir = new URL("..", import.meta.url).pathname
|
const dir = new URL("..", import.meta.url).pathname
|
||||||
process.chdir(dir)
|
process.chdir(dir)
|
||||||
|
|
||||||
if (!snapshot) {
|
if (!Script.preview) {
|
||||||
await $`git commit -am "release: v${version}"`
|
await $`git commit -am "release: v${Script.version}"`
|
||||||
await $`git tag v${version}`
|
await $`git tag v${Script.version}`
|
||||||
await $`git fetch origin`
|
await $`git fetch origin`
|
||||||
await $`git cherry-pick HEAD..origin/dev`.nothrow()
|
await $`git cherry-pick HEAD..origin/dev`.nothrow()
|
||||||
await $`git push origin HEAD --tags --no-verify --force`
|
await $`git push origin HEAD --tags --no-verify --force`
|
||||||
|
|
||||||
await $`gh release create v${version} --title "v${version}" --notes ${notes.join("\n") ?? "No notable changes"} ./packages/opencode/dist/*.zip`
|
await $`gh release create v${Script.version} --title "v${Script.version}" --notes ${notes.join("\n") ?? "No notable changes"} ./packages/opencode/dist/*.zip`
|
||||||
}
|
}
|
||||||
if (snapshot) {
|
if (Script.preview) {
|
||||||
await $`git checkout -b snapshot-${version}`
|
await $`git checkout -b snapshot-${Script.version}`
|
||||||
await $`git commit --allow-empty -m "Snapshot release v${version}"`
|
await $`git commit --allow-empty -m "Snapshot release v${Script.version}"`
|
||||||
await $`git tag v${version}`
|
await $`git tag v${Script.version}`
|
||||||
await $`git push origin v${version} --no-verify`
|
await $`git push origin v${Script.version} --no-verify`
|
||||||
await $`git checkout dev`
|
await $`git checkout dev`
|
||||||
await $`git branch -D snapshot-${version}`
|
await $`git branch -D snapshot-${Script.version}`
|
||||||
for (const file of pkgjsons) {
|
for (const file of pkgjsons) {
|
||||||
await $`git checkout ${tree} ${file}`
|
await $`git checkout ${tree} ${file}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user