diff --git a/pr-checks/update-ghes-versions.ts b/pr-checks/update-ghes-versions.ts index 283601572..72e7fbe2f 100644 --- a/pr-checks/update-ghes-versions.ts +++ b/pr-checks/update-ghes-versions.ts @@ -6,9 +6,13 @@ * an `enterprise-releases` checkout. */ +import * as fs from "node:fs"; + import { type SemVer } from "semver"; import * as semver from "semver"; +import * as json from "../src/json"; + import { API_COMPATIBILITY_FILE } from "./config"; /** The first GHES version that included Code Scanning. */ @@ -19,6 +23,36 @@ export enum EnvVar { ENTERPRISE_RELEASES_PATH = "ENTERPRISE_RELEASES_PATH", } +/** The JSON schema for `API_COMPATIBILITY_FILE`. */ +const apiCompatibilitySchema = { + minimumVersion: json.string, + maximumVersion: json.string, +} as const satisfies json.Schema; + +/** The type representing the expected contents of `API_COMPATIBILITY_FILE`. */ +type ApiCompatibility = json.FromSchema; + +/** Reads the current contents of the `API_COMPATIBILITY_FILE` file. */ +export function readApiCompatibility(): ApiCompatibility { + const apiCompatibilityData: unknown = JSON.parse( + fs.readFileSync(API_COMPATIBILITY_FILE, "utf8"), + ); + + if (!json.isObject(apiCompatibilityData)) { + throw new Error( + `Expected '${API_COMPATIBILITY_FILE}' to contain an object.`, + ); + } + if (!json.validateSchema(apiCompatibilitySchema, apiCompatibilityData)) { + throw new Error( + `The contents of '${API_COMPATIBILITY_FILE}' do not match the expected JSON schema.`, + ); + } + + return apiCompatibilityData; +} + + function main() { const enterpriseReleasesPath = process.env[EnvVar.ENTERPRISE_RELEASES_PATH]; if (!enterpriseReleasesPath) { @@ -26,6 +60,9 @@ function main() { `${EnvVar.ENTERPRISE_RELEASES_PATH} environment variable must be set`, ); } + + // Get the version compatibility data stored in the repo. + const apiCompatibilityData = readApiCompatibility(); } // Only call `main` if this script was run directly.