opencode_offline/packages/opencode/script/publish.ts

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-05-31 08:47:56 +08:00
#!/usr/bin/env bun
import { $ } from "bun"
import pkg from "../package.json"
2025-10-15 02:34:19 +08:00
import { Script } from "@opencode-ai/script"
import { fileURLToPath } from "url"
2025-05-31 08:47:56 +08:00
const dir = fileURLToPath(new URL("..", import.meta.url))
2025-10-15 02:34:19 +08:00
process.chdir(dir)
2025-05-31 08:47:56 +08:00
2025-09-19 18:10:27 +08:00
const { binaries } = await import("./build.ts")
{
const name = `${pkg.name}-${process.platform}-${process.arch}`
console.log(`smoke test: running dist/${name}/bin/opencode --version`)
await $`./dist/${name}/bin/opencode --version`
2025-05-31 08:47:56 +08:00
}
await $`mkdir -p ./dist/${pkg.name}`
await $`cp -r ./bin ./dist/${pkg.name}/bin`
2025-06-16 01:10:58 +08:00
await $`cp ./script/postinstall.mjs ./dist/${pkg.name}/postinstall.mjs`
2025-05-31 08:47:56 +08:00
await Bun.file(`./dist/${pkg.name}/package.json`).write(
JSON.stringify(
{
name: pkg.name + "-ai",
bin: {
[pkg.name]: `./bin/${pkg.name}`,
2025-05-31 08:47:56 +08:00
},
scripts: {
2025-11-01 03:07:36 +08:00
postinstall: "bun ./postinstall.mjs || node ./postinstall.mjs",
},
2025-10-15 02:34:19 +08:00
version: Script.version,
2025-09-19 18:10:27 +08:00
optionalDependencies: binaries,
2025-05-31 08:47:56 +08:00
},
null,
2,
),
)
2025-12-10 10:16:00 +08:00
const tags = [Script.channel]
2025-12-10 10:16:00 +08:00
const tasks = Object.entries(binaries).map(async ([name]) => {
if (process.platform !== "win32") {
2025-12-22 16:57:28 +08:00
await $`chmod -R 755 .`.cwd(`./dist/${name}`)
}
await $`bun pm pack`.cwd(`./dist/${name}`)
for (const tag of tags) {
await $`npm publish *.tgz --access public --tag ${tag}`.cwd(`./dist/${name}`)
}
2025-12-10 10:16:00 +08:00
})
await Promise.all(tasks)
for (const tag of tags) {
await $`cd ./dist/${pkg.name} && bun pm pack && npm publish *.tgz --access public --tag ${tag}`
2025-10-29 08:28:30 +08:00
}
2025-10-15 02:34:19 +08:00
if (!Script.preview) {
2025-12-20 11:41:18 +08:00
// Create archives for GitHub release
for (const key of Object.keys(binaries)) {
if (key.includes("linux")) {
await $`tar -czf ../../${key}.tar.gz *`.cwd(`dist/${key}/bin`)
} else {
await $`zip -r ../../${key}.zip *`.cwd(`dist/${key}/bin`)
}
}
const image = "ghcr.io/anomalyco/opencode"
2025-12-14 03:01:59 +08:00
const platforms = "linux/amd64,linux/arm64"
const tags = [`${image}:${Script.version}`, `${image}:latest`]
const tagFlags = tags.flatMap((t) => ["-t", t])
await $`docker buildx build --platform ${platforms} ${tagFlags} --push .`
2025-06-12 23:02:51 +08:00
}