diff --git a/dist/index.js b/dist/index.js index 9d171f0d..1fccfef3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -126811,111 +126811,45 @@ var lib_github = __nccwpck_require__(84005); var date_fns = __nccwpck_require__(61223); // EXTERNAL MODULE: ../../node_modules/yaml/dist/index.js var dist = __nccwpck_require__(8447); -;// CONCATENATED MODULE: external "node:fs" -const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); -;// CONCATENATED MODULE: ./src/system.ts +;// CONCATENATED MODULE: ./src/constants.ts -function getArchitecture() { +const ARCHITECTURE = (() => { switch (external_node_os_namespaceObject.arch()) { case "x64": { - return Architecture.X86_64; + return "x86_64"; } case "arm64": { - return Architecture.ARM; + return "arm64"; } default: { throw new Error("The architecture is not supported."); } } -} -function getPlatform() { +})(); +const PLATFORM = (() => { switch (external_node_os_namespaceObject.platform()) { case "linux": { - return Platform.Linux; + return "linux"; } case "darwin": { - return Platform.MacOS; + return "macos"; } case "win32": { - return Platform.Win32; + return "win32"; } default: { throw new Error("The platform is not supported."); } } -} -async function getSystemIdentificationInfo() { - const platform = getPlatform(); - if (platform === Platform.Linux) { - const osRelease = await external_node_fs_namespaceObject.promises.readFile("/etc/os-release", "utf8"); - const lines = osRelease.split(external_node_os_namespaceObject.EOL); - let id = ""; - let version = ""; - for (const line of lines) { - const [key, value] = line.split("=").map((kv) => kv.trim()); - if (key === "ID" && value !== undefined) { - id = value.toLowerCase(); - } - else if (key === "VERSION_ID" && value !== undefined) { - version = value.toLowerCase().replaceAll('"', ""); - } - } - return { id, version }; - } - else if (platform === Platform.MacOS) { - const swVers = await (0,lib_exec.getExecOutput)("sw_vers"); - const lines = swVers.stdout.split(external_node_os_namespaceObject.EOL); - let version = ""; - for (const line of lines) { - const [key, value] = line.split(":").map((kv) => kv.trim()); - if (key === "ProductVersion" && value !== undefined) { - version = value; - } - } - return { id: "macos", version }; - } - else { - throw new Error("The system is not supported."); - } -} -async function updateUnixPackageIndexFiles() { - const isGitHubRunner = process.env["ImageOS"] !== undefined; - const platform = getPlatform(); - if (isGitHubRunner) { - if (platform === Platform.Linux) { - await (0,lib_exec.exec)("sudo", ["apt-get", "update"]); - } - else if (platform === Platform.MacOS) { - await (0,lib_exec.exec)("brew", ["update"]); - } - } -} - -;// CONCATENATED MODULE: ./src/constants.ts - - - - -var Architecture; -(function (Architecture) { - Architecture["X86_64"] = "x86_64"; - Architecture["ARM"] = "arm64"; -})(Architecture || (Architecture = {})); -var Platform; -(function (Platform) { - Platform["Linux"] = "linux"; - Platform["MacOS"] = "macos"; - Platform["Win32"] = "win32"; -})(Platform || (Platform = {})); -const platform = getPlatform(); +})(); const CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); const CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bin"); const CYGWIN_ROOT_WRAPPERBIN = external_node_path_namespaceObject.join(CYGWIN_ROOT, "wrapperbin"); // [todo] remove the branch for Windows once opam 2.2 is released as stable. -const ALLOW_PRELEASE_OPAM = platform !== Platform.Win32 && +const ALLOW_PRELEASE_OPAM = PLATFORM !== "win32" && lib_core.getBooleanInput("allow-prelease-opam", { required: false, trimWhitespace: true, @@ -126956,19 +126890,71 @@ const OPAM_PIN = lib_core.getBooleanInput("opam-pin", { trimWhitespace: true, }); const repositories_yaml = dist/* parse */.Qc(lib_core.getInput("opam-repositories", { required: false, trimWhitespace: true })); -const defaultRepository = platform === Platform.Win32 +const defaultRepository = PLATFORM === "win32" ? "https://github.com/ocaml-opam/opam-repository-mingw.git#sunset" : "https://github.com/ocaml/opam-repository.git"; const OPAM_REPOSITORIES = repositories_yaml ? Object.entries(repositories_yaml).reverse() : [["default", defaultRepository]]; +;// CONCATENATED MODULE: external "node:fs" +const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); // EXTERNAL MODULE: ../../node_modules/@actions/io/lib/io.js var io = __nccwpck_require__(96890); // EXTERNAL MODULE: ../../node_modules/@actions/tool-cache/lib/tool-cache.js var tool_cache = __nccwpck_require__(40834); // EXTERNAL MODULE: ../../node_modules/semver/index.js var semver = __nccwpck_require__(77546); +;// CONCATENATED MODULE: ./src/system.ts + + + + +async function getSystemIdentificationInfo() { + if (PLATFORM === "linux") { + const osRelease = await external_node_fs_namespaceObject.promises.readFile("/etc/os-release", "utf8"); + const lines = osRelease.split(external_node_os_namespaceObject.EOL); + let id = ""; + let version = ""; + for (const line of lines) { + const [key, value] = line.split("=").map((kv) => kv.trim()); + if (key === "ID" && value !== undefined) { + id = value.toLowerCase(); + } + else if (key === "VERSION_ID" && value !== undefined) { + version = value.toLowerCase().replaceAll('"', ""); + } + } + return { id, version }; + } + else if (PLATFORM === "macos") { + const swVers = await (0,lib_exec.getExecOutput)("sw_vers"); + const lines = swVers.stdout.split(external_node_os_namespaceObject.EOL); + let version = ""; + for (const line of lines) { + const [key, value] = line.split(":").map((kv) => kv.trim()); + if (key === "ProductVersion" && value !== undefined) { + version = value; + } + } + return { id: "macos", version }; + } + else { + throw new Error("The system is not supported."); + } +} +async function updateUnixPackageIndexFiles() { + const isGitHubRunner = process.env["ImageOS"] !== undefined; + if (isGitHubRunner) { + if (PLATFORM === "linux") { + await (0,lib_exec.exec)("sudo", ["apt-get", "update"]); + } + else if (PLATFORM === "macos") { + await (0,lib_exec.exec)("brew", ["update"]); + } + } +} + // EXTERNAL MODULE: ../../node_modules/@actions/http-client/lib/index.js var lib = __nccwpck_require__(87301); ;// CONCATENATED MODULE: ../../node_modules/cheerio/lib/esm/options.js @@ -144303,9 +144289,7 @@ async function getLatestOpamRelease() { if (!latestRelease) { throw new Error("Could not retrieve the opam release matching the version constraint"); } - const architecture = getArchitecture(); - const platform = getPlatform(); - const matchedAssets = latestRelease.assets.find((asset) => asset.browser_download_url.includes(`${architecture}-${platform}`)); + const matchedAssets = latestRelease.assets.find((asset) => asset.browser_download_url.includes(`${ARCHITECTURE}-${PLATFORM}`)); if (!matchedAssets) { throw new Error("Could not find any assets matching the current platform or architecture"); } @@ -144315,8 +144299,7 @@ async function getLatestOpamRelease() { }; } async function findOpam() { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamPath = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bin", "opam.exe"); return opamPath; } @@ -144327,12 +144310,11 @@ async function findOpam() { } async function acquireOpamUnix() { const { version, browserDownloadUrl } = await getLatestOpamRelease(); - const architecture = getArchitecture(); - const cachedPath = tool_cache.find("opam", version, architecture); + const cachedPath = tool_cache.find("opam", version, ARCHITECTURE); if (cachedPath === "") { const downloadedPath = await tool_cache.downloadTool(browserDownloadUrl); lib_core.info(`Acquired ${version} from ${browserDownloadUrl}`); - const cachedPath = await tool_cache.cacheFile(downloadedPath, "opam", "opam", version, architecture); + const cachedPath = await tool_cache.cacheFile(downloadedPath, "opam", "opam", version, ARCHITECTURE); lib_core.info(`Successfully cached opam to ${cachedPath}`); await external_node_fs_namespaceObject.promises.chmod(`${cachedPath}/opam`, 0o755); lib_core.addPath(cachedPath); @@ -144345,9 +144327,8 @@ async function acquireOpamUnix() { } async function installUnixSystemPackages() { const isGitHubRunner = external_node_process_namespaceObject.env.ImageOS !== undefined; - const platform = getPlatform(); if (isGitHubRunner) { - if (platform === Platform.Linux) { + if (PLATFORM === "linux") { const { version: systemVersion } = await getSystemIdentificationInfo(); if (systemVersion === "18.04") { // [info]: musl-tools bug in ubuntu 18.04; @@ -144367,7 +144348,7 @@ async function installUnixSystemPackages() { "rsync", ]); } - else if (platform === Platform.MacOS) { + else if (PLATFORM === "macos") { await (0,lib_exec.exec)("brew", ["install", "darcs", "gpatch", "mercurial"]); } } @@ -144501,8 +144482,7 @@ async function setupOpamWindows() { external_node_process_namespaceObject.env.PATH = originalPath.join(external_node_path_namespaceObject.delimiter); } async function setupOpam() { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await setupOpamWindows(); } else { @@ -144511,8 +144491,7 @@ async function setupOpam() { } async function installOcaml(ocamlCompiler) { await lib_core.group("Install OCaml", async () => { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const originalPath = external_node_process_namespaceObject.env.PATH.split(external_node_path_namespaceObject.delimiter); const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; @@ -144564,12 +144543,11 @@ async function repositoryAdd(name, address) { } async function repositoryAddAll(repositories) { await lib_core.group("Initialise the opam repositories", async () => { - const platform = getPlatform(); let restore_autocrlf; // Works around the lack of https://github.com/ocaml/opam/pull/3882 when // adding ocaml/opam-repository on Windows. Can be removed when the action // switches to opam 2.2 - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const autocrlf = await (0,lib_exec.getExecOutput)("git", ["config", "--global", "core.autocrlf"], { ignoreReturnCode: true }); if (autocrlf.stdout.trim() !== "input") { if (autocrlf.exitCode === 0) { @@ -144629,7 +144607,6 @@ async function repositoryRemoveAll() { - function isSemverValidRange(semverVersion) { const isValidSemver = semver.validRange(semverVersion, { loose: true }) !== null; // [NOTE] explicitly deny compilers like "4.14.0+mingw64c" as invalid semver @@ -144639,10 +144616,9 @@ function isSemverValidRange(semverVersion) { } async function getAllCompilerVersions() { const octokit = lib_github.getOctokit(constants_GITHUB_TOKEN); - const platform = getPlatform(); - const owner = platform === Platform.Win32 ? "ocaml-opam" : "ocaml"; - const repo = platform === Platform.Win32 ? "opam-repository-mingw" : "opam-repository"; - const prefix = platform === Platform.Win32 ? "ocaml-variants" : "ocaml-base-compiler"; + const owner = PLATFORM === "win32" ? "ocaml-opam" : "ocaml"; + const repo = PLATFORM === "win32" ? "opam-repository-mingw" : "opam-repository"; + const prefix = PLATFORM === "win32" ? "ocaml-variants" : "ocaml-base-compiler"; const { data: packages } = await octokit.rest.repos.getContent({ owner, repo, @@ -144675,9 +144651,8 @@ async function resolveVersion(semverVersion) { } } async function resolveCompiler(compiler) { - const platform = getPlatform(); const resolvedCompiler = isSemverValidRange(compiler) - ? platform === Platform.Win32 + ? PLATFORM === "win32" ? `ocaml-variants.${await resolveVersion(compiler)}+mingw64c` : `ocaml-base-compiler.${await resolveVersion(compiler)}` : compiler; @@ -144720,8 +144695,8 @@ async function composeCygwinCacheKeys() { return { key, restoreKeys }; } function composeDuneCacheKeys() { - const platform = getPlatform().replaceAll(/\W/g, "_"); - const architecture = getArchitecture().replaceAll(/\W/g, "_"); + const platform = PLATFORM.replaceAll(/\W/g, "_"); + const architecture = ARCHITECTURE.replaceAll(/\W/g, "_"); const { workflow: _workflow, job: _job, runId, runNumber } = lib_github.context; const workflow = _workflow.toLowerCase().replaceAll(/\W/g, "_"); const job = _job.replaceAll(/\W/g, "_"); @@ -144735,13 +144710,11 @@ function composeDuneCacheKeys() { return { key, restoreKeys }; } async function composeOpamCacheKeys() { - const platform = getPlatform(); - const fullPlatform = platform === Platform.Win32 - ? platform + const fullPlatform = PLATFORM === "win32" + ? PLATFORM : // eslint-disable-next-line unicorn/no-await-expression-member - `${platform}-${(await getSystemIdentificationInfo()).version}`; - const architecture = getArchitecture(); - const opamVersion = platform === Platform.Win32 + `${PLATFORM}-${(await getSystemIdentificationInfo()).version}`; + const opamVersion = PLATFORM === "win32" ? "0.0.0.2" : // eslint-disable-next-line unicorn/no-await-expression-member (await getLatestOpamRelease()).version; @@ -144749,11 +144722,11 @@ async function composeOpamCacheKeys() { const ocamlVersion = ocamlCompiler.toLowerCase().replaceAll(/\W/g, "_"); const sandboxed = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; const { year, week } = composeDate(); - const key = `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-${week}`; + const key = `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-${week}`; const restoreKeys = [ - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-${week}`, - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-`, - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-${week}`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-`, ]; return { key, restoreKeys }; } @@ -144795,8 +144768,7 @@ function composeCygwinCachePaths() { function composeDuneCachePaths() { const paths = []; const homeDir = external_node_os_namespaceObject.homedir(); - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const duneCacheDir = external_node_path_namespaceObject.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } @@ -144811,8 +144783,7 @@ function composeDuneCachePaths() { } function composeOpamCachePaths() { const paths = []; - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamRootCachePath = external_node_path_namespaceObject.join("D:", ".opam"); paths.push(opamRootCachePath); const { repo: { repo }, } = lib_github.context; @@ -144831,8 +144802,7 @@ function composeOpamCachePaths() { } function composeOpamDownloadCachePaths() { const paths = []; - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamDownloadCachePath = external_node_path_namespaceObject.join("D:", ".opam", "download-cache"); paths.push(opamDownloadCachePath); } @@ -144943,13 +144913,11 @@ async function saveOpamDownloadCache() { - async function installDepext(ocamlVersion) { await lib_core.group("Install depext", async () => { - const platform = getPlatform(); - const depextCygwinports = platform === Platform.Win32 ? ["depext-cygwinports"] : []; + const depextCygwinports = PLATFORM === "win32" ? ["depext-cygwinports"] : []; await (0,lib_exec.exec)("opam", ["install", "opam-depext", ...depextCygwinports]); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { let base = ""; if (ocamlVersion.includes("mingw64")) { base = "x86_64-w64-mingw32"; @@ -145026,7 +144994,6 @@ async function getOpamLocalPackages() { async function installer() { - const platform = getPlatform(); if (!ALLOW_PRELEASE_OPAM) { // [todo] remove this once opam 2.2 is released as stable. // https://github.com/ocaml/setup-ocaml/issues/299 @@ -145040,11 +145007,11 @@ async function installer() { // https://github.com/ocaml/opam/issues/3447 lib_core.exportVariable("OPAMSOLVERTIMEOUT", 1000); lib_core.exportVariable("OPAMYES", 1); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamRoot = external_node_path_namespaceObject.join("D:", ".opam"); lib_core.exportVariable("OPAMROOT", opamRoot); } - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await lib_core.group("Change the file system behavior parameters", async () => { await (0,lib_exec.exec)("fsutil", ["behavior", "query", "SymlinkEvaluation"]); // https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-behavior @@ -145058,25 +145025,25 @@ async function installer() { await (0,lib_exec.exec)("fsutil", ["behavior", "query", "SymlinkEvaluation"]); }); } - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { lib_core.exportVariable("HOME", external_node_process_namespaceObject.env.USERPROFILE); lib_core.exportVariable("MSYS", "winsymlinks:native"); } - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await restoreCygwinCache(); } const opamCacheHit = await restoreOpamCache(); await setupOpam(); await repositoryRemoveAll(); await repositoryAddAll(OPAM_REPOSITORIES); + const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); if (!opamCacheHit) { - const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); await installOcaml(ocamlCompiler); await saveOpamCache(); } await restoreOpamDownloadCache(); if (OPAM_DEPEXT) { - await installDepext(platform); + await installDepext(ocamlCompiler); } if (DUNE_CACHE) { await restoreDuneCache(); diff --git a/dist/post/index.js b/dist/post/index.js index 8ce4247e..bb2d7400 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -125629,111 +125629,45 @@ var lib_github = __nccwpck_require__(84005); var date_fns = __nccwpck_require__(61223); // EXTERNAL MODULE: ../../node_modules/yaml/dist/index.js var dist = __nccwpck_require__(8447); -;// CONCATENATED MODULE: external "node:fs" -const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); -;// CONCATENATED MODULE: ./src/system.ts +;// CONCATENATED MODULE: ./src/constants.ts -function system_getArchitecture() { +const constants_ARCHITECTURE = (() => { switch (external_node_os_namespaceObject.arch()) { case "x64": { - return Architecture.X86_64; + return "x86_64"; } case "arm64": { - return Architecture.ARM; + return "arm64"; } default: { throw new Error("The architecture is not supported."); } } -} -function system_getPlatform() { +})(); +const constants_PLATFORM = (() => { switch (external_node_os_namespaceObject.platform()) { case "linux": { - return constants_Platform.Linux; + return "linux"; } case "darwin": { - return constants_Platform.MacOS; + return "macos"; } case "win32": { - return constants_Platform.Win32; + return "win32"; } default: { throw new Error("The platform is not supported."); } } -} -async function system_getSystemIdentificationInfo() { - const platform = system_getPlatform(); - if (platform === Platform.Linux) { - const osRelease = await fs.readFile("/etc/os-release", "utf8"); - const lines = osRelease.split(os.EOL); - let id = ""; - let version = ""; - for (const line of lines) { - const [key, value] = line.split("=").map((kv) => kv.trim()); - if (key === "ID" && value !== undefined) { - id = value.toLowerCase(); - } - else if (key === "VERSION_ID" && value !== undefined) { - version = value.toLowerCase().replaceAll('"', ""); - } - } - return { id, version }; - } - else if (platform === Platform.MacOS) { - const swVers = await getExecOutput("sw_vers"); - const lines = swVers.stdout.split(os.EOL); - let version = ""; - for (const line of lines) { - const [key, value] = line.split(":").map((kv) => kv.trim()); - if (key === "ProductVersion" && value !== undefined) { - version = value; - } - } - return { id: "macos", version }; - } - else { - throw new Error("The system is not supported."); - } -} -async function system_updateUnixPackageIndexFiles() { - const isGitHubRunner = process.env["ImageOS"] !== undefined; - const platform = system_getPlatform(); - if (isGitHubRunner) { - if (platform === Platform.Linux) { - await exec("sudo", ["apt-get", "update"]); - } - else if (platform === Platform.MacOS) { - await exec("brew", ["update"]); - } - } -} - -;// CONCATENATED MODULE: ./src/constants.ts - - - - -var Architecture; -(function (Architecture) { - Architecture["X86_64"] = "x86_64"; - Architecture["ARM"] = "arm64"; -})(Architecture || (Architecture = {})); -var constants_Platform; -(function (Platform) { - Platform["Linux"] = "linux"; - Platform["MacOS"] = "macos"; - Platform["Win32"] = "win32"; -})(constants_Platform || (constants_Platform = {})); -const platform = system_getPlatform(); +})(); const constants_CYGWIN_ROOT = external_node_path_namespaceObject.join("D:", "cygwin"); const constants_CYGWIN_ROOT_BIN = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "bin"); const constants_CYGWIN_ROOT_WRAPPERBIN = external_node_path_namespaceObject.join(constants_CYGWIN_ROOT, "wrapperbin"); // [todo] remove the branch for Windows once opam 2.2 is released as stable. -const constants_ALLOW_PRELEASE_OPAM = platform !== constants_Platform.Win32 && +const constants_ALLOW_PRELEASE_OPAM = constants_PLATFORM !== "win32" && lib_core.getBooleanInput("allow-prelease-opam", { required: false, trimWhitespace: true, @@ -125774,19 +125708,71 @@ const OPAM_PIN = lib_core.getBooleanInput("opam-pin", { trimWhitespace: true, }); const repositories_yaml = dist/* parse */.Qc(lib_core.getInput("opam-repositories", { required: false, trimWhitespace: true })); -const defaultRepository = platform === constants_Platform.Win32 +const defaultRepository = constants_PLATFORM === "win32" ? "https://github.com/ocaml-opam/opam-repository-mingw.git#sunset" : "https://github.com/ocaml/opam-repository.git"; const OPAM_REPOSITORIES = repositories_yaml ? Object.entries(repositories_yaml).reverse() : [["default", defaultRepository]]; +;// CONCATENATED MODULE: external "node:fs" +const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); // EXTERNAL MODULE: ../../node_modules/@actions/io/lib/io.js var lib_io = __nccwpck_require__(96890); // EXTERNAL MODULE: ../../node_modules/@actions/tool-cache/lib/tool-cache.js var tool_cache = __nccwpck_require__(40834); // EXTERNAL MODULE: ../../node_modules/semver/index.js var node_modules_semver = __nccwpck_require__(77546); +;// CONCATENATED MODULE: ./src/system.ts + + + + +async function system_getSystemIdentificationInfo() { + if (PLATFORM === "linux") { + const osRelease = await fs.readFile("/etc/os-release", "utf8"); + const lines = osRelease.split(os.EOL); + let id = ""; + let version = ""; + for (const line of lines) { + const [key, value] = line.split("=").map((kv) => kv.trim()); + if (key === "ID" && value !== undefined) { + id = value.toLowerCase(); + } + else if (key === "VERSION_ID" && value !== undefined) { + version = value.toLowerCase().replaceAll('"', ""); + } + } + return { id, version }; + } + else if (PLATFORM === "macos") { + const swVers = await getExecOutput("sw_vers"); + const lines = swVers.stdout.split(os.EOL); + let version = ""; + for (const line of lines) { + const [key, value] = line.split(":").map((kv) => kv.trim()); + if (key === "ProductVersion" && value !== undefined) { + version = value; + } + } + return { id: "macos", version }; + } + else { + throw new Error("The system is not supported."); + } +} +async function system_updateUnixPackageIndexFiles() { + const isGitHubRunner = process.env["ImageOS"] !== undefined; + if (isGitHubRunner) { + if (PLATFORM === "linux") { + await exec("sudo", ["apt-get", "update"]); + } + else if (PLATFORM === "macos") { + await exec("brew", ["update"]); + } + } +} + // EXTERNAL MODULE: ../../node_modules/@actions/http-client/lib/index.js var lib = __nccwpck_require__(87301); ;// CONCATENATED MODULE: ../../node_modules/cheerio/lib/esm/options.js @@ -143121,9 +143107,7 @@ async function opam_getLatestOpamRelease() { if (!latestRelease) { throw new Error("Could not retrieve the opam release matching the version constraint"); } - const architecture = getArchitecture(); - const platform = getPlatform(); - const matchedAssets = latestRelease.assets.find((asset) => asset.browser_download_url.includes(`${architecture}-${platform}`)); + const matchedAssets = latestRelease.assets.find((asset) => asset.browser_download_url.includes(`${ARCHITECTURE}-${PLATFORM}`)); if (!matchedAssets) { throw new Error("Could not find any assets matching the current platform or architecture"); } @@ -143133,8 +143117,7 @@ async function opam_getLatestOpamRelease() { }; } async function findOpam() { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamPath = path.join(CYGWIN_ROOT, "bin", "opam.exe"); return opamPath; } @@ -143145,12 +143128,11 @@ async function findOpam() { } async function acquireOpamUnix() { const { version, browserDownloadUrl } = await opam_getLatestOpamRelease(); - const architecture = getArchitecture(); - const cachedPath = tc.find("opam", version, architecture); + const cachedPath = tc.find("opam", version, ARCHITECTURE); if (cachedPath === "") { const downloadedPath = await tc.downloadTool(browserDownloadUrl); core.info(`Acquired ${version} from ${browserDownloadUrl}`); - const cachedPath = await tc.cacheFile(downloadedPath, "opam", "opam", version, architecture); + const cachedPath = await tc.cacheFile(downloadedPath, "opam", "opam", version, ARCHITECTURE); core.info(`Successfully cached opam to ${cachedPath}`); await fs.chmod(`${cachedPath}/opam`, 0o755); core.addPath(cachedPath); @@ -143163,9 +143145,8 @@ async function acquireOpamUnix() { } async function installUnixSystemPackages() { const isGitHubRunner = process.env["ImageOS"] !== undefined; - const platform = getPlatform(); if (isGitHubRunner) { - if (platform === Platform.Linux) { + if (PLATFORM === "linux") { const { version: systemVersion } = await getSystemIdentificationInfo(); if (systemVersion === "18.04") { // [info]: musl-tools bug in ubuntu 18.04; @@ -143185,7 +143166,7 @@ async function installUnixSystemPackages() { "rsync", ]); } - else if (platform === Platform.MacOS) { + else if (PLATFORM === "macos") { await exec("brew", ["install", "darcs", "gpatch", "mercurial"]); } } @@ -143319,8 +143300,7 @@ async function setupOpamWindows() { process.env["PATH"] = originalPath.join(path.delimiter); } async function setupOpam() { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await setupOpamWindows(); } else { @@ -143329,8 +143309,7 @@ async function setupOpam() { } async function installOcaml(ocamlCompiler) { await core.group("Install OCaml", async () => { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const originalPath = process.env["PATH"].split(path.delimiter); const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; @@ -143382,12 +143361,11 @@ async function repositoryAdd(name, address) { } async function repositoryAddAll(repositories) { await core.group("Initialise the opam repositories", async () => { - const platform = getPlatform(); let restore_autocrlf; // Works around the lack of https://github.com/ocaml/opam/pull/3882 when // adding ocaml/opam-repository on Windows. Can be removed when the action // switches to opam 2.2 - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const autocrlf = await getExecOutput("git", ["config", "--global", "core.autocrlf"], { ignoreReturnCode: true }); if (autocrlf.stdout.trim() !== "input") { if (autocrlf.exitCode === 0) { @@ -143447,7 +143425,6 @@ async function repositoryRemoveAll() { - function isSemverValidRange(semverVersion) { const isValidSemver = semver.validRange(semverVersion, { loose: true }) !== null; // [NOTE] explicitly deny compilers like "4.14.0+mingw64c" as invalid semver @@ -143457,10 +143434,9 @@ function isSemverValidRange(semverVersion) { } async function getAllCompilerVersions() { const octokit = github.getOctokit(GITHUB_TOKEN); - const platform = getPlatform(); - const owner = platform === Platform.Win32 ? "ocaml-opam" : "ocaml"; - const repo = platform === Platform.Win32 ? "opam-repository-mingw" : "opam-repository"; - const prefix = platform === Platform.Win32 ? "ocaml-variants" : "ocaml-base-compiler"; + const owner = PLATFORM === "win32" ? "ocaml-opam" : "ocaml"; + const repo = PLATFORM === "win32" ? "opam-repository-mingw" : "opam-repository"; + const prefix = PLATFORM === "win32" ? "ocaml-variants" : "ocaml-base-compiler"; const { data: packages } = await octokit.rest.repos.getContent({ owner, repo, @@ -143493,9 +143469,8 @@ async function resolveVersion(semverVersion) { } } async function version_resolveCompiler(compiler) { - const platform = getPlatform(); const resolvedCompiler = isSemverValidRange(compiler) - ? platform === Platform.Win32 + ? PLATFORM === "win32" ? `ocaml-variants.${await resolveVersion(compiler)}+mingw64c` : `ocaml-base-compiler.${await resolveVersion(compiler)}` : compiler; @@ -143538,8 +143513,8 @@ async function composeCygwinCacheKeys() { return { key, restoreKeys }; } function composeDuneCacheKeys() { - const platform = system_getPlatform().replaceAll(/\W/g, "_"); - const architecture = system_getArchitecture().replaceAll(/\W/g, "_"); + const platform = constants_PLATFORM.replaceAll(/\W/g, "_"); + const architecture = constants_ARCHITECTURE.replaceAll(/\W/g, "_"); const { workflow: _workflow, job: _job, runId, runNumber } = lib_github.context; const workflow = _workflow.toLowerCase().replaceAll(/\W/g, "_"); const job = _job.replaceAll(/\W/g, "_"); @@ -143553,13 +143528,11 @@ function composeDuneCacheKeys() { return { key, restoreKeys }; } async function composeOpamCacheKeys() { - const platform = getPlatform(); - const fullPlatform = platform === Platform.Win32 - ? platform + const fullPlatform = PLATFORM === "win32" + ? PLATFORM : // eslint-disable-next-line unicorn/no-await-expression-member - `${platform}-${(await getSystemIdentificationInfo()).version}`; - const architecture = getArchitecture(); - const opamVersion = platform === Platform.Win32 + `${PLATFORM}-${(await getSystemIdentificationInfo()).version}`; + const opamVersion = PLATFORM === "win32" ? "0.0.0.2" : // eslint-disable-next-line unicorn/no-await-expression-member (await getLatestOpamRelease()).version; @@ -143567,11 +143540,11 @@ async function composeOpamCacheKeys() { const ocamlVersion = ocamlCompiler.toLowerCase().replaceAll(/\W/g, "_"); const sandboxed = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; const { year, week } = composeDate(); - const key = `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-${week}`; + const key = `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-${week}`; const restoreKeys = [ - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-${week}`, - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-`, - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-${week}`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-`, ]; return { key, restoreKeys }; } @@ -143613,8 +143586,7 @@ function composeCygwinCachePaths() { function composeDuneCachePaths() { const paths = []; const homeDir = external_node_os_namespaceObject.homedir(); - const platform = system_getPlatform(); - if (platform === constants_Platform.Win32) { + if (constants_PLATFORM === "win32") { const duneCacheDir = external_node_path_namespaceObject.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } @@ -143629,8 +143601,7 @@ function composeDuneCachePaths() { } function composeOpamCachePaths() { const paths = []; - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamRootCachePath = path.join("D:", ".opam"); paths.push(opamRootCachePath); const { repo: { repo }, } = github.context; @@ -143649,8 +143620,7 @@ function composeOpamCachePaths() { } function composeOpamDownloadCachePaths() { const paths = []; - const platform = system_getPlatform(); - if (platform === constants_Platform.Win32) { + if (constants_PLATFORM === "win32") { const opamDownloadCachePath = external_node_path_namespaceObject.join("D:", ".opam", "download-cache"); paths.push(opamDownloadCachePath); } diff --git a/packages/setup-ocaml/src/cache.ts b/packages/setup-ocaml/src/cache.ts index 225a809d..588869ab 100644 --- a/packages/setup-ocaml/src/cache.ts +++ b/packages/setup-ocaml/src/cache.ts @@ -9,18 +9,15 @@ import * as github from "@actions/github"; import * as datefns from "date-fns"; import { + ARCHITECTURE, CACHE_PREFIX, OCAML_COMPILER, OPAM_DISABLE_SANDBOXING, OPAM_REPOSITORIES, - Platform, + PLATFORM, } from "./constants.js"; import { getLatestOpamRelease } from "./opam.js"; -import { - getArchitecture, - getPlatform, - getSystemIdentificationInfo, -} from "./system.js"; +import { getSystemIdentificationInfo } from "./system.js"; import { resolveCompiler } from "./version.js"; import { getCygwinVersion } from "./win32.js"; @@ -48,8 +45,8 @@ async function composeCygwinCacheKeys() { } function composeDuneCacheKeys() { - const platform = getPlatform().replaceAll(/\W/g, "_"); - const architecture = getArchitecture().replaceAll(/\W/g, "_"); + const platform = PLATFORM.replaceAll(/\W/g, "_"); + const architecture = ARCHITECTURE.replaceAll(/\W/g, "_"); const { workflow: _workflow, job: _job, runId, runNumber } = github.context; const workflow = _workflow.toLowerCase().replaceAll(/\W/g, "_"); const job = _job.replaceAll(/\W/g, "_"); @@ -64,15 +61,13 @@ function composeDuneCacheKeys() { } async function composeOpamCacheKeys() { - const platform = getPlatform(); const fullPlatform = - platform === Platform.Win32 - ? platform + PLATFORM === "win32" + ? PLATFORM : // eslint-disable-next-line unicorn/no-await-expression-member - `${platform}-${(await getSystemIdentificationInfo()).version}`; - const architecture = getArchitecture(); + `${PLATFORM}-${(await getSystemIdentificationInfo()).version}`; const opamVersion = - platform === Platform.Win32 + PLATFORM === "win32" ? "0.0.0.2" : // eslint-disable-next-line unicorn/no-await-expression-member (await getLatestOpamRelease()).version; @@ -80,11 +75,11 @@ async function composeOpamCacheKeys() { const ocamlVersion = ocamlCompiler.toLowerCase().replaceAll(/\W/g, "_"); const sandboxed = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; const { year, week } = composeDate(); - const key = `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-${week}`; + const key = `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-${week}`; const restoreKeys = [ - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-${week}`, - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-${year}-`, - `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${architecture}-${ocamlVersion}-`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-${week}`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-${year}-`, + `${CACHE_PREFIX}-setup-ocaml-opam-${opamVersion}-${sandboxed}-${fullPlatform}-${ARCHITECTURE}-${ocamlVersion}-`, ]; return { key, restoreKeys }; } @@ -130,8 +125,7 @@ function composeCygwinCachePaths() { function composeDuneCachePaths() { const paths = []; const homeDir = os.homedir(); - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const duneCacheDir = path.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } else { @@ -146,8 +140,7 @@ function composeDuneCachePaths() { function composeOpamCachePaths() { const paths = []; - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamRootCachePath = path.join("D:", ".opam"); paths.push(opamRootCachePath); const { @@ -175,8 +168,7 @@ function composeOpamCachePaths() { function composeOpamDownloadCachePaths() { const paths = []; - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamDownloadCachePath = path.join("D:", ".opam", "download-cache"); paths.push(opamDownloadCachePath); } else { diff --git a/packages/setup-ocaml/src/constants.ts b/packages/setup-ocaml/src/constants.ts index 7e430afd..a6e3729c 100644 --- a/packages/setup-ocaml/src/constants.ts +++ b/packages/setup-ocaml/src/constants.ts @@ -1,22 +1,39 @@ +import * as os from "node:os"; import * as path from "node:path"; import * as core from "@actions/core"; import * as yaml from "yaml"; -import { getPlatform } from "./system.js"; - -export enum Architecture { - X86_64 = "x86_64", - ARM = "arm64", -} - -export enum Platform { - Linux = "linux", - MacOS = "macos", - Win32 = "win32", -} - -const platform = getPlatform(); +export const ARCHITECTURE = (() => { + switch (os.arch()) { + case "x64": { + return "x86_64"; + } + case "arm64": { + return "arm64"; + } + default: { + throw new Error("The architecture is not supported."); + } + } +})(); + +export const PLATFORM = (() => { + switch (os.platform()) { + case "linux": { + return "linux"; + } + case "darwin": { + return "macos"; + } + case "win32": { + return "win32"; + } + default: { + throw new Error("The platform is not supported."); + } + } +})(); export const CYGWIN_ROOT = path.join("D:", "cygwin"); @@ -26,7 +43,7 @@ export const CYGWIN_ROOT_WRAPPERBIN = path.join(CYGWIN_ROOT, "wrapperbin"); // [todo] remove the branch for Windows once opam 2.2 is released as stable. export const ALLOW_PRELEASE_OPAM = - platform !== Platform.Win32 && + PLATFORM !== "win32" && core.getBooleanInput("allow-prelease-opam", { required: false, trimWhitespace: true, @@ -86,7 +103,7 @@ const repositories_yaml = yaml.parse( ) as Record | null; const defaultRepository = - platform === Platform.Win32 + PLATFORM === "win32" ? "https://github.com/ocaml-opam/opam-repository-mingw.git#sunset" : "https://github.com/ocaml/opam-repository.git"; diff --git a/packages/setup-ocaml/src/depext.ts b/packages/setup-ocaml/src/depext.ts index f3977857..d92b4b0b 100644 --- a/packages/setup-ocaml/src/depext.ts +++ b/packages/setup-ocaml/src/depext.ts @@ -3,16 +3,14 @@ import * as path from "node:path"; import * as core from "@actions/core"; import { exec } from "@actions/exec"; -import { OPAM_DEPEXT_FLAGS, Platform } from "./constants.js"; -import { getPlatform } from "./system.js"; +import { OPAM_DEPEXT_FLAGS, PLATFORM } from "./constants.js"; export async function installDepext(ocamlVersion: string) { await core.group("Install depext", async () => { - const platform = getPlatform(); const depextCygwinports = - platform === Platform.Win32 ? ["depext-cygwinports"] : []; + PLATFORM === "win32" ? ["depext-cygwinports"] : []; await exec("opam", ["install", "opam-depext", ...depextCygwinports]); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { let base = ""; if (ocamlVersion.includes("mingw64")) { base = "x86_64-w64-mingw32"; diff --git a/packages/setup-ocaml/src/installer.ts b/packages/setup-ocaml/src/installer.ts index f9a1773d..ba0d2ad3 100644 --- a/packages/setup-ocaml/src/installer.ts +++ b/packages/setup-ocaml/src/installer.ts @@ -19,7 +19,7 @@ import { OPAM_DEPEXT, OPAM_PIN, OPAM_REPOSITORIES, - Platform, + PLATFORM, } from "./constants.js"; import { installDepext, installDepextPackages } from "./depext.js"; import { installDune } from "./dune.js"; @@ -31,11 +31,10 @@ import { setupOpam, } from "./opam.js"; import { getOpamLocalPackages } from "./packages.js"; -import { getPlatform, updateUnixPackageIndexFiles } from "./system.js"; +import { updateUnixPackageIndexFiles } from "./system.js"; import { resolveCompiler } from "./version.js"; export async function installer() { - const platform = getPlatform(); if (!ALLOW_PRELEASE_OPAM) { // [todo] remove this once opam 2.2 is released as stable. // https://github.com/ocaml/setup-ocaml/issues/299 @@ -49,11 +48,11 @@ export async function installer() { // https://github.com/ocaml/opam/issues/3447 core.exportVariable("OPAMSOLVERTIMEOUT", 1000); core.exportVariable("OPAMYES", 1); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamRoot = path.join("D:", ".opam"); core.exportVariable("OPAMROOT", opamRoot); } - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await core.group("Change the file system behavior parameters", async () => { await exec("fsutil", ["behavior", "query", "SymlinkEvaluation"]); // https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-behavior @@ -67,25 +66,25 @@ export async function installer() { await exec("fsutil", ["behavior", "query", "SymlinkEvaluation"]); }); } - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { core.exportVariable("HOME", process.env["USERPROFILE"]); core.exportVariable("MSYS", "winsymlinks:native"); } - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await restoreCygwinCache(); } const opamCacheHit = await restoreOpamCache(); await setupOpam(); await repositoryRemoveAll(); await repositoryAddAll(OPAM_REPOSITORIES); + const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); if (!opamCacheHit) { - const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); await installOcaml(ocamlCompiler); await saveOpamCache(); } await restoreOpamDownloadCache(); if (OPAM_DEPEXT) { - await installDepext(platform); + await installDepext(ocamlCompiler); } if (DUNE_CACHE) { await restoreDuneCache(); diff --git a/packages/setup-ocaml/src/opam.ts b/packages/setup-ocaml/src/opam.ts index 4b65d735..dc465d0d 100644 --- a/packages/setup-ocaml/src/opam.ts +++ b/packages/setup-ocaml/src/opam.ts @@ -13,16 +13,15 @@ import * as semver from "semver"; import { saveCygwinCache } from "./cache.js"; import { ALLOW_PRELEASE_OPAM, + ARCHITECTURE, CYGWIN_ROOT, CYGWIN_ROOT_BIN, CYGWIN_ROOT_WRAPPERBIN, GITHUB_TOKEN, OPAM_DISABLE_SANDBOXING, - Platform, + PLATFORM, } from "./constants.js"; import { - getArchitecture, - getPlatform, getSystemIdentificationInfo, updateUnixPackageIndexFiles, } from "./system.js"; @@ -51,10 +50,8 @@ export async function getLatestOpamRelease() { "Could not retrieve the opam release matching the version constraint", ); } - const architecture = getArchitecture(); - const platform = getPlatform(); const matchedAssets = latestRelease.assets.find((asset) => - asset.browser_download_url.includes(`${architecture}-${platform}`), + asset.browser_download_url.includes(`${ARCHITECTURE}-${PLATFORM}`), ); if (!matchedAssets) { throw new Error( @@ -68,8 +65,7 @@ export async function getLatestOpamRelease() { } async function findOpam() { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const opamPath = path.join(CYGWIN_ROOT, "bin", "opam.exe"); return opamPath; } else { @@ -80,8 +76,7 @@ async function findOpam() { async function acquireOpamUnix() { const { version, browserDownloadUrl } = await getLatestOpamRelease(); - const architecture = getArchitecture(); - const cachedPath = tc.find("opam", version, architecture); + const cachedPath = tc.find("opam", version, ARCHITECTURE); if (cachedPath === "") { const downloadedPath = await tc.downloadTool(browserDownloadUrl); core.info(`Acquired ${version} from ${browserDownloadUrl}`); @@ -90,7 +85,7 @@ async function acquireOpamUnix() { "opam", "opam", version, - architecture, + ARCHITECTURE, ); core.info(`Successfully cached opam to ${cachedPath}`); await fs.chmod(`${cachedPath}/opam`, 0o755); @@ -104,9 +99,8 @@ async function acquireOpamUnix() { async function installUnixSystemPackages() { const isGitHubRunner = process.env["ImageOS"] !== undefined; - const platform = getPlatform(); if (isGitHubRunner) { - if (platform === Platform.Linux) { + if (PLATFORM === "linux") { const { version: systemVersion } = await getSystemIdentificationInfo(); if (systemVersion === "18.04") { // [info]: musl-tools bug in ubuntu 18.04; @@ -125,7 +119,7 @@ async function installUnixSystemPackages() { "musl-tools", "rsync", ]); - } else if (platform === Platform.MacOS) { + } else if (PLATFORM === "macos") { await exec("brew", ["install", "darcs", "gpatch", "mercurial"]); } } @@ -275,8 +269,7 @@ async function setupOpamWindows() { } export async function setupOpam() { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { await setupOpamWindows(); } else { await setupOpamUnix(); @@ -285,8 +278,7 @@ export async function setupOpam() { export async function installOcaml(ocamlCompiler: string) { await core.group("Install OCaml", async () => { - const platform = getPlatform(); - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const originalPath = process.env["PATH"]!.split(path.delimiter); const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; @@ -340,12 +332,11 @@ async function repositoryAdd(name: string, address: string) { export async function repositoryAddAll(repositories: [string, string][]) { await core.group("Initialise the opam repositories", async () => { - const platform = getPlatform(); let restore_autocrlf; // Works around the lack of https://github.com/ocaml/opam/pull/3882 when // adding ocaml/opam-repository on Windows. Can be removed when the action // switches to opam 2.2 - if (platform === Platform.Win32) { + if (PLATFORM === "win32") { const autocrlf = await getExecOutput( "git", ["config", "--global", "core.autocrlf"], diff --git a/packages/setup-ocaml/src/system.ts b/packages/setup-ocaml/src/system.ts index 8b63c014..ae86d93b 100644 --- a/packages/setup-ocaml/src/system.ts +++ b/packages/setup-ocaml/src/system.ts @@ -3,42 +3,10 @@ import * as os from "node:os"; import { exec, getExecOutput } from "@actions/exec"; -import { Architecture, Platform } from "./constants.js"; - -export function getArchitecture() { - switch (os.arch()) { - case "x64": { - return Architecture.X86_64; - } - case "arm64": { - return Architecture.ARM; - } - default: { - throw new Error("The architecture is not supported."); - } - } -} - -export function getPlatform() { - switch (os.platform()) { - case "linux": { - return Platform.Linux; - } - case "darwin": { - return Platform.MacOS; - } - case "win32": { - return Platform.Win32; - } - default: { - throw new Error("The platform is not supported."); - } - } -} +import { PLATFORM } from "./constants.js"; export async function getSystemIdentificationInfo() { - const platform = getPlatform(); - if (platform === Platform.Linux) { + if (PLATFORM === "linux") { const osRelease = await fs.readFile("/etc/os-release", "utf8"); const lines = osRelease.split(os.EOL); let id = ""; @@ -52,7 +20,7 @@ export async function getSystemIdentificationInfo() { } } return { id, version }; - } else if (platform === Platform.MacOS) { + } else if (PLATFORM === "macos") { const swVers = await getExecOutput("sw_vers"); const lines = swVers.stdout.split(os.EOL); let version = ""; @@ -70,11 +38,10 @@ export async function getSystemIdentificationInfo() { export async function updateUnixPackageIndexFiles() { const isGitHubRunner = process.env["ImageOS"] !== undefined; - const platform = getPlatform(); if (isGitHubRunner) { - if (platform === Platform.Linux) { + if (PLATFORM === "linux") { await exec("sudo", ["apt-get", "update"]); - } else if (platform === Platform.MacOS) { + } else if (PLATFORM === "macos") { await exec("brew", ["update"]); } } diff --git a/packages/setup-ocaml/src/version.ts b/packages/setup-ocaml/src/version.ts index b673b687..d38f2921 100644 --- a/packages/setup-ocaml/src/version.ts +++ b/packages/setup-ocaml/src/version.ts @@ -3,8 +3,7 @@ import * as path from "node:path"; import * as github from "@actions/github"; import * as semver from "semver"; -import { GITHUB_TOKEN, Platform } from "./constants.js"; -import { getPlatform } from "./system.js"; +import { GITHUB_TOKEN, PLATFORM } from "./constants.js"; function isSemverValidRange(semverVersion: string) { const isValidSemver = @@ -17,12 +16,12 @@ function isSemverValidRange(semverVersion: string) { async function getAllCompilerVersions() { const octokit = github.getOctokit(GITHUB_TOKEN); - const platform = getPlatform(); - const owner = platform === Platform.Win32 ? "ocaml-opam" : "ocaml"; + + const owner = PLATFORM === "win32" ? "ocaml-opam" : "ocaml"; const repo = - platform === Platform.Win32 ? "opam-repository-mingw" : "opam-repository"; + PLATFORM === "win32" ? "opam-repository-mingw" : "opam-repository"; const prefix = - platform === Platform.Win32 ? "ocaml-variants" : "ocaml-base-compiler"; + PLATFORM === "win32" ? "ocaml-variants" : "ocaml-base-compiler"; const { data: packages } = await octokit.rest.repos.getContent({ owner, repo, @@ -62,9 +61,8 @@ async function resolveVersion(semverVersion: string) { } export async function resolveCompiler(compiler: string) { - const platform = getPlatform(); const resolvedCompiler = isSemverValidRange(compiler) - ? platform === Platform.Win32 + ? PLATFORM === "win32" ? `ocaml-variants.${await resolveVersion(compiler)}+mingw64c` : `ocaml-base-compiler.${await resolveVersion(compiler)}` : compiler;