From 32ecab6fd907733048df5953053622db389559f4 Mon Sep 17 00:00:00 2001 From: Julien Pivotto <291750+roidelapluie@users.noreply.github.com> Date: Wed, 17 Jun 2026 14:34:06 +0200 Subject: [PATCH] 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> --- public/download.json | 1 + scripts/fetch-downloads-info.ts | 40 +++++++++++++++++++++++++++++++++ src/download-json-types.ts | 31 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 120000 public/download.json create mode 100644 src/download-json-types.ts diff --git a/public/download.json b/public/download.json new file mode 120000 index 000000000..4ee94d855 --- /dev/null +++ b/public/download.json @@ -0,0 +1 @@ +../generated/download.json \ No newline at end of file diff --git a/scripts/fetch-downloads-info.ts b/scripts/fetch-downloads-info.ts index ed609628b..4a5f2afb0 100644 --- a/scripts/fetch-downloads-info.ts +++ b/scripts/fetch-downloads-info.ts @@ -4,6 +4,11 @@ import * as fs from "fs"; import * as path from "path"; import docsConfig from "../docs-config"; import { Downloads, Release, Binary } from "@/downloads-metadata-types"; +import { + DownloadJSON, + DownloadRelease, + DownloadFile, +} from "@/download-json-types"; import { compareFullVersion, filterUnique, majorMinor } from "./utils"; const OUTDIR = "./generated"; @@ -22,6 +27,8 @@ const downloads: Downloads = { releases: [], }; +const downloadJSON: DownloadJSON = {}; + const getBinaries = (r: OctokitRelease) => { const binaries = r.assets .filter( @@ -155,6 +162,33 @@ for (const repoName of docsConfig.downloads.repos) { ), }); + // Build the machine-readable download.json entries for this repo. + // shownReleases is sorted newest first, so the first non-prerelease is the + // latest stable release. + const latestStableID = shownReleases.find((r) => !r.prerelease)?.id; + + downloadJSON[repoName] = shownReleases.map( + (r): DownloadRelease => ({ + version: r.tag_name, + stable: !r.prerelease, + latest: r.id === latestStableID, + lts: + docsConfig.ltsVersions[repoName]?.includes(majorMinor(r.tag_name)) ?? + false, + files: getBinaries(r).map( + (b): DownloadFile => ({ + url: b.url, + os: b.os, + arch: b.arch, + version: r.tag_name, + sha256: b.checksum, + size: b.sizeBytes, + kind: "archive", + }) + ), + }) + ); + console.groupEnd(); } @@ -181,3 +215,9 @@ fs.writeFileSync( path.join(OUTDIR, "downloads-metadata.json"), JSON.stringify(downloads, null, 2) ); + +console.log(`Writing download.json to ${OUTDIR}/download.json`); +fs.writeFileSync( + path.join(OUTDIR, "download.json"), + JSON.stringify(downloadJSON, null, 2) +); diff --git a/src/download-json-types.ts b/src/download-json-types.ts new file mode 100644 index 000000000..2951ecbbe --- /dev/null +++ b/src/download-json-types.ts @@ -0,0 +1,31 @@ +// Types for the machine-readable download.json served at the site root. +// The per-release shape intentionally mirrors Go's +// https://go.dev/dl/?mode=json (version.json) so that tooling can consume it +// in a familiar way, with Prometheus-specific "latest" and "lts" flags added. +// The top level is keyed by repository name, exposing every repository shown +// on the downloads page. + +export type DownloadJSON = { + [repo: string]: DownloadRelease[]; +}; + +export type DownloadRelease = { + version: string; + // stable is true for non-prerelease versions. + stable: boolean; + // latest is true for the most recent stable release of the repository. + latest: boolean; + // lts is true for long-term support releases. + lts: boolean; + files: DownloadFile[]; +}; + +export type DownloadFile = { + url: string; + os: string; + arch: string; + version: string; + sha256: string; + size: number; + kind: string; +};