diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 00b2021b..ef1ea0ff 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -49,21 +49,12 @@ jobs: os: - macos-latest - ubuntu-latest + - windows-latest ocaml-compiler: - "5.2" - allow-prerelease-opam: - - false include: - - os: windows-latest - ocaml-compiler: ocaml-variants.5.2.0+options,ocaml-option-mingw - allow-prerelease-opam: false - opam-repositories: | - windows-5.0: https://github.com/dra27/opam-repository.git#windows-5.0 - sunset: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset - default: https://github.com/ocaml/opam-repository.git - os: ubuntu-latest ocaml-compiler: ocaml-variants.5.2.0+options,ocaml-option-flambda - allow-prerelease-opam: true runs-on: ${{ matrix.os }} @@ -75,8 +66,6 @@ jobs: uses: ./ with: ocaml-compiler: ${{ matrix.ocaml-compiler }} - allow-prerelease-opam: ${{ matrix.allow-prerelease-opam }} - dune-cache: ${{ runner.os != 'Windows' }} - opam-repositories: ${{ matrix.opam-repositories }} + allow-prerelease-opam: true - - run: opam depext --install uri + - run: opam install uri diff --git a/CHANGELOG.md b/CHANGELOG.md index ec850c69..74b50b43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to ## [unreleased] +### Added + +- Add initial support for opam 2.2 on Windows. + ## [2.2.10] ### Changed diff --git a/EXAMPLES.md b/EXAMPLES.md index 7798b252..db75c5ca 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -59,55 +59,6 @@ jobs: uses: actions/deploy-pages@v4 ``` -## Using several conditional setup steps - -```yml -steps: - - name: Checkout tree - uses: actions/checkout@v4 - - - name: Set-up OCaml on Windows - uses: ocaml/setup-ocaml@v2 - if: runner.os == 'Windows' - with: - opam-repositories: | - sunset: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset - default: https://github.com/ocaml/opam-repository.git - - - name: Set-up OCaml on Unix - uses: ocaml/setup-ocaml@v2 - if: runner.os != 'Windows' - with: - opam-repositories: | - default: https://github.com/ocaml/opam-repository.git -``` - -## Using a custom step to choose between the values - -```yml -steps: - - name: Checkout tree - uses: actions/checkout@v4 - - - name: Set opam repository url - id: repository - shell: bash - run: | - if [ "$RUNNER_OS" == "Windows" ]; then - echo "::set-output name=url::https://github.com/ocaml-opam/opam-repository-mingw.git#sunset" - elif [ "$RUNNER_OS" == "macOS" ]; then - echo "::set-output name=url::https://github.com/custom/opam-repository.git#macOS" - else - echo "::set-output name=url::https://github.com/ocaml/opam-repository.git" - fi - - - name: Set-up OCaml with repository ${{ steps.repository.outputs.url }} - uses: ocaml/setup-ocaml@v2 - with: - opam-repositories: | - default: ${{ steps.repository.outputs.url }} -``` - ## Using glob patterns to filter local packages Consult the diff --git a/README.md b/README.md index 83d94d5f..c7dac2d5 100644 --- a/README.md +++ b/README.md @@ -97,18 +97,16 @@ steps: ## Inputs -| Name | Required | Description | Type | Default | -| ------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | -| `ocaml-compiler` | Yes | The OCaml compiler packages to initialise. Consult the [supported version syntax](#supported-version-syntax) section. | string | | -| `opam-repositories` | No | The name and URL pair of the repository to fetch the packages from. | string | | -| `opam-pin` | No | Enable the automation feature for opam pin. | bool | `true` | -| `opam-depext` | No | Enable the automation feature for opam depext. | bool | `true` | -| `opam-depext-flags` | No | The flags for the opam depext command. The flags must be separated by the comma. | string | | -| `opam-local-packages` | No | The local packages to be used by `opam-pin` or `opam-depext`. Consult the [`@actions/glob` documentation](https://github.com/actions/toolkit/tree/main/packages/glob) package for supported patterns. | string | `*.opam` | -| `opam-disable-sandboxing` | No | Disable the opam sandboxing feature. | bool | `false` | -| `dune-cache` | No | Enable the dune cache feature. This feature **_requires_** dune 2.8.5 or later on the Windows runners. | bool | `false` | -| `cache-prefix` | No | The prefix of the cache keys. | string | `v1` | -| `allow-prerelease-opam` | No | Allow to use a pre-release version of opam. | bool | `false` | +| Name | Required | Description | Type | Default | +| ------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | -------- | +| `ocaml-compiler` | Yes | The OCaml compiler packages to initialise. Consult the [supported version syntax](#supported-version-syntax) section. | string | | +| `opam-repositories` | No | The name and URL pair of the repository to fetch the packages from. | string | | +| `opam-pin` | No | Enable the automation feature for opam pin. | bool | `true` | +| `opam-local-packages` | No | The local packages to be used by `opam-pin`. Consult the [`@actions/glob` documentation](https://github.com/actions/toolkit/tree/main/packages/glob) package for supported patterns. | string | `*.opam` | +| `opam-disable-sandboxing` | No | Disable the opam sandboxing feature. | bool | `false` | +| `dune-cache` | No | Enable the dune cache feature. This feature **_requires_** dune 2.8.5 or later on the Windows runners. | bool | `false` | +| `cache-prefix` | No | The prefix of the cache keys. | string | `v1` | +| `allow-prerelease-opam` | No | Allow to use a pre-release version of opam. | bool | `false` | ### Supported version syntax @@ -122,12 +120,11 @@ more detailed examples please refer to the Examples: -- Exact package name: `ocaml-base-compiler.5.2.0`, - `ocaml-variants.4.14.2+mingw64c` +- Exact package name: `ocaml-base-compiler.5.2.0` - Combine multiple packages: `ocaml-variants.5.2.0+options,ocaml-option-flambda,ocaml-option-musl,ocaml-option-static` - Minor versions: `4.08`, `4.14`, `5.2`, `5.2.x` -- More specific versions: `~4.02.2`, `5.1.0`, +- More specific versions: `~4.02.2`, `5.1.0` ## Advanced Configurations diff --git a/action.yml b/action.yml index 28ed311d..d8ad08fe 100644 --- a/action.yml +++ b/action.yml @@ -20,16 +20,8 @@ inputs: description: Enable the automation feature for opam pin. required: false default: "true" - opam-depext: - description: Enable the automation feature for opam depext. - required: false - default: "true" - opam-depext-flags: - description: The flags for the opam depext command. - required: false - default: "" opam-local-packages: - description: The local packages to be used by `opam-pin` or `opam-depext`. + description: The local packages to be used by `opam-pin`. required: false default: "*.opam" opam-disable-sandboxing: diff --git a/analysis/dist/index.js b/analysis/dist/index.js index 980e6d10..36e87398 100644 --- a/analysis/dist/index.js +++ b/analysis/dist/index.js @@ -34957,12 +34957,12 @@ async function analysis() { const { name } = external_node_path_namespaceObject.parse(fpath); await (0,exec.exec)("opam", [ "tree", - name, + `--json=${tempJson}`, "--with-dev-setup", // [NOTE] https://github.com/ocaml/opam/issues/4541 // "--with-doc", "--with-test", - `--json=${tempJson}`, + name, ], { env: { ...process.env, @@ -34986,12 +34986,12 @@ async function installOpamPackages() { await core.group("Install opam packages", async () => { await (0,exec.exec)("opam", [ "install", - ".", "--deps-only", "--with-dev-setup", // [NOTE] https://github.com/ocaml/opam/issues/4541 // "--with-doc", "--with-test", + ".", ]); }); } diff --git a/dist/index.js b/dist/index.js index d75be056..93856b99 100644 --- a/dist/index.js +++ b/dist/index.js @@ -92580,22 +92580,19 @@ const PLATFORM = (() => { return "macos"; } case "win32": { - return "win32"; + return "windows"; } default: { throw new Error("The platform is not supported."); } } })(); +const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; 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_PRERELEASE_OPAM = PLATFORM !== "win32" && - lib_core.getBooleanInput("allow-prerelease-opam", { - required: false, - trimWhitespace: true, - }); +const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam", { + required: false, + trimWhitespace: true, +}); const CACHE_PREFIX = lib_core.getInput("cache-prefix", { required: false, trimWhitespace: true, @@ -92612,17 +92609,14 @@ const OCAML_COMPILER = lib_core.getInput("ocaml-compiler", { required: true, trimWhitespace: true, }); -// [todo] remove this once opam 2.2 is released as stable. -const OPAM_DEPEXT = !ALLOW_PRERELEASE_OPAM && - lib_core.getBooleanInput("opam-depext", { +const OPAM_DISABLE_SANDBOXING = +// [TODO] unlock this once sandboxing is supported on Windows +PLATFORM === "windows" + ? true + : lib_core.getBooleanInput("opam-disable-sandboxing", { required: false, trimWhitespace: true, }); -const OPAM_DEPEXT_FLAGS = lib_core.getInput("opam-depext-flags", { required: false, trimWhitespace: true }) - .split(",") - .map((f) => f.trim()) - .filter((f) => f.length > 0); -const OPAM_DISABLE_SANDBOXING = lib_core.getBooleanInput("opam-disable-sandboxing", { required: false, trimWhitespace: true }); const OPAM_LOCAL_PACKAGES = lib_core.getInput("opam-local-packages", { required: false, trimWhitespace: true, @@ -92632,12 +92626,9 @@ 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 === "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]]; + : [["default", "https://github.com/ocaml/opam-repository.git"]]; ;// CONCATENATED MODULE: external "node:fs" const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs"); @@ -92670,7 +92661,7 @@ async function getSystemIdentificationInfo() { return { id, version }; } if (PLATFORM === "macos") { - const swVers = await (0,lib_exec.getExecOutput)("sw_vers"); + const swVers = await (0,lib_exec.getExecOutput)("sw_vers", [], { silent: true }); const lines = swVers.stdout.split(external_node_os_.EOL); let version = ""; for (const line of lines) { @@ -109975,7 +109966,7 @@ const { parseHTML: esm_parseHTML } = static_namespaceObject; */ const { root: esm_root } = static_namespaceObject; //# sourceMappingURL=index.js.map -;// CONCATENATED MODULE: ./src/win32.ts +;// CONCATENATED MODULE: ./src/windows.ts @@ -110011,9 +110002,8 @@ async function getCygwinVersion() { - async function getLatestOpamRelease() { - const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.2.0"; + const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.3.0"; const octokit = lib_github.getOctokit(constants_GITHUB_TOKEN); const { data: releases } = await octokit.rest.repos.listReleases({ owner: "ocaml", @@ -110038,23 +110028,16 @@ async function getLatestOpamRelease() { browserDownloadUrl: matchedAssets.browser_download_url, }; } -async function findOpam() { - if (PLATFORM === "win32") { - const opamPath = external_node_path_namespaceObject.join(CYGWIN_ROOT, "bin", "opam.exe"); - return opamPath; - } - const opamPath = await io.which("opam"); - return opamPath; -} -async function acquireOpamUnix() { +async function acquireOpam() { const { version, browserDownloadUrl } = await getLatestOpamRelease(); const cachedPath = tool_cache.find("opam", version, ARCHITECTURE); + const opam = PLATFORM !== "windows" ? "opam" : "opam.exe"; 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); + await external_node_fs_namespaceObject.promises.chmod(external_node_path_namespaceObject.join(cachedPath, opam), 0o755); lib_core.addPath(cachedPath); lib_core.info("Added opam to the path"); } @@ -110069,7 +110052,7 @@ async function installUnixSystemPackages() { if (PLATFORM === "linux") { const { version: systemVersion } = await getSystemIdentificationInfo(); if (systemVersion === "18.04") { - // [info]: musl-tools bug in ubuntu 18.04; + // [INFO]: musl-tools bug in ubuntu 18.04; // await (0,lib_exec.exec)("sudo", ["add-apt-repository", "ppa:avsm/musl"]); } @@ -110116,7 +110099,7 @@ async function initializeOpamUnix() { } async function setupOpamUnix() { await lib_core.group("Install opam", async () => { - await acquireOpamUnix(); + await acquireOpam(); }); await lib_core.group("Initialise the opam state", async () => { await initializeOpamUnix(); @@ -110133,7 +110116,6 @@ async function setupCygwin() { else { lib_core.addPath(cachedPath); } - const site = "https://mirrors.kernel.org/sourceware/cygwin"; const packages = [ "curl", "diffutils", @@ -110148,78 +110130,46 @@ async function setupCygwin() { "rsync", "unzip", ].join(","); - await (0,lib_exec.exec)("setup-x86_64.exe", [ + await (0,lib_exec.exec)("setup-x86_64", [ + `--packages=${packages}`, "--quiet-mode", - "--root", - CYGWIN_ROOT, - "--site", - site, - "--packages", - packages, + `--root=${CYGWIN_ROOT}`, + `--site=${CYGWIN_MIRROR}`, "--symlink-type=sys", ]); - const setupExePath = await io.which("setup-x86_64.exe"); - await io.cp(setupExePath, CYGWIN_ROOT); -} -async function acquireOpamWindows() { - const opamVersion = "0.0.0.2"; - const cachedPath = tool_cache.find("opam", opamVersion); - if (cachedPath === "") { - const downloadedPath = await tool_cache.downloadTool(`https://github.com/fdopen/opam-repository-mingw/releases/download/${opamVersion}/opam64.zip`); - const extractedPath = await tool_cache.extractZip(downloadedPath); - const cachedPath = await tool_cache.cacheDir(extractedPath, "opam", opamVersion); - const installSh = external_node_path_namespaceObject.join(cachedPath, "opam64", "install.sh"); - await external_node_fs_namespaceObject.promises.chmod(installSh, 0o755); - await (0,lib_exec.exec)("bash", [installSh, "--prefix", "/usr"]); - } - else { - const installSh = external_node_path_namespaceObject.join(cachedPath, "opam64", "install.sh"); - await external_node_fs_namespaceObject.promises.chmod(installSh, 0o755); - await (0,lib_exec.exec)("bash", [installSh, "--prefix", "/usr"]); - } + const setup = await io.which("setup-x86_64"); + await io.cp(setup, CYGWIN_ROOT); } async function initializeOpamWindows() { - await (0,lib_exec.exec)("git", ["config", "--global", "--add", "safe.directory", "'*'"]); + const disableSandboxing = []; + if (OPAM_DISABLE_SANDBOXING) { + disableSandboxing.push("--disable-sandboxing"); + } await (0,lib_exec.exec)("opam", [ "init", "--auto-setup", "--bare", - "--disable-sandboxing", + "--cygwin-local-install", + `--cygwin-location=${CYGWIN_ROOT}`, + ...disableSandboxing, "--enable-shell-hook", ]); - await io.mkdirP(CYGWIN_ROOT_WRAPPERBIN); - const opamCmd = external_node_path_namespaceObject.join(CYGWIN_ROOT_WRAPPERBIN, "opam.cmd"); - const data = [ - "@setlocal", - "@echo off", - "set PATH=%CYGWIN_ROOT_BIN%;%PATH%", - "ocaml-env exec -- opam.exe %*", - ].join(external_node_os_.EOL); - await external_node_fs_namespaceObject.promises.writeFile(opamCmd, data, { mode: 0o755 }); } async function setupOpamWindows() { await lib_core.group("Prepare the Cygwin environment", async () => { lib_core.exportVariable("CYGWIN", "winsymlinks:native"); - lib_core.exportVariable("CYGWIN_ROOT", CYGWIN_ROOT); - lib_core.exportVariable("CYGWIN_ROOT_BIN", CYGWIN_ROOT_BIN); - lib_core.exportVariable("CYGWIN_ROOT_WRAPPERBIN", CYGWIN_ROOT_WRAPPERBIN); - lib_core.addPath(CYGWIN_ROOT_WRAPPERBIN); await setupCygwin(); }); await saveCygwinCache(); - const originalPath = external_node_process_.env.PATH?.split(external_node_path_namespaceObject.delimiter) ?? []; - const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; - external_node_process_.env.PATH = patchedPath.join(external_node_path_namespaceObject.delimiter); await lib_core.group("Install opam", async () => { - await acquireOpamWindows(); + await acquireOpam(); }); await lib_core.group("Initialise the opam state", async () => { await initializeOpamWindows(); }); - external_node_process_.env.PATH = originalPath.join(external_node_path_namespaceObject.delimiter); } async function setupOpam() { - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { await setupOpamWindows(); } else { @@ -110228,96 +110178,49 @@ async function setupOpam() { } async function installOcaml(ocamlCompiler) { await lib_core.group("Install OCaml", async () => { - if (PLATFORM === "win32") { - const originalPath = external_node_process_.env.PATH?.split(external_node_path_namespaceObject.delimiter) ?? []; - const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; - external_node_process_.env.PATH = patchedPath.join(external_node_path_namespaceObject.delimiter); - await (0,lib_exec.exec)("opam", [ - "switch", - "create", - ".", - "--no-install", - "--packages", - ocamlCompiler, - ]); - external_node_process_.env.PATH = originalPath.join(external_node_path_namespaceObject.delimiter); - } - else { - await (0,lib_exec.exec)("opam", [ - "switch", - "create", - ".", - "--no-install", - "--packages", - ocamlCompiler, - ]); - } + await (0,lib_exec.exec)("opam", [ + "switch", + "--no-install", + "--packages", + "create", + ".", + ocamlCompiler, + ]); }); } async function pin(fpaths) { await lib_core.group("Pin local packages", async () => { - const opam = await findOpam(); for (const fpath of fpaths) { const fname = external_node_path_namespaceObject.basename(fpath, ".opam"); const dname = external_node_path_namespaceObject.dirname(fpath); - await (0,lib_exec.exec)(opam, ["pin", "add", `${fname}.dev`, ".", "--no-action"], { + await (0,lib_exec.exec)("opam", ["pin", "--no-action", "add", `${fname}.dev`, "."], { cwd: dname, }); } }); } async function repositoryAdd(name, address) { - const opam = await findOpam(); - await (0,lib_exec.exec)(opam, [ + await (0,lib_exec.exec)("opam", [ "repository", + "--all-switches", + "--set-default", "add", name, address, - "--all-switches", - "--set-default", ]); } async function repositoryAddAll(repositories) { await lib_core.group("Initialise the opam repositories", async () => { - let restore_autocrlf = undefined; - // 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 === "win32") { - const autocrlf = await (0,lib_exec.getExecOutput)("git", ["config", "--global", "core.autocrlf"], { ignoreReturnCode: true }); - if (autocrlf.stdout.trim() !== "input") { - if (autocrlf.exitCode === 0) { - restore_autocrlf = autocrlf.stdout.trim(); - } - else { - restore_autocrlf = null; // Unset the value at the end - } - } - await (0,lib_exec.exec)("git", ["config", "--global", "core.autocrlf", "input"]); - } for (const [name, address] of repositories) { await repositoryAdd(name, address); } - if (restore_autocrlf === null) { - await (0,lib_exec.exec)("git", ["config", "--global", "--unset", "core.autocrlf"]); - } - else if (restore_autocrlf !== undefined) { - await (0,lib_exec.exec)("git", [ - "config", - "--global", - "core.autocrlf", - restore_autocrlf, - ]); - } }); } async function repositoryRemove(name) { - const opam = await findOpam(); - await (0,lib_exec.exec)(opam, ["repository", "remove", name, "--all-switches"]); + await (0,lib_exec.exec)("opam", ["repository", "--all-switches", "remove", name]); } async function repositoryList() { - const opam = await findOpam(); - const repositoryList = await (0,lib_exec.getExecOutput)(opam, ["repository", "list", "--all-switches", "--short"], { ignoreReturnCode: true }); + const repositoryList = await (0,lib_exec.getExecOutput)("opam", ["repository", "--all-switches", "--short", "list"], { ignoreReturnCode: true, silent: true }); if (repositoryList.exitCode === 0) { return repositoryList.stdout .split("\n") @@ -110341,27 +110244,20 @@ 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 - // syntax even though it's valid... - const plus = !semverVersion.includes("+"); - return isValidSemver && plus; + return semver.validRange(semverVersion, { loose: true }) !== null; } async function getAllCompilerVersions() { const octokit = lib_github.getOctokit(constants_GITHUB_TOKEN); - 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, - path: `packages/${prefix}`, + 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(`${prefix}.`, ""); + const version = basename.replace("ocaml-base-compiler.", ""); const parsed = semver.parse(version, { loose: true }); if (parsed !== null) { const { major, minor: _minor, patch } = parsed; @@ -110383,9 +110279,7 @@ async function resolveVersion(semverVersion) { } async function resolveCompiler(compiler) { const resolvedCompiler = isSemverValidRange(compiler) - ? PLATFORM === "win32" - ? `ocaml-variants.${await resolveVersion(compiler)}+mingw64c` - : `ocaml-base-compiler.${await resolveVersion(compiler)}` + ? `ocaml-base-compiler.${await resolveVersion(compiler)}` : compiler; return resolvedCompiler; } @@ -110441,10 +110335,10 @@ function composeDuneCacheKeys() { return { key, restoreKeys }; } async function composeOpamCacheKeys() { - const fullPlatform = PLATFORM === "win32" + const fullPlatform = PLATFORM === "windows" ? PLATFORM : `${PLATFORM}-${(await getSystemIdentificationInfo()).version}`; - const opamVersion = PLATFORM === "win32" ? "0.0.0.2" : (await getLatestOpamRelease()).version; + const opamVersion = (await getLatestOpamRelease()).version; const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); const ocamlVersion = ocamlCompiler.toLowerCase().replaceAll(/\W/g, "_"); const sandboxed = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; @@ -110487,7 +110381,7 @@ function composeCygwinCachePaths() { paths.push(cygwinRoot); const cygwinRootSymlinkPath = external_node_path_namespaceObject.posix.join("/cygdrive", "d", "cygwin"); paths.push(cygwinRootSymlinkPath); - const cygwinEncodedUri = encodeURIComponent("https://mirrors.kernel.org/sourceware/cygwin/").toLowerCase(); + const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); const cygwinPackageRoot = external_node_path_namespaceObject.join(githubWorkspace, cygwinEncodedUri); paths.push(cygwinPackageRoot); return paths; @@ -110495,7 +110389,7 @@ function composeCygwinCachePaths() { function composeDuneCachePaths() { const paths = []; const homeDir = external_node_os_.homedir(); - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const duneCacheDir = external_node_path_namespaceObject.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } @@ -110510,7 +110404,7 @@ function composeDuneCachePaths() { } function composeOpamCachePaths() { const paths = []; - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const opamRootCachePath = external_node_path_namespaceObject.join("D:", ".opam"); paths.push(opamRootCachePath); const { repo: { repo }, } = lib_github.context; @@ -110529,7 +110423,7 @@ function composeOpamCachePaths() { } function composeOpamDownloadCachePaths() { const paths = []; - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const opamDownloadCachePath = external_node_path_namespaceObject.join("D:", ".opam", "download-cache"); paths.push(opamDownloadCachePath); } @@ -110627,34 +110521,6 @@ async function saveOpamDownloadCache() { }); } -;// CONCATENATED MODULE: ./src/depext.ts - - - - -async function installDepext(ocamlVersion) { - await lib_core.group("Install depext", async () => { - const depextCygwinports = PLATFORM === "win32" ? ["depext-cygwinports"] : []; - await (0,lib_exec.exec)("opam", ["install", "opam-depext", ...depextCygwinports]); - if (PLATFORM === "win32") { - let base = ""; - if (ocamlVersion.includes("mingw64")) { - base = "x86_64-w64-mingw32"; - } - else if (ocamlVersion.includes("mingw32")) { - base = "i686-w64-mingw32"; - } - lib_core.addPath(external_node_path_namespaceObject.posix.join("/", "usr", base, "sys-root", "mingw", "bin")); - } - }); -} -async function installDepextPackages(fpaths) { - await lib_core.group("Install system packages required by opam packages", async () => { - const fnames = fpaths.map((fpath) => external_node_path_namespaceObject.basename(fpath, ".opam")); - await (0,lib_exec.exec)("opam", ["depext", ...fnames, ...OPAM_DEPEXT_FLAGS]); - }); -} - ;// CONCATENATED MODULE: ./src/dune.ts @@ -110663,12 +110529,7 @@ async function installDepextPackages(fpaths) { const { repo: { owner, repo }, runId: run_id, } = lib_github.context; async function installDune() { await lib_core.group("Install dune", async () => { - if (OPAM_DEPEXT) { - await (0,lib_exec.exec)("opam", ["depext", "--install", "dune"]); - } - else { - await (0,lib_exec.exec)("opam", ["install", "dune"]); - } + await (0,lib_exec.exec)("opam", ["install", "dune"]); }); } async function trimDuneCache() { @@ -110686,8 +110547,7 @@ async function trimDuneCache() { "dune", "cache", "trim", - "--size", - `${cacheSize}MB`, + `--size=${cacheSize}MB`, ]); }); } @@ -110715,33 +110575,21 @@ async function getOpamLocalPackages() { - - async function installer() { if (lib_core.isDebug()) { lib_core.exportVariable("OPAMVERBOSE", 1); } - if (ALLOW_PRERELEASE_OPAM) { - lib_core.exportVariable("OPAMCONFIRMLEVEL", "unsafe-yes"); - } - else { - // [todo] remove this once opam 2.2 is released as stable. - // https://github.com/ocaml/setup-ocaml/issues/299 - lib_core.exportVariable("OPAMCLI", "2.0"); - } lib_core.exportVariable("OPAMCOLOR", "always"); + lib_core.exportVariable("OPAMCONFIRMLEVEL", "unsafe-yes"); lib_core.exportVariable("OPAMERRLOGLEN", 0); lib_core.exportVariable("OPAMJOBS", external_node_os_.cpus().length); lib_core.exportVariable("OPAMPRECISETRACKING", 1); - // [todo] remove this once opam 2.2 is released as stable. - // https://github.com/ocaml/opam/issues/3447 - lib_core.exportVariable("OPAMSOLVERTIMEOUT", 1000); lib_core.exportVariable("OPAMYES", 1); - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const opamRoot = external_node_path_namespaceObject.join("D:", ".opam"); lib_core.exportVariable("OPAMROOT", opamRoot); } - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { 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 @@ -110755,11 +110603,11 @@ async function installer() { await (0,lib_exec.exec)("fsutil", ["behavior", "query", "SymlinkEvaluation"]); }); } - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { lib_core.exportVariable("HOME", external_node_process_.env.USERPROFILE); lib_core.exportVariable("MSYS", "winsymlinks:native"); } - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { await restoreCygwinCache(); } const opamCacheHit = await restoreOpamCache(); @@ -110772,9 +110620,6 @@ async function installer() { await saveOpamCache(); } await restoreOpamDownloadCache(); - if (OPAM_DEPEXT) { - await installDepext(ocamlCompiler); - } if (DUNE_CACHE) { await restoreDuneCache(); await installDune(); @@ -110788,23 +110633,8 @@ async function installer() { if (OPAM_PIN) { await pin(fnames); } - if (OPAM_DEPEXT) { - try { - await installDepextPackages(fnames); - } - catch (error) { - if (error instanceof Error) { - lib_core.notice(`An error has been caught in some system package index files, so the system package index files have been re-synchronised, and the system package installation has been retried: ${error.message.toLocaleLowerCase()}`); - } - await updateUnixPackageIndexFiles(); - await installDepextPackages(fnames); - } - } } await (0,lib_exec.exec)("opam", ["--version"]); - if (OPAM_DEPEXT) { - await (0,lib_exec.exec)("opam", ["depext", "--version"]); - } await (0,lib_exec.exec)("opam", ["exec", "--", "ocaml", "-version"]); } diff --git a/dist/post/index.js b/dist/post/index.js index 81310885..c3ea6fc9 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -85384,22 +85384,19 @@ const constants_PLATFORM = (() => { return "macos"; } case "win32": { - return "win32"; + return "windows"; } default: { throw new Error("The platform is not supported."); } } })(); +const constants_CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; 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_PRERELEASE_OPAM = constants_PLATFORM !== "win32" && - lib_core.getBooleanInput("allow-prerelease-opam", { - required: false, - trimWhitespace: true, - }); +const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam", { + required: false, + trimWhitespace: true, +}); const constants_CACHE_PREFIX = lib_core.getInput("cache-prefix", { required: false, trimWhitespace: true, @@ -85416,17 +85413,14 @@ const constants_OCAML_COMPILER = lib_core.getInput("ocaml-compiler", { required: true, trimWhitespace: true, }); -// [todo] remove this once opam 2.2 is released as stable. -const constants_OPAM_DEPEXT = !ALLOW_PRERELEASE_OPAM && - lib_core.getBooleanInput("opam-depext", { +const constants_OPAM_DISABLE_SANDBOXING = +// [TODO] unlock this once sandboxing is supported on Windows +constants_PLATFORM === "windows" + ? true + : lib_core.getBooleanInput("opam-disable-sandboxing", { required: false, trimWhitespace: true, }); -const OPAM_DEPEXT_FLAGS = lib_core.getInput("opam-depext-flags", { required: false, trimWhitespace: true }) - .split(",") - .map((f) => f.trim()) - .filter((f) => f.length > 0); -const constants_OPAM_DISABLE_SANDBOXING = lib_core.getBooleanInput("opam-disable-sandboxing", { required: false, trimWhitespace: true }); const OPAM_LOCAL_PACKAGES = lib_core.getInput("opam-local-packages", { required: false, trimWhitespace: true, @@ -85436,12 +85430,9 @@ 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 = 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]]; + : [["default", "https://github.com/ocaml/opam-repository.git"]]; ;// CONCATENATED MODULE: ./src/cache.ts @@ -85494,10 +85485,10 @@ function composeDuneCacheKeys() { return { key, restoreKeys }; } async function composeOpamCacheKeys() { - const fullPlatform = PLATFORM === "win32" + const fullPlatform = PLATFORM === "windows" ? PLATFORM : `${PLATFORM}-${(await getSystemIdentificationInfo()).version}`; - const opamVersion = PLATFORM === "win32" ? "0.0.0.2" : (await getLatestOpamRelease()).version; + const opamVersion = (await getLatestOpamRelease()).version; const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); const ocamlVersion = ocamlCompiler.toLowerCase().replaceAll(/\W/g, "_"); const sandboxed = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; @@ -85540,7 +85531,7 @@ function composeCygwinCachePaths() { paths.push(cygwinRoot); const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin"); paths.push(cygwinRootSymlinkPath); - const cygwinEncodedUri = encodeURIComponent("https://mirrors.kernel.org/sourceware/cygwin/").toLowerCase(); + const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); const cygwinPackageRoot = path.join(githubWorkspace, cygwinEncodedUri); paths.push(cygwinPackageRoot); return paths; @@ -85548,7 +85539,7 @@ function composeCygwinCachePaths() { function composeDuneCachePaths() { const paths = []; const homeDir = external_node_os_.homedir(); - if (constants_PLATFORM === "win32") { + if (constants_PLATFORM === "windows") { const duneCacheDir = external_node_path_namespaceObject.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } @@ -85563,7 +85554,7 @@ function composeDuneCachePaths() { } function composeOpamCachePaths() { const paths = []; - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const opamRootCachePath = path.join("D:", ".opam"); paths.push(opamRootCachePath); const { repo: { repo }, } = github.context; @@ -85582,7 +85573,7 @@ function composeOpamCachePaths() { } function composeOpamDownloadCachePaths() { const paths = []; - if (constants_PLATFORM === "win32") { + if (constants_PLATFORM === "windows") { const opamDownloadCachePath = external_node_path_namespaceObject.join("D:", ".opam", "download-cache"); paths.push(opamDownloadCachePath); } @@ -85688,12 +85679,7 @@ async function saveOpamDownloadCache() { const { repo: { owner, repo }, runId: run_id, } = lib_github.context; async function installDune() { await core.group("Install dune", async () => { - if (OPAM_DEPEXT) { - await exec("opam", ["depext", "--install", "dune"]); - } - else { - await exec("opam", ["install", "dune"]); - } + await exec("opam", ["install", "dune"]); }); } async function trimDuneCache() { @@ -85711,8 +85697,7 @@ async function trimDuneCache() { "dune", "cache", "trim", - "--size", - `${cacheSize}MB`, + `--size=${cacheSize}MB`, ]); }); } diff --git a/lint-doc/dist/index.js b/lint-doc/dist/index.js index 400a473d..9ce0ec64 100644 --- a/lint-doc/dist/index.js +++ b/lint-doc/dist/index.js @@ -27919,14 +27919,13 @@ var exec = __nccwpck_require__(6473); ;// CONCATENATED MODULE: ./src/odoc.ts async function lintOdoc() { - const options = { + const exitCode = await (0,exec.exec)("opam", ["exec", "--", "dune", "build", "@doc"], { env: { ...process.env, PATH: process.env["PATH"] ?? "", ODOC_WARN_ERROR: "true", }, - }; - const exitCode = await (0,exec.exec)("opam", ["exec", "--", "dune", "build", "@doc"], options); + }); if (exitCode !== 0) { throw new Error("dune build @doc failed"); } @@ -27937,18 +27936,12 @@ async function lintOdoc() { async function installOpamPackages() { await core.group("Install opam packages", async () => { - await (0,exec.exec)("opam", ["install", ".", "--deps-only", "--with-doc"]); + await (0,exec.exec)("opam", ["install", "--deps-only", "--with-doc", "."]); }); } async function installOdoc() { await core.group("Install odoc", async () => { - await (0,exec.exec)("opam", [ - "depext", - "--install", - "conf-m4", - "dune", - "odoc>=1.5.0", - ]); + await (0,exec.exec)("opam", ["install", "conf-m4", "dune", "odoc>=1.5.0"]); }); } diff --git a/lint-opam/dist/index.js b/lint-opam/dist/index.js index 5c3c23fd..dbb4929b 100644 --- a/lint-opam/dist/index.js +++ b/lint-opam/dist/index.js @@ -27932,10 +27932,10 @@ async function installOpamPackages() { await core.group("Install opam packages", async () => { await (0,exec.exec)("opam", [ "install", - ".", "--deps-only", - "--with-test", "--with-doc", + "--with-test", + ".", ]); }); } diff --git a/packages/analysis/src/analysis.ts b/packages/analysis/src/analysis.ts index 7c061eb0..a53af536 100644 --- a/packages/analysis/src/analysis.ts +++ b/packages/analysis/src/analysis.ts @@ -35,12 +35,12 @@ export async function analysis() { "opam", [ "tree", - name, + `--json=${tempJson}`, "--with-dev-setup", // [NOTE] https://github.com/ocaml/opam/issues/4541 // "--with-doc", "--with-test", - `--json=${tempJson}`, + name, ], { env: { diff --git a/packages/analysis/src/opam.ts b/packages/analysis/src/opam.ts index d9d99729..1847b994 100644 --- a/packages/analysis/src/opam.ts +++ b/packages/analysis/src/opam.ts @@ -5,12 +5,12 @@ export async function installOpamPackages() { await core.group("Install opam packages", async () => { await exec("opam", [ "install", - ".", "--deps-only", "--with-dev-setup", // [NOTE] https://github.com/ocaml/opam/issues/4541 // "--with-doc", "--with-test", + ".", ]); }); } diff --git a/packages/lint-doc/src/odoc.ts b/packages/lint-doc/src/odoc.ts index 511b05c7..671d0915 100644 --- a/packages/lint-doc/src/odoc.ts +++ b/packages/lint-doc/src/odoc.ts @@ -1,19 +1,13 @@ -import type { ExecOptions } from "@actions/exec"; import { exec } from "@actions/exec"; export async function lintOdoc() { - const options: ExecOptions = { + const exitCode = await exec("opam", ["exec", "--", "dune", "build", "@doc"], { env: { ...process.env, PATH: process.env["PATH"] ?? "", ODOC_WARN_ERROR: "true", }, - }; - const exitCode = await exec( - "opam", - ["exec", "--", "dune", "build", "@doc"], - options, - ); + }); if (exitCode !== 0) { throw new Error("dune build @doc failed"); } diff --git a/packages/lint-doc/src/opam.ts b/packages/lint-doc/src/opam.ts index 63b9c447..14730710 100644 --- a/packages/lint-doc/src/opam.ts +++ b/packages/lint-doc/src/opam.ts @@ -3,18 +3,12 @@ import { exec } from "@actions/exec"; export async function installOpamPackages() { await core.group("Install opam packages", async () => { - await exec("opam", ["install", ".", "--deps-only", "--with-doc"]); + await exec("opam", ["install", "--deps-only", "--with-doc", "."]); }); } export async function installOdoc() { await core.group("Install odoc", async () => { - await exec("opam", [ - "depext", - "--install", - "conf-m4", - "dune", - "odoc>=1.5.0", - ]); + await exec("opam", ["install", "conf-m4", "dune", "odoc>=1.5.0"]); }); } diff --git a/packages/lint-opam/src/opam.ts b/packages/lint-opam/src/opam.ts index 9ccca264..513598c6 100644 --- a/packages/lint-opam/src/opam.ts +++ b/packages/lint-opam/src/opam.ts @@ -5,10 +5,10 @@ export async function installOpamPackages() { await core.group("Install opam packages", async () => { await exec("opam", [ "install", - ".", "--deps-only", - "--with-test", "--with-doc", + "--with-test", + ".", ]); }); } diff --git a/packages/setup-ocaml/src/cache.ts b/packages/setup-ocaml/src/cache.ts index fcb01125..7bbfa61a 100644 --- a/packages/setup-ocaml/src/cache.ts +++ b/packages/setup-ocaml/src/cache.ts @@ -11,6 +11,7 @@ import * as datefns from "date-fns"; import { ARCHITECTURE, CACHE_PREFIX, + CYGWIN_MIRROR, OCAML_COMPILER, OPAM_DISABLE_SANDBOXING, OPAM_REPOSITORIES, @@ -19,7 +20,7 @@ import { import { getLatestOpamRelease } from "./opam.js"; import { getSystemIdentificationInfo } from "./system.js"; import { resolveCompiler } from "./version.js"; -import { getCygwinVersion } from "./win32.js"; +import { getCygwinVersion } from "./windows.js"; function composeDate() { const d = new Date(); @@ -62,11 +63,10 @@ function composeDuneCacheKeys() { async function composeOpamCacheKeys() { const fullPlatform = - PLATFORM === "win32" + PLATFORM === "windows" ? PLATFORM : `${PLATFORM}-${(await getSystemIdentificationInfo()).version}`; - const opamVersion = - PLATFORM === "win32" ? "0.0.0.2" : (await getLatestOpamRelease()).version; + const opamVersion = (await getLatestOpamRelease()).version; const ocamlCompiler = await resolveCompiler(OCAML_COMPILER); const ocamlVersion = ocamlCompiler.toLowerCase().replaceAll(/\W/g, "_"); const sandboxed = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox"; @@ -110,9 +110,7 @@ function composeCygwinCachePaths() { paths.push(cygwinRoot); const cygwinRootSymlinkPath = path.posix.join("/cygdrive", "d", "cygwin"); paths.push(cygwinRootSymlinkPath); - const cygwinEncodedUri = encodeURIComponent( - "https://mirrors.kernel.org/sourceware/cygwin/", - ).toLowerCase(); + const cygwinEncodedUri = encodeURIComponent(CYGWIN_MIRROR).toLowerCase(); const cygwinPackageRoot = path.join(githubWorkspace, cygwinEncodedUri); paths.push(cygwinPackageRoot); return paths; @@ -121,7 +119,7 @@ function composeCygwinCachePaths() { function composeDuneCachePaths() { const paths = []; const homeDir = os.homedir(); - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const duneCacheDir = path.join(homeDir, "Local Settings", "Cache", "dune"); paths.push(duneCacheDir); } else { @@ -136,7 +134,7 @@ function composeDuneCachePaths() { function composeOpamCachePaths() { const paths = []; - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const opamRootCachePath = path.join("D:", ".opam"); paths.push(opamRootCachePath); const { @@ -164,7 +162,7 @@ function composeOpamCachePaths() { function composeOpamDownloadCachePaths() { const paths = []; - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { 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 1876da7d..791bb4cc 100644 --- a/packages/setup-ocaml/src/constants.ts +++ b/packages/setup-ocaml/src/constants.ts @@ -27,7 +27,7 @@ export const PLATFORM = (() => { return "macos"; } case "win32": { - return "win32"; + return "windows"; } default: { throw new Error("The platform is not supported."); @@ -35,19 +35,17 @@ export const PLATFORM = (() => { } })(); -export const CYGWIN_ROOT = path.join("D:", "cygwin"); - -export const CYGWIN_ROOT_BIN = path.join(CYGWIN_ROOT, "bin"); +export const CYGWIN_MIRROR = "https://cygwin.mirror.constant.com/"; -export const CYGWIN_ROOT_WRAPPERBIN = path.join(CYGWIN_ROOT, "wrapperbin"); +export const CYGWIN_ROOT = path.join("D:", "cygwin"); -// [todo] remove the branch for Windows once opam 2.2 is released as stable. -export const ALLOW_PRERELEASE_OPAM = - PLATFORM !== "win32" && - core.getBooleanInput("allow-prerelease-opam", { +export const ALLOW_PRERELEASE_OPAM = core.getBooleanInput( + "allow-prerelease-opam", + { required: false, trimWhitespace: true, - }); + }, +); export const CACHE_PREFIX = core.getInput("cache-prefix", { required: false, @@ -69,24 +67,14 @@ export const OCAML_COMPILER = core.getInput("ocaml-compiler", { trimWhitespace: true, }); -// [todo] remove this once opam 2.2 is released as stable. -export const OPAM_DEPEXT = - !ALLOW_PRERELEASE_OPAM && - core.getBooleanInput("opam-depext", { - required: false, - trimWhitespace: true, - }); - -export const OPAM_DEPEXT_FLAGS = core - .getInput("opam-depext-flags", { required: false, trimWhitespace: true }) - .split(",") - .map((f) => f.trim()) - .filter((f) => f.length > 0); - -export const OPAM_DISABLE_SANDBOXING = core.getBooleanInput( - "opam-disable-sandboxing", - { required: false, trimWhitespace: true }, -); +export const OPAM_DISABLE_SANDBOXING = + // [TODO] unlock this once sandboxing is supported on Windows + PLATFORM === "windows" + ? true + : core.getBooleanInput("opam-disable-sandboxing", { + required: false, + trimWhitespace: true, + }); export const OPAM_LOCAL_PACKAGES = core.getInput("opam-local-packages", { required: false, @@ -102,11 +90,6 @@ const repositories_yaml = yaml.parse( core.getInput("opam-repositories", { required: false, trimWhitespace: true }), ) as Record | null; -const defaultRepository = - PLATFORM === "win32" - ? "https://github.com/ocaml-opam/opam-repository-mingw.git#sunset" - : "https://github.com/ocaml/opam-repository.git"; - export const OPAM_REPOSITORIES: [string, string][] = repositories_yaml ? Object.entries(repositories_yaml).reverse() - : [["default", defaultRepository]]; + : [["default", "https://github.com/ocaml/opam-repository.git"]]; diff --git a/packages/setup-ocaml/src/depext.ts b/packages/setup-ocaml/src/depext.ts deleted file mode 100644 index d92b4b0b..00000000 --- a/packages/setup-ocaml/src/depext.ts +++ /dev/null @@ -1,35 +0,0 @@ -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"; - -export async function installDepext(ocamlVersion: string) { - await core.group("Install depext", async () => { - const depextCygwinports = - PLATFORM === "win32" ? ["depext-cygwinports"] : []; - await exec("opam", ["install", "opam-depext", ...depextCygwinports]); - if (PLATFORM === "win32") { - let base = ""; - if (ocamlVersion.includes("mingw64")) { - base = "x86_64-w64-mingw32"; - } else if (ocamlVersion.includes("mingw32")) { - base = "i686-w64-mingw32"; - } - core.addPath( - path.posix.join("/", "usr", base, "sys-root", "mingw", "bin"), - ); - } - }); -} - -export async function installDepextPackages(fpaths: string[]) { - await core.group( - "Install system packages required by opam packages", - async () => { - const fnames = fpaths.map((fpath) => path.basename(fpath, ".opam")); - await exec("opam", ["depext", ...fnames, ...OPAM_DEPEXT_FLAGS]); - }, - ); -} diff --git a/packages/setup-ocaml/src/dune.ts b/packages/setup-ocaml/src/dune.ts index 272903cf..e66db7d9 100644 --- a/packages/setup-ocaml/src/dune.ts +++ b/packages/setup-ocaml/src/dune.ts @@ -2,7 +2,7 @@ import * as core from "@actions/core"; import { exec } from "@actions/exec"; import * as github from "@actions/github"; -import { GITHUB_TOKEN, OPAM_DEPEXT } from "./constants.js"; +import { GITHUB_TOKEN } from "./constants.js"; const { repo: { owner, repo }, @@ -11,11 +11,7 @@ const { export async function installDune() { await core.group("Install dune", async () => { - if (OPAM_DEPEXT) { - await exec("opam", ["depext", "--install", "dune"]); - } else { - await exec("opam", ["install", "dune"]); - } + await exec("opam", ["install", "dune"]); }); } @@ -38,8 +34,7 @@ export async function trimDuneCache() { "dune", "cache", "trim", - "--size", - `${cacheSize}MB`, + `--size=${cacheSize}MB`, ]); }, ); diff --git a/packages/setup-ocaml/src/installer.ts b/packages/setup-ocaml/src/installer.ts index 68ef64c1..a47d834b 100644 --- a/packages/setup-ocaml/src/installer.ts +++ b/packages/setup-ocaml/src/installer.ts @@ -13,15 +13,12 @@ import { saveOpamCache, } from "./cache.js"; import { - ALLOW_PRERELEASE_OPAM, DUNE_CACHE, OCAML_COMPILER, - OPAM_DEPEXT, OPAM_PIN, OPAM_REPOSITORIES, PLATFORM, } from "./constants.js"; -import { installDepext, installDepextPackages } from "./depext.js"; import { installDune } from "./dune.js"; import { installOcaml, @@ -31,33 +28,23 @@ import { setupOpam, } from "./opam.js"; import { getOpamLocalPackages } from "./packages.js"; -import { updateUnixPackageIndexFiles } from "./system.js"; import { resolveCompiler } from "./version.js"; export async function installer() { if (core.isDebug()) { core.exportVariable("OPAMVERBOSE", 1); } - if (ALLOW_PRERELEASE_OPAM) { - core.exportVariable("OPAMCONFIRMLEVEL", "unsafe-yes"); - } else { - // [todo] remove this once opam 2.2 is released as stable. - // https://github.com/ocaml/setup-ocaml/issues/299 - core.exportVariable("OPAMCLI", "2.0"); - } core.exportVariable("OPAMCOLOR", "always"); + core.exportVariable("OPAMCONFIRMLEVEL", "unsafe-yes"); core.exportVariable("OPAMERRLOGLEN", 0); core.exportVariable("OPAMJOBS", os.cpus().length); core.exportVariable("OPAMPRECISETRACKING", 1); - // [todo] remove this once opam 2.2 is released as stable. - // https://github.com/ocaml/opam/issues/3447 - core.exportVariable("OPAMSOLVERTIMEOUT", 1000); core.exportVariable("OPAMYES", 1); - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { const opamRoot = path.join("D:", ".opam"); core.exportVariable("OPAMROOT", opamRoot); } - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { 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 @@ -71,11 +58,11 @@ export async function installer() { await exec("fsutil", ["behavior", "query", "SymlinkEvaluation"]); }); } - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { core.exportVariable("HOME", process.env["USERPROFILE"]); core.exportVariable("MSYS", "winsymlinks:native"); } - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { await restoreCygwinCache(); } const opamCacheHit = await restoreOpamCache(); @@ -88,9 +75,6 @@ export async function installer() { await saveOpamCache(); } await restoreOpamDownloadCache(); - if (OPAM_DEPEXT) { - await installDepext(ocamlCompiler); - } if (DUNE_CACHE) { await restoreDuneCache(); await installDune(); @@ -104,23 +88,7 @@ export async function installer() { if (OPAM_PIN) { await pin(fnames); } - if (OPAM_DEPEXT) { - try { - await installDepextPackages(fnames); - } catch (error) { - if (error instanceof Error) { - core.notice( - `An error has been caught in some system package index files, so the system package index files have been re-synchronised, and the system package installation has been retried: ${error.message.toLocaleLowerCase()}`, - ); - } - await updateUnixPackageIndexFiles(); - await installDepextPackages(fnames); - } - } } await exec("opam", ["--version"]); - if (OPAM_DEPEXT) { - await exec("opam", ["depext", "--version"]); - } await exec("opam", ["exec", "--", "ocaml", "-version"]); } diff --git a/packages/setup-ocaml/src/opam.ts b/packages/setup-ocaml/src/opam.ts index a1f33bde..472f64e9 100644 --- a/packages/setup-ocaml/src/opam.ts +++ b/packages/setup-ocaml/src/opam.ts @@ -1,5 +1,4 @@ import { promises as fs } from "node:fs"; -import * as os from "node:os"; import * as path from "node:path"; import * as process from "node:process"; @@ -14,9 +13,8 @@ import { saveCygwinCache } from "./cache.js"; import { ALLOW_PRERELEASE_OPAM, ARCHITECTURE, + CYGWIN_MIRROR, CYGWIN_ROOT, - CYGWIN_ROOT_BIN, - CYGWIN_ROOT_WRAPPERBIN, GITHUB_TOKEN, OPAM_DISABLE_SANDBOXING, PLATFORM, @@ -25,10 +23,10 @@ import { getSystemIdentificationInfo, updateUnixPackageIndexFiles, } from "./system.js"; -import { getCygwinVersion } from "./win32.js"; +import { getCygwinVersion } from "./windows.js"; export async function getLatestOpamRelease() { - const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.2.0"; + const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.3.0"; const octokit = github.getOctokit(GITHUB_TOKEN); const { data: releases } = await octokit.rest.repos.listReleases({ owner: "ocaml", @@ -64,30 +62,22 @@ export async function getLatestOpamRelease() { }; } -async function findOpam() { - if (PLATFORM === "win32") { - const opamPath = path.join(CYGWIN_ROOT, "bin", "opam.exe"); - return opamPath; - } - const opamPath = await io.which("opam"); - return opamPath; -} - -async function acquireOpamUnix() { +async function acquireOpam() { const { version, browserDownloadUrl } = await getLatestOpamRelease(); const cachedPath = toolCache.find("opam", version, ARCHITECTURE); + const opam = PLATFORM !== "windows" ? "opam" : "opam.exe"; if (cachedPath === "") { const downloadedPath = await toolCache.downloadTool(browserDownloadUrl); core.info(`Acquired ${version} from ${browserDownloadUrl}`); const cachedPath = await toolCache.cacheFile( downloadedPath, - "opam", + opam, "opam", version, ARCHITECTURE, ); core.info(`Successfully cached opam to ${cachedPath}`); - await fs.chmod(`${cachedPath}/opam`, 0o755); + await fs.chmod(path.join(cachedPath, opam), 0o755); core.addPath(cachedPath); core.info("Added opam to the path"); } else { @@ -102,7 +92,7 @@ async function installUnixSystemPackages() { if (PLATFORM === "linux") { const { version: systemVersion } = await getSystemIdentificationInfo(); if (systemVersion === "18.04") { - // [info]: musl-tools bug in ubuntu 18.04; + // [INFO]: musl-tools bug in ubuntu 18.04; // await exec("sudo", ["add-apt-repository", "ppa:avsm/musl"]); } @@ -151,7 +141,7 @@ async function initializeOpamUnix() { async function setupOpamUnix() { await core.group("Install opam", async () => { - await acquireOpamUnix(); + await acquireOpam(); }); await core.group("Initialise the opam state", async () => { await initializeOpamUnix(); @@ -176,7 +166,6 @@ async function setupCygwin() { } else { core.addPath(cachedPath); } - const site = "https://mirrors.kernel.org/sourceware/cygwin"; const packages = [ "curl", "diffutils", @@ -191,87 +180,49 @@ async function setupCygwin() { "rsync", "unzip", ].join(","); - await exec("setup-x86_64.exe", [ + await exec("setup-x86_64", [ + `--packages=${packages}`, "--quiet-mode", - "--root", - CYGWIN_ROOT, - "--site", - site, - "--packages", - packages, + `--root=${CYGWIN_ROOT}`, + `--site=${CYGWIN_MIRROR}`, "--symlink-type=sys", ]); - const setupExePath = await io.which("setup-x86_64.exe"); - await io.cp(setupExePath, CYGWIN_ROOT); -} - -async function acquireOpamWindows() { - const opamVersion = "0.0.0.2"; - const cachedPath = toolCache.find("opam", opamVersion); - if (cachedPath === "") { - const downloadedPath = await toolCache.downloadTool( - `https://github.com/fdopen/opam-repository-mingw/releases/download/${opamVersion}/opam64.zip`, - ); - const extractedPath = await toolCache.extractZip(downloadedPath); - const cachedPath = await toolCache.cacheDir( - extractedPath, - "opam", - opamVersion, - ); - const installSh = path.join(cachedPath, "opam64", "install.sh"); - await fs.chmod(installSh, 0o755); - await exec("bash", [installSh, "--prefix", "/usr"]); - } else { - const installSh = path.join(cachedPath, "opam64", "install.sh"); - await fs.chmod(installSh, 0o755); - await exec("bash", [installSh, "--prefix", "/usr"]); - } + const setup = await io.which("setup-x86_64"); + await io.cp(setup, CYGWIN_ROOT); } async function initializeOpamWindows() { - await exec("git", ["config", "--global", "--add", "safe.directory", "'*'"]); + const disableSandboxing = []; + if (OPAM_DISABLE_SANDBOXING) { + disableSandboxing.push("--disable-sandboxing"); + } await exec("opam", [ "init", "--auto-setup", "--bare", - "--disable-sandboxing", + "--cygwin-local-install", + `--cygwin-location=${CYGWIN_ROOT}`, + ...disableSandboxing, "--enable-shell-hook", ]); - await io.mkdirP(CYGWIN_ROOT_WRAPPERBIN); - const opamCmd = path.join(CYGWIN_ROOT_WRAPPERBIN, "opam.cmd"); - const data = [ - "@setlocal", - "@echo off", - "set PATH=%CYGWIN_ROOT_BIN%;%PATH%", - "ocaml-env exec -- opam.exe %*", - ].join(os.EOL); - await fs.writeFile(opamCmd, data, { mode: 0o755 }); } async function setupOpamWindows() { await core.group("Prepare the Cygwin environment", async () => { core.exportVariable("CYGWIN", "winsymlinks:native"); - core.exportVariable("CYGWIN_ROOT", CYGWIN_ROOT); - core.exportVariable("CYGWIN_ROOT_BIN", CYGWIN_ROOT_BIN); - core.exportVariable("CYGWIN_ROOT_WRAPPERBIN", CYGWIN_ROOT_WRAPPERBIN); - core.addPath(CYGWIN_ROOT_WRAPPERBIN); await setupCygwin(); }); await saveCygwinCache(); - const originalPath = process.env["PATH"]?.split(path.delimiter) ?? []; - const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; - process.env["PATH"] = patchedPath.join(path.delimiter); await core.group("Install opam", async () => { - await acquireOpamWindows(); + await acquireOpam(); }); await core.group("Initialise the opam state", async () => { await initializeOpamWindows(); }); - process.env["PATH"] = originalPath.join(path.delimiter); } export async function setupOpam() { - if (PLATFORM === "win32") { + if (PLATFORM === "windows") { await setupOpamWindows(); } else { await setupOpamUnix(); @@ -280,39 +231,23 @@ export async function setupOpam() { export async function installOcaml(ocamlCompiler: string) { await core.group("Install OCaml", async () => { - if (PLATFORM === "win32") { - const originalPath = process.env["PATH"]?.split(path.delimiter) ?? []; - const patchedPath = [CYGWIN_ROOT_BIN, ...originalPath]; - process.env["PATH"] = patchedPath.join(path.delimiter); - await exec("opam", [ - "switch", - "create", - ".", - "--no-install", - "--packages", - ocamlCompiler, - ]); - process.env["PATH"] = originalPath.join(path.delimiter); - } else { - await exec("opam", [ - "switch", - "create", - ".", - "--no-install", - "--packages", - ocamlCompiler, - ]); - } + await exec("opam", [ + "switch", + "--no-install", + "--packages", + "create", + ".", + ocamlCompiler, + ]); }); } export async function pin(fpaths: string[]) { await core.group("Pin local packages", async () => { - const opam = await findOpam(); for (const fpath of fpaths) { const fname = path.basename(fpath, ".opam"); const dname = path.dirname(fpath); - await exec(opam, ["pin", "add", `${fname}.dev`, ".", "--no-action"], { + await exec("opam", ["pin", "--no-action", "add", `${fname}.dev`, "."], { cwd: dname, }); } @@ -320,65 +255,33 @@ export async function pin(fpaths: string[]) { } async function repositoryAdd(name: string, address: string) { - const opam = await findOpam(); - await exec(opam, [ + await exec("opam", [ "repository", + "--all-switches", + "--set-default", "add", name, address, - "--all-switches", - "--set-default", ]); } export async function repositoryAddAll(repositories: [string, string][]) { await core.group("Initialise the opam repositories", async () => { - let restore_autocrlf: string | null | undefined = undefined; - // 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 === "win32") { - const autocrlf = await getExecOutput( - "git", - ["config", "--global", "core.autocrlf"], - { ignoreReturnCode: true }, - ); - if (autocrlf.stdout.trim() !== "input") { - if (autocrlf.exitCode === 0) { - restore_autocrlf = autocrlf.stdout.trim(); - } else { - restore_autocrlf = null; // Unset the value at the end - } - } - await exec("git", ["config", "--global", "core.autocrlf", "input"]); - } for (const [name, address] of repositories) { await repositoryAdd(name, address); } - if (restore_autocrlf === null) { - await exec("git", ["config", "--global", "--unset", "core.autocrlf"]); - } else if (restore_autocrlf !== undefined) { - await exec("git", [ - "config", - "--global", - "core.autocrlf", - restore_autocrlf, - ]); - } }); } async function repositoryRemove(name: string) { - const opam = await findOpam(); - await exec(opam, ["repository", "remove", name, "--all-switches"]); + await exec("opam", ["repository", "--all-switches", "remove", name]); } async function repositoryList() { - const opam = await findOpam(); const repositoryList = await getExecOutput( - opam, - ["repository", "list", "--all-switches", "--short"], - { ignoreReturnCode: true }, + "opam", + ["repository", "--all-switches", "--short", "list"], + { ignoreReturnCode: true, silent: true }, ); if (repositoryList.exitCode === 0) { return repositoryList.stdout diff --git a/packages/setup-ocaml/src/system.ts b/packages/setup-ocaml/src/system.ts index 9f38dc3f..df08f344 100644 --- a/packages/setup-ocaml/src/system.ts +++ b/packages/setup-ocaml/src/system.ts @@ -22,7 +22,7 @@ export async function getSystemIdentificationInfo() { return { id, version }; } if (PLATFORM === "macos") { - const swVers = await getExecOutput("sw_vers"); + const swVers = await getExecOutput("sw_vers", [], { silent: true }); const lines = swVers.stdout.split(os.EOL); let version = ""; for (const line of lines) { diff --git a/packages/setup-ocaml/src/version.ts b/packages/setup-ocaml/src/version.ts index 5be82618..2b45f70c 100644 --- a/packages/setup-ocaml/src/version.ts +++ b/packages/setup-ocaml/src/version.ts @@ -3,35 +3,24 @@ 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 { GITHUB_TOKEN } from "./constants.js"; function isSemverValidRange(semverVersion: string) { - const isValidSemver = - semver.validRange(semverVersion, { loose: true }) !== null; - // [NOTE] explicitly deny compilers like "4.14.0+mingw64c" as invalid semver - // syntax even though it's valid... - const plus = !semverVersion.includes("+"); - return isValidSemver && plus; + return semver.validRange(semverVersion, { loose: true }) !== null; } async function getAllCompilerVersions() { const octokit = github.getOctokit(GITHUB_TOKEN); - - 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, - path: `packages/${prefix}`, + 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 = path.basename(p); - const version = basename.replace(`${prefix}.`, ""); + const version = basename.replace("ocaml-base-compiler.", ""); const parsed = semver.parse(version, { loose: true }); if (parsed !== null) { const { major, minor: _minor, patch } = parsed; @@ -61,9 +50,7 @@ async function resolveVersion(semverVersion: string) { export async function resolveCompiler(compiler: string) { const resolvedCompiler = isSemverValidRange(compiler) - ? PLATFORM === "win32" - ? `ocaml-variants.${await resolveVersion(compiler)}+mingw64c` - : `ocaml-base-compiler.${await resolveVersion(compiler)}` + ? `ocaml-base-compiler.${await resolveVersion(compiler)}` : compiler; return resolvedCompiler; } diff --git a/packages/setup-ocaml/src/win32.ts b/packages/setup-ocaml/src/windows.ts similarity index 100% rename from packages/setup-ocaml/src/win32.ts rename to packages/setup-ocaml/src/windows.ts