diff --git a/src/llvm/llvm.ts b/src/llvm/llvm.ts index 073c78f0..2cfd82a6 100644 --- a/src/llvm/llvm.ts +++ b/src/llvm/llvm.ts @@ -4,7 +4,7 @@ import semverLte from "semver/functions/lte" import { isValidUrl } from "../utils/http/validate_url" import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin" import { extractExe, extractTarByExe } from "../utils/setup/extract" -import { getSpecificVersions, getVersions } from "../utils/setup/version" +import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version" //================================================ // Version @@ -212,24 +212,6 @@ function getUrl(platform: string, version: string): string | null | Promise { - if (!VERSIONS.has(version)) { - throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`) - } - - for (const specificVersion of getSpecificVersions(VERSIONS, version)) { - // eslint-disable-next-line no-await-in-loop - const url = await getUrl(platform, specificVersion) - // eslint-disable-next-line no-await-in-loop - if (url !== null && (await isValidUrl(url))) { - return [specificVersion, url] - } - } - - throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`) -} - //================================================ // Action //================================================ @@ -238,7 +220,7 @@ const DEFAULT_NIX_DIRECTORY = "./llvm" const DEFAULT_WIN32_DIRECTORY = "C:/Program Files/LLVM" async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): Promise { - const [specificVersion, url] = await getSpecificVersionAndUrl(platform, version) + const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, platform, version, getUrl) core.setOutput("version", specificVersion) return { url, diff --git a/src/utils/setup/version.ts b/src/utils/setup/version.ts index 3c572b91..bb9943ff 100644 --- a/src/utils/setup/version.ts +++ b/src/utils/setup/version.ts @@ -1,6 +1,8 @@ +import { isValidUrl } from "../http/validate_url" + /** - * Gets the specific LLVM versions supported by this action compatible with the supplied (specific or minimum) LLVM - * version in descending order of release (e.g., `5.0.2`, `5.0.1`, and `5.0.0` for `5`). + * Gets the specific versions supported by this action compatible with the supplied (specific or minimum) version in + * descending order of release (e.g., `5.0.2`, `5.0.1`, and `5.0.0` for `5`). */ export function getSpecificVersions(versions: Set, semversion: string): string[] { return Array.from(versions) @@ -10,8 +12,8 @@ export function getSpecificVersions(versions: Set, semversion: string): } /** - * Gets the specific and minimum LLVM versions that can be used to refer to the supplied specific LLVM versions (e.g., - * `3`, `3.5`, `3.5.2` for `3.5.2`). + * Gets the specific and minimum versions that can be used to refer to the supplied specific versions (e.g., `3`, `3.5`, + * `3.5.2` for `3.5.2`). */ export function getVersions(specific: string[]): Set { const versions = new Set(specific) @@ -23,3 +25,26 @@ export function getVersions(specific: string[]): Set { return versions } + +/** Gets the most recent specific version for which there is a valid download URL. */ +export async function getSpecificVersionAndUrl( + versions: Set, + platform: string, + version: string, + getUrl: (platform: string, version: string) => string | null | Promise +): Promise<[string, string]> { + if (!versions.has(version)) { + throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`) + } + + for (const specificVersion of getSpecificVersions(versions, version)) { + // eslint-disable-next-line no-await-in-loop + const url = await getUrl(platform, specificVersion) + // eslint-disable-next-line no-await-in-loop + if (url !== null && (await isValidUrl(url))) { + return [specificVersion, url] + } + } + + throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`) +}