diff --git a/src/llvm/llvm.ts b/src/llvm/llvm.ts index 5fe24251..073c78f0 100644 --- a/src/llvm/llvm.ts +++ b/src/llvm/llvm.ts @@ -4,26 +4,12 @@ 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" //================================================ // Version //================================================ -/** - * 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`). - */ -function getVersions(specific: string[]): Set { - const versions = new Set(specific) - - for (const version of specific) { - versions.add(/^\d+/.exec(version)![0]) - versions.add(/^\d+\.\d+/.exec(version)![0]) - } - - return versions -} - /** The specific and minimum LLVM versions supported by this action. */ const VERSIONS: Set = getVersions([ "3.5.0", @@ -61,17 +47,6 @@ const VERSIONS: Set = getVersions([ "12.0.1", ]) -/** - * 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`). - */ -function getSpecificVersions(version: string): string[] { - return Array.from(VERSIONS) - .filter((v) => /^\d+\.\d+\.\d+$/.test(v) && v.startsWith(version)) - .sort() - .reverse() -} - //================================================ // URL //================================================ @@ -243,7 +218,7 @@ export async function getSpecificVersionAndUrl(platform: string, version: string throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`) } - for (const specificVersion of getSpecificVersions(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 diff --git a/src/utils/setup/version.ts b/src/utils/setup/version.ts new file mode 100644 index 00000000..3c572b91 --- /dev/null +++ b/src/utils/setup/version.ts @@ -0,0 +1,25 @@ +/** + * 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`). + */ +export function getSpecificVersions(versions: Set, semversion: string): string[] { + return Array.from(versions) + .filter((v) => /^\d+\.\d+\.\d+$/.test(v) && v.startsWith(semversion)) + .sort() + .reverse() +} + +/** + * 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`). + */ +export function getVersions(specific: string[]): Set { + const versions = new Set(specific) + + for (const version of specific) { + versions.add(/^\d+/.exec(version)![0]) + versions.add(/^\d+\.\d+/.exec(version)![0]) + } + + return versions +}