cloudaxe-opencode/packages/opencode/script/publish.ts

71 lines
2 KiB
TypeScript
Raw Normal View History

2025-05-31 00:47:56 +00:00
#!/usr/bin/env bun
import { $ } from "bun"
import pkg from "../package.json"
2025-10-14 18:34:19 +00:00
import { Script } from "@opencode-ai/script"
import { fileURLToPath } from "url"
2025-05-31 00:47:56 +00:00
const dir = fileURLToPath(new URL("..", import.meta.url))
2025-10-14 18:34:19 +00:00
process.chdir(dir)
2025-05-31 00:47:56 +00:00
2025-09-19 10:10:27 +00: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 00:47:56 +00:00
}
await $`mkdir -p ./dist/${pkg.name}`
await $`cp -r ./bin ./dist/${pkg.name}/bin`
2025-06-15 17:10:58 +00:00
await $`cp ./script/postinstall.mjs ./dist/${pkg.name}/postinstall.mjs`
2025-05-31 00:47:56 +00: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 00:47:56 +00:00
},
scripts: {
2025-10-31 19:07:36 +00:00
postinstall: "bun ./postinstall.mjs || node ./postinstall.mjs",
},
2025-10-14 18:34:19 +00:00
version: Script.version,
2025-09-19 10:10:27 +00:00
optionalDependencies: binaries,
2025-05-31 00:47:56 +00:00
},
null,
2,
),
)
2025-12-10 02:16:00 +00:00
const tags = [Script.channel]
2025-12-10 02:16:00 +00:00
const tasks = Object.entries(binaries).map(async ([name]) => {
if (process.platform !== "win32") {
2025-12-22 08:57:28 +00: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 02:16:00 +00: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 00:28:30 +00:00
}
2025-10-14 18:34:19 +00:00
if (!Script.preview) {
2025-12-20 03:41:18 +00: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-13 19:01:59 +00: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 15:02:51 +00:00
}