From ecb2fc4799438381794fdcec91556d48264d0b38 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Sat, 8 Mar 2025 11:56:34 +0900 Subject: [PATCH] Don't make heavy API requests multiple times Signed-off-by: Sora Morimoto --- dist/index.js | 322 +++++++++++++------------- dist/post/index.js | 205 ++++++++-------- packages/setup-ocaml/src/cache.ts | 16 +- packages/setup-ocaml/src/constants.ts | 9 +- packages/setup-ocaml/src/installer.ts | 4 +- packages/setup-ocaml/src/opam.ts | 6 +- packages/setup-ocaml/src/version.ts | 12 +- packages/setup-ocaml/src/windows.ts | 6 +- 8 files changed, 288 insertions(+), 292 deletions(-) diff --git a/dist/index.js b/dist/index.js index a370d330..48577caa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -146831,6 +146831,102 @@ var lib_github = __nccwpck_require__(58064); var lib = __nccwpck_require__(8134); // EXTERNAL MODULE: ../../node_modules/yaml/dist/index.js var dist = __nccwpck_require__(33483); +;// CONCATENATED MODULE: ./src/constants.ts + + + + + +const ARCHITECTURE = (() => { + switch (external_node_process_.arch) { + case "arm": { + return "armhf"; + } + case "arm64": { + return "arm64"; + } + case "riscv64": { + return "riscv64"; + } + case "s390x": { + return "s390x"; + } + case "x64": { + return "x86_64"; + } + default: { + throw new Error(`'${external_node_process_.arch}' is not supported. Supported architectures: arm, arm64, riscv64, s390x, x64`); + } + } +})(); +const PLATFORM = (() => { + switch (external_node_process_.platform) { + case "darwin": { + return "macos"; + } + case "freebsd": { + return "freebsd"; + } + case "linux": { + return "linux"; + } + case "openbsd": { + return "openbsd"; + } + case "win32": { + return "windows"; + } + default: { + throw new Error(`'${external_node_process_.platform}' is not supported. Supported platforms: darwin, freebsd, linux, openbsd, win32`); + } + } +})(); +const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/"; +const GITHUB_WORKSPACE = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); +const CYGWIN_MIRROR_ENCODED_URI = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); +// [HACK] https://github.com/ocaml/setup-ocaml/pull/55 +const CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); +const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bin"); +const CYGWIN_BASH_ENV = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bash_env"); +const DUNE_CACHE_ROOT = (() => { + const xdgCacheHome = external_node_process_.env.XDG_CACHE_HOME; + if (xdgCacheHome) { + return external_node_path_namespaceObject.join(xdgCacheHome, "dune"); + } + if (PLATFORM === "windows") { + // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 + return external_node_path_namespaceObject.join("D:", "dune"); + } + return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".cache", "dune"); +})(); +const OPAM_ROOT = (() => { + if (PLATFORM === "windows") { + // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 + return external_node_path_namespaceObject.join("D:", ".opam"); + } + return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".opam"); +})(); +const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam"); +const CACHE_PREFIX = lib_core.getInput("cache-prefix"); +const constants_GITHUB_TOKEN = lib_core.getInput("github-token"); +const DUNE_CACHE = lib_core.getBooleanInput("dune-cache"); +const OCAML_COMPILER = lib_core.getInput("ocaml-compiler", { + required: true, +}); +const OPAM_DISABLE_SANDBOXING = +// [TODO] unlock this once sandboxing is supported on Windows +PLATFORM !== "windows" && lib_core.getBooleanInput("opam-disable-sandboxing"); +const OPAM_LOCAL_PACKAGES = lib_core.getInput("opam-local-packages"); +const OPAM_PIN = lib_core.getBooleanInput("opam-pin"); +const OPAM_REPOSITORIES = (() => { + const repositoriesYaml = dist/* parse */.qg(lib_core.getInput("opam-repositories")); + return Object.entries(repositoriesYaml).reverse(); +})(); + +;// CONCATENATED MODULE: external "node:fs" +const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); +// EXTERNAL MODULE: ../../node_modules/@actions/tool-cache/lib/tool-cache.js +var tool_cache = __nccwpck_require__(60532); // EXTERNAL MODULE: ../../node_modules/bottleneck/light.js var light = __nccwpck_require__(46503); ;// CONCATENATED MODULE: ../../node_modules/@octokit/plugin-retry/node_modules/@octokit/request-error/dist-src/index.js @@ -146954,155 +147050,6 @@ dist_bundle_retry.VERSION = VERSION; // EXTERNAL MODULE: ../../node_modules/semver/index.js var semver = __nccwpck_require__(90084); -;// CONCATENATED MODULE: ./src/version.ts - - - - - -function isSemverValidRange(semverVersion) { - return semver.validRange(semverVersion, { loose: true }) !== null; -} -async function retrieveAllCompilerVersions() { - const octokit = lib_github.getOctokit(constants_GITHUB_TOKEN, undefined, dist_bundle_retry); - const { data: packages } = await octokit.rest.repos.getContent({ - owner: "ocaml", - repo: "opam-repository", - path: "packages/ocaml-base-compiler", - }); - const versions = new Set(); - if (Array.isArray(packages)) { - for (const { path: p } of packages) { - const basename = external_node_path_namespaceObject.basename(p); - const version = basename.replace("ocaml-base-compiler.", ""); - const parsed = semver.parse(version, { loose: true }); - if (parsed !== null) { - const { major, minor: _minor, patch } = parsed; - const minor = major < 5 && _minor < 10 - ? // ocaml-base-compiler.4.00.0, ocaml-base-compiler.4.01.0 - `0${_minor}` - : // ocaml-base-compiler.5.3.0, ocaml-base-compiler.4.14.2 - _minor; - const version = `${major}.${minor}.${patch}`; - versions.add(version); - } - } - } - return [...versions]; -} -async function resolveVersion(semverVersion) { - const compilerVersions = await retrieveAllCompilerVersions(); - const matchedFullCompilerVersion = semver.maxSatisfying(compilerVersions, semverVersion, { loose: true }); - if (matchedFullCompilerVersion === null) { - throw new Error(`Could not find any OCaml compiler version matching '${semverVersion}' in the opam-repository. Please check if you specified a valid version number or version range.`); - } - return matchedFullCompilerVersion; -} -async function resolveCompiler(compiler) { - const resolvedCompiler = isSemverValidRange(compiler) - ? `ocaml-base-compiler.${await resolveVersion(compiler)}` - : compiler; - return resolvedCompiler; -} - -;// CONCATENATED MODULE: ./src/constants.ts - - - - - - -const ARCHITECTURE = (() => { - switch (external_node_process_.arch) { - case "arm": { - return "armhf"; - } - case "arm64": { - return "arm64"; - } - case "riscv64": { - return "riscv64"; - } - case "s390x": { - return "s390x"; - } - case "x64": { - return "x86_64"; - } - default: { - throw new Error(`'${external_node_process_.arch}' is not supported. Supported architectures: arm, arm64, riscv64, s390x, x64`); - } - } -})(); -const PLATFORM = (() => { - switch (external_node_process_.platform) { - case "darwin": { - return "macos"; - } - case "freebsd": { - return "freebsd"; - } - case "linux": { - return "linux"; - } - case "openbsd": { - return "openbsd"; - } - case "win32": { - return "windows"; - } - default: { - throw new Error(`'${external_node_process_.platform}' is not supported. Supported platforms: darwin, freebsd, linux, openbsd, win32`); - } - } -})(); -const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/"; -const GITHUB_WORKSPACE = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); -const CYGWIN_MIRROR_ENCODED_URI = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); -// [HACK] https://github.com/ocaml/setup-ocaml/pull/55 -const CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); -const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bin"); -const CYGWIN_BASH_ENV = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bash_env"); -const DUNE_CACHE_ROOT = (() => { - const xdgCacheHome = external_node_process_.env.XDG_CACHE_HOME; - if (xdgCacheHome) { - return external_node_path_namespaceObject.join(xdgCacheHome, "dune"); - } - if (PLATFORM === "windows") { - // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 - return external_node_path_namespaceObject.join("D:", "dune"); - } - return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".cache", "dune"); -})(); -const OPAM_ROOT = (() => { - if (PLATFORM === "windows") { - // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 - return external_node_path_namespaceObject.join("D:", ".opam"); - } - return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".opam"); -})(); -const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam"); -const CACHE_PREFIX = lib_core.getInput("cache-prefix"); -const constants_GITHUB_TOKEN = lib_core.getInput("github-token"); -const DUNE_CACHE = lib_core.getBooleanInput("dune-cache"); -const OCAML_COMPILER = lib_core.getInput("ocaml-compiler", { required: true }); -const OPAM_DISABLE_SANDBOXING = -// [TODO] unlock this once sandboxing is supported on Windows -PLATFORM !== "windows" && lib_core.getBooleanInput("opam-disable-sandboxing"); -const OPAM_LOCAL_PACKAGES = lib_core.getInput("opam-local-packages"); -const OPAM_PIN = lib_core.getBooleanInput("opam-pin"); -const OPAM_REPOSITORIES = (() => { - const repositoriesYaml = dist/* parse */.qg(lib_core.getInput("opam-repositories")); - return Object.entries(repositoriesYaml).reverse(); -})(); -const RESOLVED_COMPILER = (async () => { - return await resolveCompiler(OCAML_COMPILER); -})(); - -;// CONCATENATED MODULE: external "node:fs" -const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); -// EXTERNAL MODULE: ../../node_modules/@actions/tool-cache/lib/tool-cache.js -var tool_cache = __nccwpck_require__(60532); ;// CONCATENATED MODULE: ./src/unix.ts @@ -147181,7 +147128,7 @@ async function updateUnixPackageIndexFiles() { -async function retrieveLatestOpamRelease() { +const latestOpamRelease = (async () => { const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.4.0"; const octokit = lib_github.getOctokit(constants_GITHUB_TOKEN, undefined, dist_bundle_retry); const { data: releases } = await octokit.rest.repos.listReleases({ @@ -147211,10 +147158,10 @@ async function retrieveLatestOpamRelease() { version: latestRelease.tag_name, browserDownloadUrl: matchedAssets.browser_download_url, }; -} +})(); async function acquireOpam() { await lib_core.group("Installing opam", async () => { - const { version, browserDownloadUrl } = await retrieveLatestOpamRelease(); + const { version, browserDownloadUrl } = await latestOpamRelease; const cachedPath = tool_cache.find("opam", version, ARCHITECTURE); const opam = PLATFORM !== "windows" ? "opam" : "opam.exe"; if (cachedPath === "") { @@ -147336,6 +147283,57 @@ async function update() { }); } +;// CONCATENATED MODULE: ./src/version.ts + + + + + +function isSemverValidRange(semverVersion) { + return semver.validRange(semverVersion, { loose: true }) !== null; +} +async function retrieveAllCompilerVersions() { + const octokit = lib_github.getOctokit(constants_GITHUB_TOKEN, undefined, dist_bundle_retry); + const { data: packages } = await octokit.rest.repos.getContent({ + owner: "ocaml", + repo: "opam-repository", + path: "packages/ocaml-base-compiler", + }); + const versions = new Set(); + if (Array.isArray(packages)) { + for (const { path: p } of packages) { + const basename = external_node_path_namespaceObject.basename(p); + const version = basename.replace("ocaml-base-compiler.", ""); + const parsed = semver.parse(version, { loose: true }); + if (parsed !== null) { + const { major, minor: _minor, patch } = parsed; + const minor = major < 5 && _minor < 10 + ? // ocaml-base-compiler.4.00.0, ocaml-base-compiler.4.01.0 + `0${_minor}` + : // ocaml-base-compiler.5.3.0, ocaml-base-compiler.4.14.2 + _minor; + const version = `${major}.${minor}.${patch}`; + versions.add(version); + } + } + } + return [...versions]; +} +async function resolveVersion(semverVersion) { + const compilerVersions = await retrieveAllCompilerVersions(); + const matchedFullCompilerVersion = semver.maxSatisfying(compilerVersions, semverVersion, { loose: true }); + if (matchedFullCompilerVersion === null) { + throw new Error(`Could not find any OCaml compiler version matching '${semverVersion}' in the opam-repository. Please check if you specified a valid version number or version range.`); + } + return matchedFullCompilerVersion; +} +const resolvedCompiler = (async () => { + const resolvedCompiler = isSemverValidRange(OCAML_COMPILER) + ? `ocaml-base-compiler.${await resolveVersion(OCAML_COMPILER)}` + : OCAML_COMPILER; + return resolvedCompiler; +})(); + // EXTERNAL MODULE: ../../node_modules/@actions/http-client/lib/index.js var http_client_lib = __nccwpck_require__(9920); // EXTERNAL MODULE: ../../node_modules/@actions/io/lib/io.js @@ -165800,7 +165798,7 @@ async function fromURL(url, options = {}) { function createHttpClient() { return new http_client_lib.HttpClient("OCamlBot (+https://github.com/ocaml/setup-ocaml)", [], { allowRetries: true, maxRetries: 5 }); } -async function retrieveCygwinVersion() { +const cygwinVersion = (async () => { const httpClient = createHttpClient(); const response = await httpClient.get("https://www.cygwin.com"); const body = await response.readBody(); @@ -165813,7 +165811,7 @@ async function retrieveCygwinVersion() { } }); return version; -} +})(); async function setGitToIgnoreCygwinLocalPackageDirectory() { const xdgConfigHome = process.env.XDG_CONFIG_HOME; const homeDir = external_node_os_.homedir(); @@ -165845,7 +165843,7 @@ async function setGitToIgnoreCygwinLocalPackageDirectory() { async function setupCygwin() { await lib_core.group("Setting up Cygwin environment", async () => { await setGitToIgnoreCygwinLocalPackageDirectory(); - const version = await retrieveCygwinVersion(); + const version = await cygwinVersion; const cachedPath = tool_cache.find("cygwin", version, "x86_64"); if (cachedPath === "") { const downloadedPath = await tool_cache.downloadTool("https://cygwin.com/setup-x86_64.exe"); @@ -165894,15 +165892,16 @@ async function setupCygwin() { + async function composeCygwinCacheKeys() { - const cygwinVersion = await retrieveCygwinVersion(); - const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${cygwinVersion}`; + const version = await cygwinVersion; + const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${version}`; const restoreKeys = [key]; return { key, restoreKeys }; } async function composeDuneCacheKeys() { const { workflow, job, runId } = lib_github.context; - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; const plainKey = [ocamlCompiler, workflow, job].join(); const hash = external_node_crypto_.createHash("sha256").update(plainKey).digest("hex"); const key = `${CACHE_PREFIX}-setup-ocaml-dune-${PLATFORM}-${ARCHITECTURE}-${hash}-${runId}`; @@ -165915,9 +165914,9 @@ async function composeDuneCacheKeys() { return { key, restoreKeys }; } async function composeOpamCacheKeys() { - const { version: opamVersion } = await retrieveLatestOpamRelease(); + const { version: opamVersion } = await latestOpamRelease; const sandbox = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; const repositoryUrls = OPAM_REPOSITORIES.map(([_, value]) => value).join(); const osInfo = await lib.osInfo(); const plainKey = [ @@ -166119,6 +166118,7 @@ async function retrieveOpamLocalPackages() { + async function installer() { if (lib_core.isDebug()) { lib_core.exportVariable("OPAMVERBOSE", 1); @@ -166162,7 +166162,7 @@ async function installer() { if (!opamCacheHit) { await repositoryRemoveAll(); await repositoryAddAll(OPAM_REPOSITORIES); - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; await installOcaml(ocamlCompiler); await saveOpamCache(); } diff --git a/dist/post/index.js b/dist/post/index.js index 5cb9db1f..e5728ed7 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -111485,6 +111485,98 @@ var lib = __nccwpck_require__(8134); var external_node_os_ = __nccwpck_require__(48161); // EXTERNAL MODULE: ../../node_modules/yaml/dist/index.js var dist = __nccwpck_require__(33483); +;// CONCATENATED MODULE: ./src/constants.ts + + + + + +const constants_ARCHITECTURE = (() => { + switch (external_node_process_.arch) { + case "arm": { + return "armhf"; + } + case "arm64": { + return "arm64"; + } + case "riscv64": { + return "riscv64"; + } + case "s390x": { + return "s390x"; + } + case "x64": { + return "x86_64"; + } + default: { + throw new Error(`'${external_node_process_.arch}' is not supported. Supported architectures: arm, arm64, riscv64, s390x, x64`); + } + } +})(); +const constants_PLATFORM = (() => { + switch (external_node_process_.platform) { + case "darwin": { + return "macos"; + } + case "freebsd": { + return "freebsd"; + } + case "linux": { + return "linux"; + } + case "openbsd": { + return "openbsd"; + } + case "win32": { + return "windows"; + } + default: { + throw new Error(`'${external_node_process_.platform}' is not supported. Supported platforms: darwin, freebsd, linux, openbsd, win32`); + } + } +})(); +const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/"; +const constants_GITHUB_WORKSPACE = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); +const constants_CYGWIN_MIRROR_ENCODED_URI = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); +// [HACK] https://github.com/ocaml/setup-ocaml/pull/55 +const constants_CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); +const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "bin"); +const CYGWIN_BASH_ENV = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "bash_env"); +const DUNE_CACHE_ROOT = (() => { + const xdgCacheHome = external_node_process_.env.XDG_CACHE_HOME; + if (xdgCacheHome) { + return external_node_path_namespaceObject.join(xdgCacheHome, "dune"); + } + if (constants_PLATFORM === "windows") { + // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 + return external_node_path_namespaceObject.join("D:", "dune"); + } + return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".cache", "dune"); +})(); +const constants_OPAM_ROOT = (() => { + if (constants_PLATFORM === "windows") { + // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 + return external_node_path_namespaceObject.join("D:", ".opam"); + } + return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".opam"); +})(); +const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam"); +const constants_CACHE_PREFIX = lib_core.getInput("cache-prefix"); +const GITHUB_TOKEN = lib_core.getInput("github-token"); +const DUNE_CACHE = lib_core.getBooleanInput("dune-cache"); +const OCAML_COMPILER = lib_core.getInput("ocaml-compiler", { + required: true, +}); +const constants_OPAM_DISABLE_SANDBOXING = +// [TODO] unlock this once sandboxing is supported on Windows +constants_PLATFORM !== "windows" && lib_core.getBooleanInput("opam-disable-sandboxing"); +const OPAM_LOCAL_PACKAGES = lib_core.getInput("opam-local-packages"); +const OPAM_PIN = lib_core.getBooleanInput("opam-pin"); +const constants_OPAM_REPOSITORIES = (() => { + const repositoriesYaml = dist/* parse */.qg(lib_core.getInput("opam-repositories")); + return Object.entries(repositoriesYaml).reverse(); +})(); + // EXTERNAL MODULE: ../../node_modules/bottleneck/light.js var light = __nccwpck_require__(46503); ;// CONCATENATED MODULE: ../../node_modules/@octokit/plugin-retry/node_modules/@octokit/request-error/dist-src/index.js @@ -111652,105 +111744,11 @@ async function resolveVersion(semverVersion) { } return matchedFullCompilerVersion; } -async function resolveCompiler(compiler) { - const resolvedCompiler = isSemverValidRange(compiler) - ? `ocaml-base-compiler.${await resolveVersion(compiler)}` - : compiler; +const version_resolvedCompiler = (async () => { + const resolvedCompiler = isSemverValidRange(OCAML_COMPILER) + ? `ocaml-base-compiler.${await resolveVersion(OCAML_COMPILER)}` + : OCAML_COMPILER; return resolvedCompiler; -} - -;// CONCATENATED MODULE: ./src/constants.ts - - - - - - -const constants_ARCHITECTURE = (() => { - switch (external_node_process_.arch) { - case "arm": { - return "armhf"; - } - case "arm64": { - return "arm64"; - } - case "riscv64": { - return "riscv64"; - } - case "s390x": { - return "s390x"; - } - case "x64": { - return "x86_64"; - } - default: { - throw new Error(`'${external_node_process_.arch}' is not supported. Supported architectures: arm, arm64, riscv64, s390x, x64`); - } - } -})(); -const constants_PLATFORM = (() => { - switch (external_node_process_.platform) { - case "darwin": { - return "macos"; - } - case "freebsd": { - return "freebsd"; - } - case "linux": { - return "linux"; - } - case "openbsd": { - return "openbsd"; - } - case "win32": { - return "windows"; - } - default: { - throw new Error(`'${external_node_process_.platform}' is not supported. Supported platforms: darwin, freebsd, linux, openbsd, win32`); - } - } -})(); -const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/"; -const constants_GITHUB_WORKSPACE = external_node_process_.env.GITHUB_WORKSPACE ?? external_node_process_.cwd(); -const constants_CYGWIN_MIRROR_ENCODED_URI = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); -// [HACK] https://github.com/ocaml/setup-ocaml/pull/55 -const constants_CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); -const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "bin"); -const CYGWIN_BASH_ENV = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "bash_env"); -const DUNE_CACHE_ROOT = (() => { - const xdgCacheHome = external_node_process_.env.XDG_CACHE_HOME; - if (xdgCacheHome) { - return external_node_path_namespaceObject.join(xdgCacheHome, "dune"); - } - if (constants_PLATFORM === "windows") { - // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 - return external_node_path_namespaceObject.join("D:", "dune"); - } - return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".cache", "dune"); -})(); -const constants_OPAM_ROOT = (() => { - if (constants_PLATFORM === "windows") { - // [HACK] https://github.com/ocaml/setup-ocaml/pull/55 - return external_node_path_namespaceObject.join("D:", ".opam"); - } - return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".opam"); -})(); -const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam"); -const constants_CACHE_PREFIX = lib_core.getInput("cache-prefix"); -const GITHUB_TOKEN = lib_core.getInput("github-token"); -const DUNE_CACHE = lib_core.getBooleanInput("dune-cache"); -const OCAML_COMPILER = lib_core.getInput("ocaml-compiler", { required: true }); -const constants_OPAM_DISABLE_SANDBOXING = -// [TODO] unlock this once sandboxing is supported on Windows -constants_PLATFORM !== "windows" && lib_core.getBooleanInput("opam-disable-sandboxing"); -const OPAM_LOCAL_PACKAGES = lib_core.getInput("opam-local-packages"); -const OPAM_PIN = lib_core.getBooleanInput("opam-pin"); -const constants_OPAM_REPOSITORIES = (() => { - const repositoriesYaml = dist/* parse */.qg(lib_core.getInput("opam-repositories")); - return Object.entries(repositoriesYaml).reverse(); -})(); -const constants_RESOLVED_COMPILER = (async () => { - return await resolveCompiler(OCAML_COMPILER); })(); ;// CONCATENATED MODULE: ./src/cache.ts @@ -111764,15 +111762,16 @@ const constants_RESOLVED_COMPILER = (async () => { + async function composeCygwinCacheKeys() { - const cygwinVersion = await retrieveCygwinVersion(); - const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${cygwinVersion}`; + const version = await cygwinVersion; + const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${version}`; const restoreKeys = [key]; return { key, restoreKeys }; } async function composeDuneCacheKeys() { const { workflow, job, runId } = lib_github.context; - const ocamlCompiler = await constants_RESOLVED_COMPILER; + const ocamlCompiler = await version_resolvedCompiler; const plainKey = [ocamlCompiler, workflow, job].join(); const hash = external_node_crypto_.createHash("sha256").update(plainKey).digest("hex"); const key = `${constants_CACHE_PREFIX}-setup-ocaml-dune-${constants_PLATFORM}-${constants_ARCHITECTURE}-${hash}-${runId}`; @@ -111785,9 +111784,9 @@ async function composeDuneCacheKeys() { return { key, restoreKeys }; } async function composeOpamCacheKeys() { - const { version: opamVersion } = await retrieveLatestOpamRelease(); + const { version: opamVersion } = await latestOpamRelease; const sandbox = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; const repositoryUrls = OPAM_REPOSITORIES.map(([_, value]) => value).join(); const osInfo = await system.osInfo(); const plainKey = [ diff --git a/packages/setup-ocaml/src/cache.ts b/packages/setup-ocaml/src/cache.ts index 97fec9d6..a3be7380 100644 --- a/packages/setup-ocaml/src/cache.ts +++ b/packages/setup-ocaml/src/cache.ts @@ -17,21 +17,21 @@ import { OPAM_REPOSITORIES, OPAM_ROOT, PLATFORM, - RESOLVED_COMPILER, } from "./constants.js"; -import { retrieveLatestOpamRelease } from "./opam.js"; -import { retrieveCygwinVersion } from "./windows.js"; +import { latestOpamRelease } from "./opam.js"; +import { resolvedCompiler } from "./version.js"; +import { cygwinVersion } from "./windows.js"; async function composeCygwinCacheKeys() { - const cygwinVersion = await retrieveCygwinVersion(); - const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${cygwinVersion}`; + const version = await cygwinVersion; + const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${CYGWIN_MIRROR_ENCODED_URI}-${version}`; const restoreKeys = [key]; return { key, restoreKeys }; } async function composeDuneCacheKeys() { const { workflow, job, runId } = github.context; - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; const plainKey = [ocamlCompiler, workflow, job].join(); const hash = crypto.createHash("sha256").update(plainKey).digest("hex"); const key = `${CACHE_PREFIX}-setup-ocaml-dune-${PLATFORM}-${ARCHITECTURE}-${hash}-${runId}`; @@ -45,9 +45,9 @@ async function composeDuneCacheKeys() { } async function composeOpamCacheKeys() { - const { version: opamVersion } = await retrieveLatestOpamRelease(); + const { version: opamVersion } = await latestOpamRelease; const sandbox = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; const repositoryUrls = OPAM_REPOSITORIES.map(([_, value]) => value).join(); const osInfo = await system.osInfo(); const plainKey = [ diff --git a/packages/setup-ocaml/src/constants.ts b/packages/setup-ocaml/src/constants.ts index e1bae43f..70786b72 100644 --- a/packages/setup-ocaml/src/constants.ts +++ b/packages/setup-ocaml/src/constants.ts @@ -3,7 +3,6 @@ import * as path from "node:path"; import * as process from "node:process"; import * as core from "@actions/core"; import * as yaml from "yaml"; -import { resolveCompiler } from "./version.js"; export const ARCHITECTURE = (() => { switch (process.arch) { @@ -99,7 +98,9 @@ export const GITHUB_TOKEN = core.getInput("github-token"); export const DUNE_CACHE = core.getBooleanInput("dune-cache"); -const OCAML_COMPILER = core.getInput("ocaml-compiler", { required: true }); +export const OCAML_COMPILER = core.getInput("ocaml-compiler", { + required: true, +}); export const OPAM_DISABLE_SANDBOXING = // [TODO] unlock this once sandboxing is supported on Windows @@ -115,7 +116,3 @@ export const OPAM_REPOSITORIES: [string, string][] = (() => { ) as Record; return Object.entries(repositoriesYaml).reverse(); })(); - -export const RESOLVED_COMPILER = (async () => { - return await resolveCompiler(OCAML_COMPILER); -})(); diff --git a/packages/setup-ocaml/src/installer.ts b/packages/setup-ocaml/src/installer.ts index 30123e39..2d78e0aa 100644 --- a/packages/setup-ocaml/src/installer.ts +++ b/packages/setup-ocaml/src/installer.ts @@ -18,7 +18,6 @@ import { OPAM_REPOSITORIES, OPAM_ROOT, PLATFORM, - RESOLVED_COMPILER, } from "./constants.js"; import { installDune } from "./dune.js"; import { @@ -30,6 +29,7 @@ import { update, } from "./opam.js"; import { retrieveOpamLocalPackages } from "./packages.js"; +import { resolvedCompiler } from "./version.js"; import { setupCygwin } from "./windows.js"; export async function installer() { @@ -75,7 +75,7 @@ export async function installer() { if (!opamCacheHit) { await repositoryRemoveAll(); await repositoryAddAll(OPAM_REPOSITORIES); - const ocamlCompiler = await RESOLVED_COMPILER; + const ocamlCompiler = await resolvedCompiler; await installOcaml(ocamlCompiler); await saveOpamCache(); } else { diff --git a/packages/setup-ocaml/src/opam.ts b/packages/setup-ocaml/src/opam.ts index c1087a39..56b2c478 100644 --- a/packages/setup-ocaml/src/opam.ts +++ b/packages/setup-ocaml/src/opam.ts @@ -19,7 +19,7 @@ import { updateUnixPackageIndexFiles, } from "./unix.js"; -export async function retrieveLatestOpamRelease() { +export const latestOpamRelease = (async () => { const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.4.0"; const octokit = github.getOctokit(GITHUB_TOKEN, undefined, retry); const { data: releases } = await octokit.rest.repos.listReleases({ @@ -59,11 +59,11 @@ export async function retrieveLatestOpamRelease() { version: latestRelease.tag_name, browserDownloadUrl: matchedAssets.browser_download_url, }; -} +})(); async function acquireOpam() { await core.group("Installing opam", async () => { - const { version, browserDownloadUrl } = await retrieveLatestOpamRelease(); + const { version, browserDownloadUrl } = await latestOpamRelease; const cachedPath = toolCache.find("opam", version, ARCHITECTURE); const opam = PLATFORM !== "windows" ? "opam" : "opam.exe"; if (cachedPath === "") { diff --git a/packages/setup-ocaml/src/version.ts b/packages/setup-ocaml/src/version.ts index e685aeb2..6471e99f 100644 --- a/packages/setup-ocaml/src/version.ts +++ b/packages/setup-ocaml/src/version.ts @@ -2,7 +2,7 @@ import * as path from "node:path"; import * as github from "@actions/github"; import { retry } from "@octokit/plugin-retry"; import * as semver from "semver"; -import { GITHUB_TOKEN } from "./constants.js"; +import { GITHUB_TOKEN, OCAML_COMPILER } from "./constants.js"; function isSemverValidRange(semverVersion: string) { return semver.validRange(semverVersion, { loose: true }) !== null; @@ -52,9 +52,9 @@ async function resolveVersion(semverVersion: string) { return matchedFullCompilerVersion; } -export async function resolveCompiler(compiler: string) { - const resolvedCompiler = isSemverValidRange(compiler) - ? `ocaml-base-compiler.${await resolveVersion(compiler)}` - : compiler; +export const resolvedCompiler = (async () => { + const resolvedCompiler = isSemverValidRange(OCAML_COMPILER) + ? `ocaml-base-compiler.${await resolveVersion(OCAML_COMPILER)}` + : OCAML_COMPILER; return resolvedCompiler; -} +})(); diff --git a/packages/setup-ocaml/src/windows.ts b/packages/setup-ocaml/src/windows.ts index af7b19c5..93ab7055 100644 --- a/packages/setup-ocaml/src/windows.ts +++ b/packages/setup-ocaml/src/windows.ts @@ -22,7 +22,7 @@ function createHttpClient() { ); } -export async function retrieveCygwinVersion() { +export const cygwinVersion = (async () => { const httpClient = createHttpClient(); const response = await httpClient.get("https://www.cygwin.com"); const body = await response.readBody(); @@ -35,7 +35,7 @@ export async function retrieveCygwinVersion() { } }); return version; -} +})(); async function setGitToIgnoreCygwinLocalPackageDirectory() { const xdgConfigHome = process.env.XDG_CONFIG_HOME; @@ -71,7 +71,7 @@ async function setGitToIgnoreCygwinLocalPackageDirectory() { export async function setupCygwin() { await core.group("Setting up Cygwin environment", async () => { await setGitToIgnoreCygwinLocalPackageDirectory(); - const version = await retrieveCygwinVersion(); + const version = await cygwinVersion; const cachedPath = toolCache.find("cygwin", version, "x86_64"); if (cachedPath === "") { const downloadedPath = await toolCache.downloadTool(