Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/download.json
40 changes: 40 additions & 0 deletions scripts/fetch-downloads-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -22,6 +27,8 @@ const downloads: Downloads = {
releases: [],
};

const downloadJSON: DownloadJSON = {};

const getBinaries = (r: OctokitRelease) => {
const binaries = r.assets
.filter(
Expand Down Expand Up @@ -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();
}

Expand All @@ -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)
);
31 changes: 31 additions & 0 deletions src/download-json-types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Loading