diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 156ba3c5431..7d4046df932 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -46,7 +46,7 @@ jobs: - uses: ./.github/actions/setup-bun - # kilocode_change start - install deps for changeset changelog generation + # kilocode_change start - install deps for version script workspace resolution - name: Install dependencies run: bun install diff --git a/script/publish.ts b/script/publish.ts index 846321e95e5..088ecc118d2 100755 --- a/script/publish.ts +++ b/script/publish.ts @@ -34,6 +34,38 @@ Add highlights before publishing. Delete this section if no highlights. console.log("=== publishing ===\n") +// kilocode_change start - consume changesets on the publish runner so changelog +// changes are included in the release commit. Previously this ran in the +// version job on a separate runner whose workspace was discarded. +{ + await $`bun install` + const paths = ["packages/kilo-vscode/CHANGELOG.md", "packages/opencode/CHANGELOG.md"] + const before = new Map() + for (const p of paths) { + before.set( + p, + await Bun.file(p) + .text() + .catch(() => ""), + ) + } + const res = await $`bunx changeset version`.nothrow() + if (res.exitCode !== 0) { + console.warn("changeset version failed (exit " + res.exitCode + ")") + } + // Changeset computes its own version from package.json, but we use + // Script.version. Fix the heading in any changelog that was modified. + for (const p of paths) { + const content = await Bun.file(p) + .text() + .catch(() => "") + if (content !== before.get(p)) { + await Bun.write(p, content.replace(/^## .+$/m, `## ${Script.version}`)) + } + } +} +// kilocode_change end + const pkgjsons = await Array.fromAsync( new Bun.Glob("**/package.json").scan({ absolute: true, @@ -73,7 +105,16 @@ if (Script.release) { // kilocode_change end // kilocode_change start - mark prerelease GitHub releases accordingly + // and populate release notes from the changelog updated by changeset above const flags = Script.preview ? ["--draft=false", "--prerelease"] : ["--draft=false"] + const changelog = await Bun.file("packages/kilo-vscode/CHANGELOG.md") + .text() + .catch(() => "") + const body = extractLatestSection(changelog) || "No notable changes" + const tmp = process.env.RUNNER_TEMP ?? "/tmp" + const notes = `${tmp}/release-notes.txt` + await Bun.write(notes, body) + flags.push("--notes-file", notes) await $`gh release edit v${Script.version} ${flags} --repo ${process.env.GH_REPO}` // kilocode_change end } @@ -94,3 +135,17 @@ await import(`../packages/kilo-vscode/script/publish.ts`) const dir = fileURLToPath(new URL("..", import.meta.url)) process.chdir(dir) + +// kilocode_change start - extract latest changelog section for release notes +function extractLatestSection(changelog: string): string { + if (!changelog) return "" + const lines = changelog.split("\n") + const start = lines.findIndex((line) => /^## /.test(line)) + if (start < 0) return "" + const end = lines.findIndex((line, i) => i > start && /^## /.test(line)) + return lines + .slice(start + 1, end < 0 ? undefined : end) + .join("\n") + .trim() +} +// kilocode_change end diff --git a/script/version.ts b/script/version.ts index a34c5bc14ff..479fc557b98 100755 --- a/script/version.ts +++ b/script/version.ts @@ -6,30 +6,10 @@ import { $ } from "bun" const output = [`version=${Script.version}`] if (!Script.preview) { - // kilocode_change start - use changesets for changelog generation - // Run changeset version to consume .changeset/*.md files into CHANGELOG.md. - // This also bumps package.json versions, but publish.ts overwrites them with - // Script.version later, so the changeset-computed versions are irrelevant. - // If no changesets exist yet, changeset version exits 0 but writes nothing. - const result = await $`bunx changeset version`.nothrow() - if (result.exitCode !== 0) { - console.warn("changeset version failed (exit " + result.exitCode + "), continuing with fallback notes") - } - - // Extract the latest version section from the kilo-code extension changelog. - // Changesets writes to packages/kilo-vscode/CHANGELOG.md (not root) because - // the changeset targets the "kilo-code" package. This is also the file the - // VS Code Marketplace reads at publish time. - const changelog = await Bun.file(`${process.cwd()}/packages/kilo-vscode/CHANGELOG.md`) - .text() - .catch(() => "") - const body = extractLatestSection(changelog) || "No notable changes" - - const dir = process.env.RUNNER_TEMP ?? "/tmp" - const notesFile = `${dir}/opencode-release-notes.txt` - await Bun.write(notesFile, body) + // kilocode_change start - create draft release; changelog generation and + // release notes are handled by publish.ts on the same runner that commits. + await $`gh release create v${Script.version} -d --title "v${Script.version}" --notes ""` // kilocode_change end - await $`gh release create v${Script.version} -d --title "v${Script.version}" --notes-file ${notesFile}` const release = await $`gh release view v${Script.version} --json tagName,databaseId`.json() output.push(`release=${release.databaseId}`) output.push(`tag=${release.tagName}`) @@ -49,18 +29,4 @@ if (process.env.GITHUB_OUTPUT) { await Bun.write(process.env.GITHUB_OUTPUT, output.join("\n")) } -// kilocode_change start - extract latest changelog section for release notes -function extractLatestSection(changelog: string): string { - if (!changelog) return "" - const lines = changelog.split("\n") - // Find first ## heading (version section) - const start = lines.findIndex((line) => /^## /.test(line)) - if (start < 0) return "" - // Find the next ## heading after the first one - const end = lines.findIndex((line, i) => i > start && /^## /.test(line)) - const section = lines.slice(start + 1, end < 0 ? undefined : end) - return section.join("\n").trim() -} -// kilocode_change end - process.exit(0)