Skip to content

Commit 60a839b

Browse files
committed
Fix upgrade bootstrap: publish legacy darwin/win32 asset aliases and add fallback in selectAsset
Old binaries (<=v1.1.0) look for 'github-code-search-darwin-arm64' in the release assets, but since v1.2.0 the CD pipeline only produces 'github-code-search-macos-arm64'. This creates a bootstrap failure: already-installed binaries cannot upgrade themselves. Two complementary fixes: - cd.yaml: after downloading artifacts, copy macos-*/windows-* to darwin-*/win32-* so that every release contains both naming conventions going forward. - upgrade.ts (selectAsset): try the canonical mapped name first (macos-arm64), then fall back to the raw Node.js platform name (darwin-arm64) for resilience. Closes #45.
1 parent 569bee1 commit 60a839b

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

.github/workflows/cd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ jobs:
8383
path: dist/
8484
merge-multiple: true
8585

86+
- name: Create legacy artifact aliases (backward-compat for upgrade)
87+
# Fix: binaries built before v1.2.1 look for darwin-* / win32-* asset names.
88+
# Publishing these aliases lets old binaries upgrade themselves — see issue #45.
89+
run: |
90+
cp dist/github-code-search-macos-arm64 dist/github-code-search-darwin-arm64
91+
cp dist/github-code-search-macos-x64 dist/github-code-search-darwin-x64
92+
cp dist/github-code-search-windows-x64.exe dist/github-code-search-win32-x64.exe
93+
8694
- name: Create release
8795
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
8896
with:

src/upgrade.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ describe("selectAsset", () => {
9393
it("returns null for empty asset list", () => {
9494
expect(selectAsset([], "darwin", "arm64")).toBeNull();
9595
});
96+
97+
describe("legacy fallback (pre-v1.2.1 asset names)", () => {
98+
const legacyAssets: ReleaseAsset[] = [
99+
makeAsset("github-code-search-darwin-arm64"),
100+
makeAsset("github-code-search-darwin-x64"),
101+
makeAsset("github-code-search-linux-x64"),
102+
makeAsset("github-code-search-linux-arm64"),
103+
makeAsset("github-code-search-win32-x64.exe"),
104+
];
105+
106+
it("falls back to darwin-arm64 when macos-arm64 is absent", () => {
107+
const asset = selectAsset(legacyAssets, "darwin", "arm64");
108+
expect(asset?.name).toBe("github-code-search-darwin-arm64");
109+
});
110+
111+
it("falls back to darwin-x64 when macos-x64 is absent", () => {
112+
const asset = selectAsset(legacyAssets, "darwin", "x64");
113+
expect(asset?.name).toBe("github-code-search-darwin-x64");
114+
});
115+
116+
it("falls back to win32-x64.exe when windows-x64.exe is absent", () => {
117+
const asset = selectAsset(legacyAssets, "win32", "x64");
118+
expect(asset?.name).toBe("github-code-search-win32-x64.exe");
119+
});
120+
121+
it("prefers canonical macos-arm64 over legacy darwin-arm64 when both present", () => {
122+
const mixed = [
123+
makeAsset("github-code-search-darwin-arm64"),
124+
makeAsset("github-code-search-macos-arm64"),
125+
];
126+
const asset = selectAsset(mixed, "darwin", "arm64");
127+
expect(asset?.name).toBe("github-code-search-macos-arm64");
128+
});
129+
});
96130
});
97131

98132
// ─── fetchLatestRelease ─────────────────────────────────────────────────────

src/upgrade.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,27 @@ export function isNewerVersion(current: string, latest: string): boolean {
4444
* Node.js/Bun platform names are mapped to artifact names:
4545
* darwin → macos
4646
* win32 → windows
47+
*
48+
* A legacy fallback also tries the raw Node.js platform name (darwin, win32)
49+
* so that binaries built before v1.2.1 can still upgrade themselves.
4750
*/
4851
export function selectAsset(
4952
assets: ReleaseAsset[],
5053
platform: string,
5154
arch: string,
5255
): ReleaseAsset | null {
53-
const platformMap: Record<string, string> = { darwin: "macos", win32: "windows" };
56+
const platformMap: Record<string, string> = {
57+
darwin: "macos",
58+
win32: "windows",
59+
};
5460
const artifactPlatform = platformMap[platform] ?? platform;
5561
const suffix = artifactPlatform === "windows" ? ".exe" : "";
5662
const name = `github-code-search-${artifactPlatform}-${arch}${suffix}`;
57-
return assets.find((a) => a.name === name) ?? null;
63+
// Fix: fall back to legacy platform names (darwin, win32) published alongside
64+
// the canonical names for backward-compat with pre-v1.2.1 binaries — see issue #45
65+
const legacySuffix = platform === "win32" ? ".exe" : "";
66+
const legacyName = `github-code-search-${platform}-${arch}${legacySuffix}`;
67+
return assets.find((a) => a.name === name) ?? assets.find((a) => a.name === legacyName) ?? null;
5868
}
5969

6070
// ─── GitHub API ───────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)