Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/core/src/installation/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ declare global {
const OPENCODE_CHANNEL: string
}

export const InstallationVersion = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
export const InstallationChannel = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
function deriveFromGit() {
try {
const { execSync } = require("child_process")
const branch = execSync("git branch --show-current", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim()
if (!branch) return { channel: "local", version: "local" }
const integrationMatch = branch.match(/^integration\/(\d{4}-\d{2}-\d{2}-\d{2}-\d{2})$/)
if (integrationMatch) return { channel: branch, version: integrationMatch[1] }
const ts = new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")
return { channel: branch, version: `0.0.0-${branch}-${ts}` }
} catch {
return { channel: "local", version: "local" }
}
}

const fallback = typeof OPENCODE_VERSION === "string" ? null : deriveFromGit()

export const InstallationVersion = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : (fallback?.version ?? "local")
export const InstallationChannel = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : (fallback?.channel ?? "local")
export const InstallationLocal = InstallationChannel === "local"