Skip to content

Commit ef1ce2f

Browse files
committed
Dynamically fetch latest stable release installer
Fetch the install-linux-release asset from the latest GitHub release instead of pointing to the main branch. Falls back to main branch URL if the API call fails. The endpoint now serves immutable release assets with a 5-minute CDN cache.
1 parent 0129cf6 commit ef1ce2f

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ nteract Linux installer.
66
The endpoint intentionally stays separate from the marketing site. It serves
77
plain shell, not HTML, and it does not install agent-specific integrations.
88

9-
The bootstrap currently downloads the merged desktop installer from
10-
`raw.githubusercontent.com/nteract/desktop/main/scripts/install-linux-release`.
11-
If desktop releases later publish the installer as a release asset, switch the
12-
bootstrap URL to that immutable release asset.
9+
The bootstrap dynamically fetches the latest stable release's
10+
`install-linux-release` asset from GitHub releases. Falls back to the main
11+
branch version if the API call fails.
1312

1413
## Local development
1514

api/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { installerScript } from "../lib/script.js";
1+
import { installerScript, getLatestStableInstallerUrl } from "../lib/script.js";
22

3-
export default function handler(request, response) {
3+
export default async function handler(request, response) {
44
response.setHeader("Content-Type", "text/x-shellscript; charset=utf-8");
55
response.setHeader("Cache-Control", "public, max-age=300, s-maxage=300");
66
response.setHeader("X-Content-Type-Options", "nosniff");
7-
response.status(200).send(installerScript());
7+
8+
const installerUrl = await getLatestStableInstallerUrl();
9+
response.status(200).send(installerScript(installerUrl));
810
}

lib/script.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
const DEFAULT_INSTALLER_URL =
1+
const FALLBACK_INSTALLER_URL =
22
"https://raw.githubusercontent.com/nteract/desktop/main/scripts/install-linux-release";
33

4-
export function installerScript(installerUrl = DEFAULT_INSTALLER_URL) {
4+
/**
5+
* Fetch the latest stable release's install-linux-release asset URL.
6+
* Returns fallback URL on error.
7+
*/
8+
export async function getLatestStableInstallerUrl() {
9+
try {
10+
const res = await fetch(
11+
"https://api.github.com/repos/nteract/desktop/releases/latest",
12+
{
13+
headers: { Accept: "application/vnd.github.v3+json" },
14+
}
15+
);
16+
if (!res.ok) return FALLBACK_INSTALLER_URL;
17+
18+
const release = await res.json();
19+
const asset = release.assets?.find((a) => a.name === "install-linux-release");
20+
return asset?.browser_download_url || FALLBACK_INSTALLER_URL;
21+
} catch {
22+
return FALLBACK_INSTALLER_URL;
23+
}
24+
}
25+
26+
export function installerScript(installerUrl) {
527
return `#!/bin/sh
628
set -eu
729

0 commit comments

Comments
 (0)