feat: add update channel status

Co-authored-by: Richard Poelderl <18185649+p6l-richard@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-20 14:05:55 +00:00
parent 30fd7001f2
commit 5d017dae5a
8 changed files with 370 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
export type UpdateChannel = "stable" | "beta" | "dev";
export type UpdateChannelSource = "config" | "git-tag" | "git-branch" | "default";
export const DEFAULT_PACKAGE_CHANNEL: UpdateChannel = "stable";
export const DEFAULT_GIT_CHANNEL: UpdateChannel = "dev";
@@ -24,3 +25,49 @@ export function isBetaTag(tag: string): boolean {
export function isStableTag(tag: string): boolean {
return !isBetaTag(tag);
}
export function resolveEffectiveUpdateChannel(params: {
configChannel?: UpdateChannel | null;
installKind: "git" | "package" | "unknown";
git?: { tag?: string | null; branch?: string | null };
}): { channel: UpdateChannel; source: UpdateChannelSource } {
if (params.configChannel) {
return { channel: params.configChannel, source: "config" };
}
if (params.installKind === "git") {
const tag = params.git?.tag;
if (tag) {
return { channel: isBetaTag(tag) ? "beta" : "stable", source: "git-tag" };
}
const branch = params.git?.branch;
if (branch && branch !== "HEAD") {
return { channel: "dev", source: "git-branch" };
}
return { channel: DEFAULT_GIT_CHANNEL, source: "default" };
}
if (params.installKind === "package") {
return { channel: DEFAULT_PACKAGE_CHANNEL, source: "default" };
}
return { channel: DEFAULT_PACKAGE_CHANNEL, source: "default" };
}
export function formatUpdateChannelLabel(params: {
channel: UpdateChannel;
source: UpdateChannelSource;
gitTag?: string | null;
gitBranch?: string | null;
}): string {
if (params.source === "config") return `${params.channel} (config)`;
if (params.source === "git-tag") {
return params.gitTag ? `${params.channel} (${params.gitTag})` : `${params.channel} (tag)`;
}
if (params.source === "git-branch") {
return params.gitBranch
? `${params.channel} (${params.gitBranch})`
: `${params.channel} (branch)`;
}
return `${params.channel} (default)`;
}

View File

@@ -8,6 +8,8 @@ export type PackageManager = "pnpm" | "bun" | "npm" | "unknown";
export type GitUpdateStatus = {
root: string;
sha: string | null;
tag: string | null;
branch: string | null;
upstream: string | null;
dirty: boolean | null;
@@ -90,6 +92,8 @@ export async function checkGitUpdateStatus(params: {
const base: GitUpdateStatus = {
root,
sha: null,
tag: null,
branch: null,
upstream: null,
dirty: null,
@@ -107,6 +111,17 @@ export async function checkGitUpdateStatus(params: {
}
const branch = branchRes.stdout.trim() || null;
const shaRes = await runCommandWithTimeout(["git", "-C", root, "rev-parse", "HEAD"], {
timeoutMs,
}).catch(() => null);
const sha = shaRes && shaRes.code === 0 ? shaRes.stdout.trim() : null;
const tagRes = await runCommandWithTimeout(
["git", "-C", root, "describe", "--tags", "--exact-match"],
{ timeoutMs },
).catch(() => null);
const tag = tagRes && tagRes.code === 0 ? tagRes.stdout.trim() : null;
const upstreamRes = await runCommandWithTimeout(
["git", "-C", root, "rev-parse", "--abbrev-ref", "@{upstream}"],
{ timeoutMs },
@@ -144,6 +159,8 @@ export async function checkGitUpdateStatus(params: {
return {
root,
sha,
tag,
branch,
upstream,
dirty,