summaryrefslogtreecommitdiffhomepage
path: root/script/publish.ts
diff options
context:
space:
mode:
authorLuke Parker <[email protected]>2025-12-19 12:09:41 +1000
committeropencode <[email protected]>2025-12-19 02:12:35 +0000
commit7f8e79939217c504effa9ff20bb113941645d581 (patch)
tree8a490f23627053656fbab2a8ed4d201c05b68879 /script/publish.ts
parent289f4abaaa90f7b8e1d6b49169ae260d46ceeecd (diff)
downloadopencode-7f8e79939217c504effa9ff20bb113941645d581.tar.gz
opencode-7f8e79939217c504effa9ff20bb113941645d581.zip
tweak: DevEx to run changelog independently (#5774)
Diffstat (limited to 'script/publish.ts')
-rwxr-xr-xscript/publish.ts179
1 files changed, 5 insertions, 174 deletions
diff --git a/script/publish.ts b/script/publish.ts
index ad1c9d31c..d11b435b4 100755
--- a/script/publish.ts
+++ b/script/publish.ts
@@ -1,38 +1,10 @@
#!/usr/bin/env bun
import { $ } from "bun"
-import { createOpencode } from "@opencode-ai/sdk"
import { Script } from "@opencode-ai/script"
+import { generateChangelog } from "./changelog"
-const notes = [] as string[]
-
-const team = [
- "actions-user",
- "opencode",
- "rekram1-node",
- "thdxr",
- "kommander",
- "jayair",
- "fwang",
- "adamdotdevin",
- "iamdavidhill",
- "opencode-agent[bot]",
-]
-
-function getAreaFromPath(file: string): string {
- if (file.startsWith("packages/")) {
- const parts = file.replace("packages/", "").split("/")
- if (parts[0] === "extensions" && parts[1]) return `extensions/${parts[1]}`
- return parts[0] || "other"
- }
- if (file.startsWith("sdks/")) {
- const name = file.replace("sdks/", "").split("/")[0] || "other"
- return `extensions/${name}`
- }
- const rootDir = file.split("/")[0]
- if (rootDir && !rootDir.includes(".")) return rootDir
- return "other"
-}
+let notes = ""
console.log("=== publishing ===\n")
@@ -44,152 +16,11 @@ if (!Script.preview) {
})
.then((data: any) => data.version)
- // Fetch commit authors from GitHub API (hash -> login)
- const compare =
- await $`gh api "/repos/sst/opencode/compare/v${previous}...HEAD" --jq '.commits[] | {sha: .sha, login: .author.login, message: .commit.message}'`.text()
- const authorByHash = new Map<string, string>()
- const contributors = new Map<string, string[]>()
-
- for (const line of compare.split("\n").filter(Boolean)) {
- const { sha, login, message } = JSON.parse(line) as { sha: string; login: string | null; message: string }
- const shortHash = sha.slice(0, 7)
- if (login) authorByHash.set(shortHash, login)
-
- const title = message.split("\n")[0] || ""
- if (title.match(/^(ignore:|test:|chore:|ci:|release:)/i)) continue
- if (login && !team.includes(login)) {
- if (!contributors.has(login)) contributors.set(login, [])
- contributors.get(login)?.push(title)
- }
- }
-
- // Batch-fetch files for all commits (hash -> areas)
- const diffLog = await $`git log v${previous}..HEAD --name-only --format="%h"`.text()
- const areasByHash = new Map<string, Set<string>>()
- let currentHash: string | null = null
-
- for (const rawLine of diffLog.split("\n")) {
- const line = rawLine.trim()
- if (!line) continue
- if (/^[0-9a-f]{7}$/i.test(line)) {
- currentHash = line
- if (!areasByHash.has(currentHash)) areasByHash.set(currentHash, new Set())
- continue
- }
- if (currentHash) {
- areasByHash.get(currentHash)!.add(getAreaFromPath(line))
- }
- }
-
- // Build commit lines with author and areas
- const log = await $`git log v${previous}..HEAD --oneline --format="%h %s"`.text()
- const commitLines = log.split("\n").filter((line) => line && !line.match(/^\w+ (ignore:|test:|chore:|ci:|release:)/i))
-
- const commitsWithMeta = commitLines
- .map((line) => {
- const hash = line.split(" ")[0]
- if (!hash) return null
- const author = authorByHash.get(hash)
- const authorStr = author ? ` [author: ${author}]` : ""
- const areas = areasByHash.get(hash)
- const areaStr = areas && areas.size > 0 ? ` [areas: ${[...areas].join(", ")}]` : " [areas: other]"
- return `${line}${authorStr}${areaStr}`
- })
- .filter(Boolean) as string[]
- const commits = commitsWithMeta.join("\n")
-
- const opencode = await createOpencode()
- const session = await opencode.client.session.create()
console.log("generating changelog since " + previous)
- const raw = await opencode.client.session
- .prompt({
- path: {
- id: session.data!.id,
- },
- body: {
- model: {
- providerID: "opencode",
- modelID: "gemini-3-flash",
- },
- parts: [
- {
- type: "text",
- text: `
-Analyze these commits and generate a changelog of all notable user facing changes, grouped by area.
-
-Each commit below includes:
-- [author: username] showing the GitHub username of the commit author
-- [areas: ...] showing which areas of the codebase were modified
-
-Commits between ${previous} and HEAD:
-${commits}
-
-Group the changes into these categories based on the [areas: ...] tags (omit any category with no changes):
-- **TUI**: Changes to "opencode" area (the terminal/CLI interface)
-- **Desktop**: Changes to "desktop" or "tauri" areas (the desktop application)
-- **SDK**: Changes to "sdk" or "plugin" areas (the SDK and plugin system)
-- **Extensions**: Changes to "extensions/zed", "extensions/vscode", or "github" areas (editor extensions and GitHub Action)
-- **Other**: Any user-facing changes that don't fit the above categories
-
-Excluded areas (omit these entirely unless they contain user-facing changes like refactors that may affect behavior):
-- "nix", "infra", "script" - CI/build infrastructure
-- "ui", "docs", "web", "console", "enterprise", "function", "util", "identity", "slack" - internal packages
-
-Rules:
-- Use the [areas: ...] tags to determine the correct category. If a commit touches multiple areas, put it in the most relevant user-facing category.
-- ONLY include commits that have user-facing impact. Omit purely internal changes (CI, build scripts, internal tooling).
-- However, DO include refactors that touch user-facing code - refactors can introduce bugs or change behavior.
-- Do NOT make general statements about "improvements", be very specific about what was changed.
-- For commits that are already well-written and descriptive, avoid rewording them. Simply capitalize the first letter, fix any misspellings, and ensure proper English grammar.
-- DO NOT read any other commits than the ones listed above (THIS IS IMPORTANT TO AVOID DUPLICATING THINGS IN OUR CHANGELOG).
-- If a commit was made and then reverted do not include it in the changelog. If the commits only include a revert but not the original commit, then include the revert in the changelog.
-- Omit categories that have no changes.
-- For community contributors: if the [author: username] is NOT in the team list, add (@username) at the end of the changelog entry. This is REQUIRED for all non-team contributors.
-- The team members are: ${team.join(", ")}. Do NOT add @ mentions for team members.
-
-IMPORTANT: ONLY return the grouped changelog, do not include any other information. Do not include a preamble like "Based on my analysis..." or "Here is the changelog..."
-
-<example>
-## TUI
-- Added experimental support for the Ty language server (@OpeOginni)
-- Added /fork slash command for keyboard-friendly session forking (@ariane-emory)
-- Increased retry attempts for failed requests
-- Fixed model validation before executing slash commands (@devxoul)
-
-## Desktop
-- Added shell mode support
-- Fixed prompt history navigation and optimistic prompt duplication
-- Disabled pinch-to-zoom on Linux (@Brendonovich)
-
-## Extensions
-- Added OIDC_BASE_URL support for custom GitHub App installations (@elithrar)
-</example>
-`,
- },
- ],
- },
- })
- .then((x) => x.data?.parts?.find((y) => y.type === "text")?.text)
- for (const line of raw?.split("\n") ?? []) {
- if (line.startsWith("## ")) {
- if (notes.length > 0) notes.push("")
- notes.push(line)
- } else if (line.startsWith("- ")) {
- notes.push(line)
- }
- }
+ notes = await generateChangelog(`v${previous}`, "HEAD")
console.log("---- Generated Changelog ----")
- console.log(notes.join("\n"))
+ console.log(notes)
console.log("-----------------------------")
- opencode.server.close()
-
- if (contributors.size > 0) {
- notes.push("")
- notes.push(`**Thank you to ${contributors.size} community contributor${contributors.size > 1 ? "s" : ""}:**`)
- for (const username of contributors.keys()) {
- notes.push(`- @${username}`)
- }
- }
}
const pkgjsons = await Array.fromAsync(
@@ -233,7 +64,7 @@ if (!Script.preview) {
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))
- await $`gh release create v${Script.version} -d --title "v${Script.version}" --notes ${notes.join("\n") || "No notable changes"} ./packages/opencode/dist/*.zip ./packages/opencode/dist/*.tar.gz`
+ await $`gh release create v${Script.version} -d --title "v${Script.version}" --notes ${notes || "No notable changes"} ./packages/opencode/dist/*.zip ./packages/opencode/dist/*.tar.gz`
const release = await $`gh release view v${Script.version} --json id,tagName`.json()
if (process.env.GITHUB_OUTPUT) {
await Bun.write(process.env.GITHUB_OUTPUT, `releaseId=${release.id}\ntagName=${release.tagName}\n`)