Add rich update check, version diffs, and changelog release history querying
Binaries / Build & Release Binaries (push) Has been cancelled
Binaries / Build & Release Binaries (push) Has been cancelled
This commit is contained in:
1 parent
e716f069ed
commit
63d579c273
6 files changed
+338
-71
No files matched your search
+133
-5
@@ -15,6 +15,8 @@ const GITHUB_REPO_ENV = "SEAL_HOME_GITHUB_REPO";
|
||||
|
||||
export type UpdateOptions = {
|
||||
checkOnly?: boolean;
|
||||
changelogOnly?: boolean;
|
||||
limit?: number;
|
||||
force?: boolean;
|
||||
targetVersion?: string;
|
||||
repo?: string;
|
||||
@@ -29,12 +31,56 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
launcher: runtime.launcher
|
||||
};
|
||||
|
||||
// 1. Source development mode (running via bun/node)
|
||||
const repo = options.repo || process.env[GITHUB_REPO_ENV]?.trim() || DEFAULT_GITHUB_REPO;
|
||||
|
||||
// 1. Changelog / Release History query
|
||||
if (options.changelogOnly) {
|
||||
const releases = await fetchGitHubReleases(repo, options.limit ?? 10);
|
||||
printJson({
|
||||
currentVersion: VERSION,
|
||||
totalQueried: releases.length,
|
||||
releases: releases.map((r) => ({
|
||||
version: r.version,
|
||||
tagName: r.tagName,
|
||||
publishedAt: r.publishedAt,
|
||||
author: r.author,
|
||||
releaseNotes: r.notes,
|
||||
releaseUrl: r.htmlUrl,
|
||||
isCurrent: r.version === VERSION,
|
||||
isNewer: isNewerVersion(r.version, VERSION)
|
||||
}))
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Source development mode (running via bun/node)
|
||||
if (!isCompiledBinary()) {
|
||||
if (options.checkOnly) {
|
||||
const releases = await fetchGitHubReleases(repo, 30);
|
||||
const latestRelease = releases[0];
|
||||
const latestVersion = latestRelease?.version ?? VERSION;
|
||||
const currentRelease = releases.find((r) => r.version === VERSION);
|
||||
const isUpgrade = isNewerVersion(latestVersion, VERSION);
|
||||
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||
|
||||
printJson({
|
||||
updated: false,
|
||||
version: VERSION,
|
||||
updateAvailable: isUpgrade,
|
||||
currentVersion: VERSION,
|
||||
currentVersionPublishedAt: currentRelease?.publishedAt,
|
||||
latestVersion,
|
||||
latestVersionPublishedAt: latestRelease?.publishedAt,
|
||||
behindCount: pendingReleases.length,
|
||||
pendingReleases: pendingReleases.map((r) => ({
|
||||
version: r.version,
|
||||
tagName: r.tagName,
|
||||
publishedAt: r.publishedAt,
|
||||
author: r.author,
|
||||
releaseNotes: r.notes,
|
||||
releaseUrl: r.htmlUrl
|
||||
})),
|
||||
releaseNotes: latestRelease?.notes ?? "",
|
||||
releaseUrl: latestRelease?.htmlUrl ?? "",
|
||||
mode: "source",
|
||||
message: "Running in source development mode. Run 'seal-home update' to git pull & bun install."
|
||||
});
|
||||
@@ -62,12 +108,16 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Standalone binary mode: check GitHub Releases
|
||||
const repo = options.repo || process.env[GITHUB_REPO_ENV]?.trim() || DEFAULT_GITHUB_REPO;
|
||||
// 3. Standalone binary mode: check GitHub Releases
|
||||
const platform = detectPlatform();
|
||||
const arch = detectArch();
|
||||
|
||||
const release = await fetchGitHubRelease(repo, options.targetVersion);
|
||||
const releases = await fetchGitHubReleases(repo, 30);
|
||||
const release = options.targetVersion
|
||||
? (releases.find((r) => r.version === options.targetVersion || r.tagName === options.targetVersion) ??
|
||||
await fetchGitHubRelease(repo, options.targetVersion))
|
||||
: (releases[0] ?? await fetchGitHubRelease(repo));
|
||||
|
||||
if (!release) {
|
||||
printJson({
|
||||
updated: false,
|
||||
@@ -79,15 +129,28 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
}
|
||||
|
||||
const latestVersion = release.version;
|
||||
const currentRelease = releases.find((r) => r.version === VERSION);
|
||||
const isUpgrade = isNewerVersion(latestVersion, VERSION);
|
||||
const shouldUpdate = options.force || Boolean(options.targetVersion) || isUpgrade;
|
||||
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||
|
||||
if (options.checkOnly) {
|
||||
printJson({
|
||||
updated: false,
|
||||
updateAvailable: isUpgrade,
|
||||
currentVersion: VERSION,
|
||||
currentVersionPublishedAt: currentRelease?.publishedAt,
|
||||
latestVersion,
|
||||
latestVersionPublishedAt: release.publishedAt,
|
||||
behindCount: pendingReleases.length,
|
||||
pendingReleases: pendingReleases.map((r) => ({
|
||||
version: r.version,
|
||||
tagName: r.tagName,
|
||||
publishedAt: r.publishedAt,
|
||||
author: r.author,
|
||||
releaseNotes: r.notes,
|
||||
releaseUrl: r.htmlUrl
|
||||
})),
|
||||
releaseNotes: release.notes,
|
||||
releaseUrl: release.htmlUrl,
|
||||
mode: "binary"
|
||||
@@ -99,7 +162,9 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
printJson({
|
||||
updated: false,
|
||||
currentVersion: VERSION,
|
||||
currentVersionPublishedAt: currentRelease?.publishedAt,
|
||||
latestVersion,
|
||||
latestVersionPublishedAt: release.publishedAt,
|
||||
mode: "binary",
|
||||
message: `seal-home is already up to date (v${VERSION})`
|
||||
});
|
||||
@@ -200,11 +265,68 @@ type GitHubAsset = {
|
||||
type GitHubRelease = {
|
||||
version: string;
|
||||
tagName: string;
|
||||
name?: string;
|
||||
publishedAt?: string;
|
||||
author?: string;
|
||||
notes: string;
|
||||
htmlUrl: string;
|
||||
assets: GitHubAsset[];
|
||||
};
|
||||
|
||||
async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRelease[]> {
|
||||
const url = `https://api.github.com/repos/${repo}/releases?per_page=${limit}`;
|
||||
const headers: Record<string, string> = {
|
||||
"User-Agent": `seal-home/${VERSION}`,
|
||||
Accept: "application/vnd.github.v3+json"
|
||||
};
|
||||
|
||||
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
||||
if (token) {
|
||||
headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(url, { headers });
|
||||
if (!res.ok) return [];
|
||||
const json = (await res.json()) as Array<{
|
||||
tag_name?: string;
|
||||
name?: string;
|
||||
body?: string;
|
||||
html_url?: string;
|
||||
published_at?: string;
|
||||
author?: { login?: string };
|
||||
assets?: Array<{ name: string; browser_download_url: string; size?: number }>;
|
||||
}>;
|
||||
|
||||
if (!Array.isArray(json)) return [];
|
||||
|
||||
const list: GitHubRelease[] = [];
|
||||
for (const item of json) {
|
||||
const tagName = item.tag_name ?? "";
|
||||
const version = tagName.replace(/^v/, "");
|
||||
if (!version) continue;
|
||||
const assets: GitHubAsset[] = (item.assets ?? []).map((a) => ({
|
||||
name: a.name,
|
||||
downloadUrl: a.browser_download_url,
|
||||
size: a.size ?? 0
|
||||
}));
|
||||
list.push({
|
||||
version,
|
||||
tagName,
|
||||
name: item.name ?? tagName,
|
||||
publishedAt: item.published_at,
|
||||
author: item.author?.login,
|
||||
notes: item.body ?? "",
|
||||
htmlUrl: item.html_url ?? "",
|
||||
assets
|
||||
});
|
||||
}
|
||||
return list;
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise<GitHubRelease | undefined> {
|
||||
const url = targetVersion
|
||||
? `https://api.github.com/repos/${repo}/releases/tags/${targetVersion.startsWith("v") ? targetVersion : `v${targetVersion}`}`
|
||||
@@ -225,8 +347,11 @@ async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise
|
||||
if (!res.ok) return undefined;
|
||||
const json = (await res.json()) as {
|
||||
tag_name?: string;
|
||||
name?: string;
|
||||
body?: string;
|
||||
html_url?: string;
|
||||
published_at?: string;
|
||||
author?: { login?: string };
|
||||
assets?: Array<{ name: string; browser_download_url: string; size?: number }>;
|
||||
};
|
||||
|
||||
@@ -243,6 +368,9 @@ async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise
|
||||
return {
|
||||
version,
|
||||
tagName,
|
||||
name: json.name ?? tagName,
|
||||
publishedAt: json.published_at,
|
||||
author: json.author?.login,
|
||||
notes: json.body ?? "",
|
||||
htmlUrl: json.html_url ?? "",
|
||||
assets
|
||||
|
||||
Reference in new issue
Block a user