Skip to content

Commit bf34f76

Browse files
t3dotggonly21milclaude
committed
fix(install): stable installs no longer fail behind a page of nightlies
The install scripts read one page of 100 GitHub releases, so a stable install failed once 100 nightlies were newer than the latest stable release. Stable now reads github.com/<repo>/releases/latest as JSON. release.yml marks only plain stable releases latest, and this page is not under the anonymous API quota. Nightly and preview page the releases API, up to 10 pages. Co-authored-by: Victor Vogel <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8d3b061 commit bf34f76

3 files changed

Lines changed: 109 additions & 6 deletions

File tree

‎scripts/install.ps1‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,19 @@ if (-not $version) {
139139
"preview" { '^v\d+\.\d+\.\d+-preview\.\d+\.\d+$' }
140140
default { Fail "T3CODE_CHANNEL must be stable, nightly, or preview" }
141141
}
142-
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases?per_page=100" -Headers @{ "User-Agent" = "t3-install" }
143-
$tag = ($releases | Where-Object { -not $_.draft -and $_.tag_name -match $tagPattern } | Select-Object -First 1).tag_name
142+
if ($channel -eq "stable") {
143+
# release.yml marks only plain stable releases latest. This is a github.com
144+
# page, so it is not cut off by a page of newer nightlies or the API quota.
145+
$release = Invoke-RestMethod -Uri "https://github.com/$repo/releases/latest" -Headers @{ "User-Agent" = "t3-install"; "Accept" = "application/json" }
146+
$tag = ($release | Where-Object { $_.tag_name -match $tagPattern }).tag_name
147+
} else {
148+
$tag = $null
149+
for ($page = 1; -not $tag -and $page -le 10; $page++) {
150+
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases?per_page=100&page=$page" -Headers @{ "User-Agent" = "t3-install" }
151+
$tag = ($releases | Where-Object { -not $_.draft -and $_.tag_name -match $tagPattern } | Select-Object -First 1).tag_name
152+
if (-not $releases) { break }
153+
}
154+
}
144155
if (-not $tag) { Fail "could not find a $channel release; set T3CODE_VERSION" }
145156
$version = $tag.Substring(1)
146157
}

‎scripts/install.sh‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ step "Finding your release..."
5353
# Exit 44 on a 404 so callers can tell "no such asset" from a network failure.
5454
fetch() {
5555
if command -v curl >/dev/null 2>&1; then
56-
status="$(curl -sSL -w '%{http_code}' "$1" -o "$2")" || return 1
56+
status="$(curl -sSL -H "Accept: ${3:-*/*}" -w '%{http_code}' "$1" -o "$2")" || return 1
5757
case "$status" in
5858
2??) return 0 ;;
5959
404) return 44 ;;
6060
*) printf 'GET %s returned HTTP %s\n' "$1" "$status" >&2; return 1 ;;
6161
esac
6262
elif command -v wget >/dev/null 2>&1; then
63-
wget -q --server-response "$1" -O "$2" 2>"$2.headers" && rm -f "$2.headers" && return 0
63+
wget -q --server-response --header="Accept: ${3:-*/*}" "$1" -O "$2" 2>"$2.headers" && rm -f "$2.headers" && return 0
6464
if grep -q ' 404 ' "$2.headers" 2>/dev/null; then rm -f "$2.headers"; return 44; fi
6565
cat "$2.headers" >&2; rm -f "$2.headers"; return 1
6666
else
@@ -154,8 +154,20 @@ if [ -z "$version" ]; then
154154
*) fail "T3CODE_CHANNEL must be stable, nightly, or preview" ;;
155155
esac
156156
tmp_index="$(mktemp)"
157-
fetch "https://api.github.com/repos/${repo}/releases?per_page=100" "$tmp_index"
158-
version="$(sed -n "s/.*\"tag_name\": *\"${tag_pattern}\".*/\1/p" "$tmp_index" | head -n 1)"
157+
if [ "$channel" = stable ]; then
158+
# release.yml marks only plain stable releases latest. This is a github.com
159+
# page, so it is not cut off by a page of newer nightlies or the API quota.
160+
fetch "https://github.com/${repo}/releases/latest" "$tmp_index" application/json
161+
version="$(sed -n "s/.*\"tag_name\": *\"${tag_pattern}\".*/\1/p" "$tmp_index" | head -n 1)"
162+
else
163+
page=1
164+
while [ -z "$version" ] && [ "$page" -le 10 ]; do
165+
fetch "https://api.github.com/repos/${repo}/releases?per_page=100&page=${page}" "$tmp_index"
166+
version="$(sed -n "s/.*\"tag_name\": *\"${tag_pattern}\".*/\1/p" "$tmp_index" | head -n 1)"
167+
grep -q '"tag_name"' "$tmp_index" || break
168+
page=$((page + 1))
169+
done
170+
fi
159171
rm -f "$tmp_index"
160172
[ -n "$version" ] || fail "could not find a ${channel} release; set T3CODE_VERSION"
161173
fi

