From ce6b3ce569b1e7c38508683863e46f6fda2906ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Catriel=20M=C3=BCller?= Date: Thu, 9 Apr 2026 23:25:35 -0300 Subject: [PATCH] fix: align pre-release version publishing --- packages/script/src/index.ts | 54 +++++++++++++++++++++++++++++------- script/publish.ts | 13 ++++++--- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/packages/script/src/index.ts b/packages/script/src/index.ts index 5ea9d757a6..a4c91a3a76 100644 --- a/packages/script/src/index.ts +++ b/packages/script/src/index.ts @@ -36,6 +36,26 @@ const CHANNEL = await (async () => { const IS_PREVIEW = CHANNEL !== "latest" // kilocode_change start - shared helpers for version computation +function parseVersion(input: string) { + const match = input.trim().match(/^v?(\d+)\.(\d+)\.(\d+)$/) + if (!match) return + return { + major: Number(match[1]), + minor: Number(match[2]), + patch: Number(match[3]), + value: `${match[1]}.${match[2]}.${match[3]}`, + } +} + +function compareVersion( + a: NonNullable>, + b: NonNullable>, +) { + if (a.major !== b.major) return a.major - b.major + if (a.minor !== b.minor) return a.minor - b.minor + return a.patch - b.patch +} + 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) @@ -44,28 +64,42 @@ async function fetchLatest() { return data.version as string } +async function fetchHighest() { + if (!env.KILO_RELEASE || !process.env.GH_REPO) return fetchLatest() + const data: { tagName: string }[] = await $`gh release list --json tagName --limit 100 --repo ${process.env.GH_REPO}` + .json() + .catch(() => []) + const versions = data.flatMap((item) => { + const version = parseVersion(item.tagName) + if (!version) return [] + return [version] + }) + const highest = versions.sort(compareVersion).at(-1) + if (highest) return highest.value + return fetchLatest() +} + 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}` + const version = parseVersion(current) + if (!version) throw new Error(`Invalid version: ${current}`) + if (type === "major") return `${version.major + 1}.0.0` + if (type === "minor") return `${version.major}.${version.minor + 1}.0` + return `${version.major}.${version.minor}.${version.patch + 1}` } // kilocode_change end const VERSION = await (async () => { if (env.KILO_VERSION) return env.KILO_VERSION // kilocode_change if (IS_PREVIEW) { - // kilocode_change start - compute semver prerelease for rc channel + // kilocode_change start - rc releases use plain semver required by VS Code Marketplace 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}` + const current = await fetchHighest() + return bumpVersion(current, env.KILO_BUMP.toLowerCase()) } // kilocode_change end return `0.0.0-${CHANNEL}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}` } - const version = await fetchLatest() // kilocode_change + const version = await fetchHighest() // kilocode_change return bumpVersion(version, env.KILO_BUMP?.toLowerCase() ?? "patch") // kilocode_change })() diff --git a/script/publish.ts b/script/publish.ts index 14b75965ec..68e0b70225 100755 --- a/script/publish.ts +++ b/script/publish.ts @@ -58,14 +58,19 @@ await $`bun install` await import(`../packages/sdk/js/script/build.ts`) if (Script.release) { + // kilocode_change start - commit and tag both release and rc version bumps + await $`git commit -am "release: v${Script.version}"` + await $`git tag v${Script.version}` + await $`git fetch origin` if (!Script.preview) { - await $`git commit -am "release: v${Script.version}"` - await $`git tag v${Script.version}` - await $`git fetch origin` await $`git cherry-pick HEAD..origin/dev`.nothrow() await $`git push origin HEAD --tags --no-verify --force-with-lease` - await new Promise((resolve) => setTimeout(resolve, 5_000)) } + if (Script.preview) { + await $`git push origin HEAD --tags` + } + await new Promise((resolve) => setTimeout(resolve, 5_000)) + // kilocode_change end // kilocode_change start // await import(`../packages/desktop/scripts/finalize-latest-json.ts`)