feat(cli): publish CLI as npm prerelease when pre_release flag is set

When the publish workflow is dispatched with pre_release=true, the CLI
and SDK packages are now published to npm under the "rc" dist-tag with
a semver prerelease version (e.g. 7.1.24-rc.202604081425) instead of
going to the "latest" tag as a stable release.

This ensures that pre-release VS Code extension builds ship with a
matching pre-release CLI on npm, so users on the stable channel are
never affected by pre-release publishes.
This commit is contained in:
kiloconnect[bot]
2026-04-08 14:27:42 +00:00
parent ee332b4ec2
commit 3ea1e8f400
4 changed files with 45 additions and 16 deletions
+34 -12
View File
@@ -21,30 +21,52 @@ const env = {
KILO_BUMP: process.env["KILO_BUMP"],
KILO_VERSION: process.env["KILO_VERSION"],
KILO_RELEASE: process.env["KILO_RELEASE"],
KILO_PRE_RELEASE: process.env["KILO_PRE_RELEASE"],
}
// kilocode_change end
const CHANNEL = await (async () => {
if (env.KILO_CHANNEL) return env.KILO_CHANNEL // kilocode_change
// kilocode_change start - publish to "rc" channel for pre-releases
if (env.KILO_BUMP && env.KILO_PRE_RELEASE === "true") return "rc"
// kilocode_change end
if (env.KILO_BUMP) return "latest" // kilocode_change
if (env.KILO_VERSION && !env.KILO_VERSION.startsWith("0.0.0-")) return "latest" // kilocode_change
return await $`git branch --show-current`.text().then((x) => x.trim())
})()
const IS_PREVIEW = CHANNEL !== "latest"
// kilocode_change start - shared helpers for version computation
async function fetchLatest() {
const data: any = await fetch("https://registry.npmjs.org/@kilocode/cli/latest").then((res) => {
if (!res.ok) throw new Error(res.statusText)
return res.json()
})
return data.version as string
}
function bumpVersion(current: string, type: string) {
const [major, minor, patch] = current.split(".").map((x: string) => Number(x) || 0)
if (type === "major") return `${major + 1}.0.0`
if (type === "minor") return `${major}.${minor + 1}.0`
return `${major}.${minor}.${patch + 1}`
}
// kilocode_change end
const VERSION = await (async () => {
if (env.KILO_VERSION) return env.KILO_VERSION // kilocode_change
if (IS_PREVIEW) return `0.0.0-${CHANNEL}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
const version = await fetch("https://registry.npmjs.org/@kilocode/cli/latest") // kilocode_change
.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 = env.KILO_BUMP?.toLowerCase() // kilocode_change
if (t === "major") return `${major + 1}.0.0`
if (t === "minor") return `${major}.${minor + 1}.0`
return `${major}.${minor}.${patch + 1}`
if (IS_PREVIEW) {
// kilocode_change start - compute semver prerelease for rc channel
if (env.KILO_BUMP && env.KILO_PRE_RELEASE === "true") {
const current = await fetchLatest()
const base = bumpVersion(current, env.KILO_BUMP.toLowerCase())
const stamp = new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")
return `${base}-rc.${stamp}`
}
// kilocode_change end
return `0.0.0-${CHANNEL}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
}
const version = await fetchLatest() // kilocode_change
return bumpVersion(version, env.KILO_BUMP?.toLowerCase() ?? "patch") // kilocode_change
})()
// kilocode_change start