‎scripts/install.test.ts‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// @effect-diagnostics nodeBuiltinImport:off - Drives the real shell installer against a local GitHub fixture.
2+
import * as HostProcess from "@t3tools/shared/HostProcess";
3+
import * as NodeChildProcess from "node:child_process";
4+
import * as NodeFSP from "node:fs/promises";
5+
import * as NodeHttp from "node:http";
6+
import * as NodeOS from "node:os";
7+
import * as NodePath from "node:path";
8+
import { describe, expect, it } from "vite-plus/test";
9+
10+
const nightlies = Array.from({ length: 100 }, (_, index) => ({
11+
tag_name: `v1.2.4-nightly.20261020.${200 - index}`,
12+
}));
13+
14+
// regression: #22490
15+
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer channel lookup", () => {
16+
it.each([
17+
["stable", "1.2.3"],
18+
["preview", "1.2.4-preview.20261019.50"],
19+
])("finds the newest %s release behind a full page of nightlies", async (channel, version) => {
20+
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-index-"));
21+
const target = NodePath.join(root, "home/runtime/versions", version);
22+
const server = NodeHttp.createServer((request, response) => {
23+
const url = new URL(request.url ?? "/", "http://fixture");
24+
const body =
25+
url.pathname === "/pingdotgg/t3code/releases/latest" &&
26+
request.headers.accept === "application/json"
27+
? { tag_name: "v1.2.3" }
28+
: url.pathname === "/repos/pingdotgg/t3code/releases"
29+
? { "1": nightlies, "2": [{ tag_name: `v${version}` }, { tag_name: "v1.2.3" }] }[
30+
url.searchParams.get("page") ?? ""
31+
]
32+
: undefined;
33+
if (body === undefined) response.statusCode = 404;
34+
// The API pretty-prints and the installer reads it line by line.
35+
response.end(JSON.stringify(body ?? [], null, 2));
36+
});
37+
try {
38+
// An existing completed install isolates release resolution from archive downloads.
39+
await NodeFSP.mkdir(target, { recursive: true });
40+
await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), `${version}\n`);
41+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
42+
const address = server.address();
43+
if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
44+
const origin = `http://127.0.0.1:${address.port}`;
45+
const source = await NodeFSP.readFile(
46+
NodePath.resolve(import.meta.dirname, "install.sh"),
47+
"utf8",
48+
);
49+
const installer = NodePath.join(root, "install.sh");
50+
await NodeFSP.writeFile(installer, source.replace(/https:\/\/(api\.)?github\.com/g, origin));
51+
const { code, output } = await new Promise<{ code: number | null; output: string }>(
52+
(resolve, reject) => {
53+
const child = NodeChildProcess.spawn("sh", [installer], {
54+
env: {
55+
...process.env,
56+
T3CODE_VERSION: "",
57+
T3CODE_CHANNEL: channel,
58+
T3CODE_HOME: NodePath.join(root, "home"),
59+
T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin"),
60+
// A wrong version must fail here instead of downloading a real release.
61+
T3CODE_RELEASE_BASE_URL: origin,
62+
},
63+
stdio: ["ignore", "pipe", "pipe"],
64+
});
65+
let output = "";
66+
child.stdout.on("data", (chunk: Buffer) => (output += chunk.toString()));
67+
child.stderr.on("data", (chunk: Buffer) => (output += chunk.toString()));
68+
child.on("error", reject);
69+
child.on("close", (code) => resolve({ code, output }));
70+
},
71+
);
72+
expect(code, output).toBe(0);
73+
expect(output).toContain(`Installed T3 Code ${version}`);
74+
} finally {
75+
server.closeAllConnections();
76+
await new Promise<void>((resolve) => server.close(() => resolve()));
77+
await NodeFSP.rm(root, { recursive: true, force: true });
78+
}
79+
});
80+
});

0 commit comments

Comments
 (0)