diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b77943c..dab1a43c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to - Don't install Cygwin's git or mercurial packages (reduces cache by ~90MB) +### Fixed + +- Ensure ocaml/opam-repository can be added without getting hash errors. + ## [2.0.10] ### Fixed diff --git a/dist/index.js b/dist/index.js index 0e7c1a6d..a55d2d77 100644 --- a/dist/index.js +++ b/dist/index.js @@ -126798,10 +126798,38 @@ async function repositoryAdd(name, address) { ]); } async function repositoryAddAll(repositories) { + const platform = getPlatform(); + let restore_autocrlf; lib_core.startGroup("Initialise the opam repositories"); + // 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" /* Platform.Win32 */) { + const autocrlf = await (0,lib_exec.getExecOutput)("git", ["config", "--global", "core.autocrlf"], { ignoreReturnCode: true }); + if (autocrlf.stdout !== "input") { + if (autocrlf.exitCode !== 0) { + restore_autocrlf = null; // Unset the value at the end + } + else { + restore_autocrlf = autocrlf.stdout; + } + } + 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, + ]); + } lib_core.endGroup(); } async function repositoryRemove(name) { diff --git a/src/setup-ocaml/opam.ts b/src/setup-ocaml/opam.ts index c561f06d..85f771ef 100644 --- a/src/setup-ocaml/opam.ts +++ b/src/setup-ocaml/opam.ts @@ -4,7 +4,7 @@ import * as path from "node:path"; import * as process from "node:process"; import * as core from "@actions/core"; -import { exec } from "@actions/exec"; +import { exec, getExecOutput } from "@actions/exec"; import * as github from "@actions/github"; import * as io from "@actions/io"; import * as tc from "@actions/tool-cache"; @@ -334,10 +334,40 @@ async function repositoryAdd(name: string, address: string) { export async function repositoryAddAll( repositories: [string, string][] ): Promise { + const platform = getPlatform(); + let restore_autocrlf; core.startGroup("Initialise the opam repositories"); + // 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) { + const autocrlf = await getExecOutput( + "git", + ["config", "--global", "core.autocrlf"], + { ignoreReturnCode: true } + ); + if (autocrlf.stdout !== "input") { + if (autocrlf.exitCode !== 0) { + restore_autocrlf = null; // Unset the value at the end + } else { + restore_autocrlf = autocrlf.stdout; + } + } + 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, + ]); + } core.endGroup(); }