Add release automation script and Homebrew-aware update dispatch
This commit is contained in:
1 parent
31c499ae60
commit
0bfad43bc3
8 files changed
+581
-174
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { compareSemVer, getMirrorMode, isNewerVersion, matchAssetForPlatform } from "./update.js";
|
||||
import { compareSemVer, getMirrorMode, isHomebrewInstall, isNewerVersion, matchAssetForPlatform } from "./update.js";
|
||||
|
||||
type Asset = { name: string; downloadUrl: string; size: number };
|
||||
|
||||
@@ -185,4 +185,22 @@ describe("update command bgSave and cache integration", () => {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
describe("isHomebrewInstall", () => {
|
||||
test("detects Homebrew Cellar paths on Apple Silicon and Intel macOS", () => {
|
||||
expect(isHomebrewInstall("/opt/homebrew/Cellar/seal-use/0.10.33/bin/seal-use")).toBe(true);
|
||||
expect(isHomebrewInstall("/usr/local/Cellar/seal-use/0.10.33/bin/seal-use")).toBe(true);
|
||||
expect(isHomebrewInstall("/opt/homebrew/bin/seal-use")).toBe(true);
|
||||
});
|
||||
|
||||
test("detects Homebrew Cellar paths on Linuxbrew", () => {
|
||||
expect(isHomebrewInstall("/home/linuxbrew/.linuxbrew/Cellar/seal-use/0.10.33/bin/seal-use")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false for non-Homebrew paths", () => {
|
||||
expect(isHomebrewInstall("/usr/local/bin/seal-use")).toBe(false);
|
||||
expect(isHomebrewInstall("/Users/alice/.local/bin/seal-use")).toBe(false);
|
||||
expect(isHomebrewInstall("/tmp/seal-use")).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
+157
-3
@@ -1,11 +1,11 @@
|
||||
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
||||
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { isCompiledBinary } from "../../core/runtime.js";
|
||||
import { readInstalledSkillVersion } from "../../core/embedded-skill.js";
|
||||
import { saveUpdateCache } from "../../core/update-cache.js";
|
||||
import { VERSION, IS_RELEASE } from "../../version.js";
|
||||
import { runServiceCommand, serviceStatus } from "../service.js";
|
||||
import { runServiceCommand, serviceStatus, type ServiceConfig } from "../service.js";
|
||||
import { printJson } from "../printer.js";
|
||||
import { STATE_DIR } from "./service.js";
|
||||
import type { CliRuntime } from "../types.js";
|
||||
@@ -162,7 +162,19 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Standalone binary mode: check GitHub Releases
|
||||
// 3. Homebrew managed mode
|
||||
if (isHomebrewInstall()) {
|
||||
try {
|
||||
await handleHomebrewUpdate(runtime, options, serviceConfig, repo, targetVersion);
|
||||
return;
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`⚠️ Homebrew 自动更新失败,回退至原生二进制更新: ${err instanceof Error ? err.message : String(err)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Standalone binary mode: check GitHub Releases
|
||||
const platform = detectPlatform();
|
||||
const arch = detectArch();
|
||||
|
||||
@@ -378,6 +390,148 @@ function detectArch(): "arm64" | "x64" {
|
||||
return process.arch === "arm64" ? "arm64" : "x64";
|
||||
}
|
||||
|
||||
export function isHomebrewInstall(execPath = process.execPath): boolean {
|
||||
try {
|
||||
const resolved = realpathSync(execPath);
|
||||
return (
|
||||
resolved.includes("/Cellar/seal-use/") ||
|
||||
resolved.includes("/homebrew/Cellar/seal-use/") ||
|
||||
resolved.includes("/.linuxbrew/Cellar/seal-use/") ||
|
||||
execPath.includes("/Cellar/seal-use/") ||
|
||||
execPath.includes("/homebrew/bin/seal-use")
|
||||
);
|
||||
} catch {
|
||||
return (
|
||||
execPath.includes("/Cellar/seal-use/") ||
|
||||
execPath.includes("/homebrew/bin/seal-use")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleHomebrewUpdate(
|
||||
runtime: CliRuntime,
|
||||
options: UpdateOptions,
|
||||
serviceConfig: ServiceConfig,
|
||||
repo: string,
|
||||
targetVersion?: string
|
||||
): Promise<void> {
|
||||
const releases = await fetchGitHubReleases(repo, 30);
|
||||
const release = targetVersion
|
||||
? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ??
|
||||
await fetchGitHubRelease(repo, targetVersion))
|
||||
: (releases[0] ?? await fetchGitHubRelease(repo));
|
||||
|
||||
const latestVersion = release?.version ?? VERSION;
|
||||
const isUpgrade = isNewerVersion(latestVersion, VERSION);
|
||||
const shouldUpdate = isUpgrade || Boolean(options.force);
|
||||
|
||||
if (release?.version) {
|
||||
saveUpdateCache({
|
||||
latestVersion: release.version,
|
||||
publishedAt: release.publishedAt,
|
||||
releaseUrl: release.htmlUrl
|
||||
});
|
||||
}
|
||||
|
||||
if (options.bgSave) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.checkOnly) {
|
||||
const currentRelease = releases.find((r) => r.version === VERSION);
|
||||
const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION));
|
||||
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: "homebrew"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldUpdate) {
|
||||
printJson({
|
||||
updated: false,
|
||||
currentVersion: VERSION,
|
||||
latestVersion,
|
||||
mode: "homebrew",
|
||||
message: `seal-use is already up to date (v${VERSION})`
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("ℹ️ 检测到当前 seal-use 由 Homebrew 管理。");
|
||||
console.error("📦 正在通过 Homebrew 极速更新: brew update yunyingk/tap && brew upgrade seal-use ...");
|
||||
|
||||
const wasRunning = serviceStatus(serviceConfig).running;
|
||||
if (wasRunning) await runServiceCommand("stop", serviceConfig);
|
||||
|
||||
// 1. Fast update of the dedicated tap
|
||||
const tapUpdate = spawnSync("brew", ["update", "yunyingk/tap"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, NONINTERACTIVE: "1" }
|
||||
});
|
||||
|
||||
if (tapUpdate.status !== 0) {
|
||||
const msg = tapUpdate.stderr?.trim() || tapUpdate.stdout?.trim();
|
||||
if (msg) console.error(`⚠️ brew update yunyingk/tap 提示: ${msg}`);
|
||||
}
|
||||
|
||||
// 2. Upgrade the formula
|
||||
const upgradeRes = spawnSync("brew", ["upgrade", "seal-use"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, NONINTERACTIVE: "1" }
|
||||
});
|
||||
|
||||
const outCombined = `${upgradeRes.stdout || ""} ${upgradeRes.stderr || ""}`;
|
||||
const alreadyLatest =
|
||||
outCombined.includes("already installed") || outCombined.includes("latest version already installed");
|
||||
|
||||
if (upgradeRes.status !== 0 && !alreadyLatest) {
|
||||
throw new Error(
|
||||
`brew upgrade seal-use failed (exit ${upgradeRes.status}): ${upgradeRes.stderr?.trim() || upgradeRes.stdout?.trim()}`
|
||||
);
|
||||
}
|
||||
|
||||
if (wasRunning) await runServiceCommand("start", serviceConfig);
|
||||
|
||||
// Refresh installed skill through new binary
|
||||
try {
|
||||
spawnSync("seal-use", ["skill", "install"], { stdio: "ignore" });
|
||||
} catch {
|
||||
// best-effort
|
||||
}
|
||||
|
||||
console.error("✅ seal-use 已通过 Homebrew 成功更新!");
|
||||
|
||||
printJson({
|
||||
updated: true,
|
||||
previousVersion: VERSION,
|
||||
latestVersion,
|
||||
mode: "homebrew",
|
||||
serviceRestarted: wasRunning,
|
||||
message: alreadyLatest
|
||||
? `seal-use is already at the latest version v${latestVersion} in Homebrew`
|
||||
: `Successfully upgraded seal-use to v${latestVersion} via Homebrew`
|
||||
});
|
||||
}
|
||||
|
||||
type GitHubAsset = {
|
||||
name: string;
|
||||
downloadUrl: string;
|
||||
|
||||
Reference in new issue
Block a user