Skip to content

Commit 3dd2f04

Browse files
committed
Serve machine-readable download.json at site root
Add a download.json, served at https://prometheus.io/download.json, listing the releases of every repository shown on the downloads page. The per-release shape mirrors Go's version.json (version, stable, files with os/arch/sha256/ size), with Prometheus-specific "latest" and "lts" flags added. The file is generated by fetch-downloads-info.ts into generated/ and exposed at the site root via a committed symlink in public/, matching the existing repo-docs-assets mechanism. Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
1 parent 8ee9b25 commit 3dd2f04

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

public/download.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../generated/download.json

scripts/fetch-downloads-info.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import * as fs from "fs";
44
import * as path from "path";
55
import docsConfig from "../docs-config";
66
import { Downloads, Release, Binary } from "@/downloads-metadata-types";
7+
import {
8+
DownloadJSON,
9+
DownloadRelease,
10+
DownloadFile,
11+
} from "@/download-json-types";
712
import { compareFullVersion, filterUnique, majorMinor } from "./utils";
813

914
const OUTDIR = "./generated";
@@ -22,6 +27,8 @@ const downloads: Downloads = {
2227
releases: [],
2328
};
2429

30+
const downloadJSON: DownloadJSON = {};
31+
2532
const getBinaries = (r: OctokitRelease) => {
2633
const binaries = r.assets
2734
.filter(
@@ -155,6 +162,33 @@ for (const repoName of docsConfig.downloads.repos) {
155162
),
156163
});
157164

165+
// Build the machine-readable download.json entries for this repo.
166+
// shownReleases is sorted newest first, so the first non-prerelease is the
167+
// latest stable release.
168+
const latestStableID = shownReleases.find((r) => !r.prerelease)?.id;
169+
170+
downloadJSON[repoName] = shownReleases.map(
171+
(r): DownloadRelease => ({
172+
version: r.tag_name,
173+
stable: !r.prerelease,
174+
latest: r.id === latestStableID,
175+
lts:
176+
docsConfig.ltsVersions[repoName]?.includes(majorMinor(r.tag_name)) ??
177+
false,
178+
files: getBinaries(r).map(
179+
(b): DownloadFile => ({
180+
filename: b.name,
181+
os: b.os,
182+
arch: b.arch,
183+
version: r.tag_name,
184+
sha256: b.checksum,
185+
size: b.sizeBytes,
186+
kind: "archive",
187+
})
188+
),
189+
})
190+
);
191+
158192
console.groupEnd();
159193
}
160194

@@ -181,3 +215,9 @@ fs.writeFileSync(
181215
path.join(OUTDIR, "downloads-metadata.json"),
182216
JSON.stringify(downloads, null, 2)
183217
);
218+
219+
console.log(`Writing download.json to ${OUTDIR}/download.json`);
220+
fs.writeFileSync(
221+
path.join(OUTDIR, "download.json"),
222+
JSON.stringify(downloadJSON, null, 2)
223+
);

src/download-json-types.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Types for the machine-readable download.json served at the site root.
2+
// The per-release shape intentionally mirrors Go's
3+
// https://go.dev/dl/?mode=json (version.json) so that tooling can consume it
4+
// in a familiar way, with Prometheus-specific "latest" and "lts" flags added.
5+
// The top level is keyed by repository name, exposing every repository shown
6+
// on the downloads page.
7+
8+
export type DownloadJSON = {
9+
[repo: string]: DownloadRelease[];
10+
};
11+
12+
export type DownloadRelease = {
13+
version: string;
14+
// stable is true for non-prerelease versions.
15+
stable: boolean;
16+
// latest is true for the most recent stable release of the repository.
17+
latest: boolean;
18+
// lts is true for long-term support releases.
19+
lts: boolean;
20+
files: DownloadFile[];
21+
};
22+
23+
export type DownloadFile = {
24+
filename: string;
25+
os: string;
26+
arch: string;
27+
version: string;
28+
sha256: string;
29+
size: number;
30+
kind: string;
31+
};

0 commit comments

Comments
 (0)