From 4470014c495e61ebc73ebc8cd4c1c77a624172cd Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Tue, 24 Dec 2024 14:25:30 +0900 Subject: [PATCH] Revert "Run `opam update --depext` before installing system dependencies" --- dist/index.js | 23 +++++++++++++++++++++-- packages/setup-ocaml/src/opam.ts | 18 +++++++++++++++--- packages/setup-ocaml/src/unix.ts | 11 +++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index e8ef8e58..62746316 100644 --- a/dist/index.js +++ b/dist/index.js @@ -148557,6 +148557,17 @@ async function installUnixSystemPackages() { } } } +async function updateUnixPackageIndexFiles() { + const isGitHubRunner = external_node_process_.env.GITHUB_ACTIONS === "true"; + 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"]); + } + } +} ;// CONCATENATED MODULE: ./src/opam.ts @@ -148621,9 +148632,17 @@ async function acquireOpam() { } async function initializeOpam() { await lib_core.group("Initialise opam state", async () => { - await (0,lib_exec.exec)("opam", ["update", "--depexts"]); if (PLATFORM !== "windows") { - await installUnixSystemPackages(); + try { + await installUnixSystemPackages(); + } + 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 installUnixSystemPackages(); + } } const extraOptions = []; if (PLATFORM === "windows") { diff --git a/packages/setup-ocaml/src/opam.ts b/packages/setup-ocaml/src/opam.ts index a3c00199..1a215271 100644 --- a/packages/setup-ocaml/src/opam.ts +++ b/packages/setup-ocaml/src/opam.ts @@ -13,7 +13,10 @@ import { OPAM_DISABLE_SANDBOXING, PLATFORM, } from "./constants.js"; -import { installUnixSystemPackages } from "./unix.js"; +import { + installUnixSystemPackages, + updateUnixPackageIndexFiles, +} from "./unix.js"; export async function retrieveLatestOpamRelease() { const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.4.0"; @@ -85,9 +88,18 @@ async function acquireOpam() { async function initializeOpam() { await core.group("Initialise opam state", async () => { - await exec("opam", ["update", "--depexts"]); if (PLATFORM !== "windows") { - await installUnixSystemPackages(); + try { + await installUnixSystemPackages(); + } 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 installUnixSystemPackages(); + } } const extraOptions = []; if (PLATFORM === "windows") { diff --git a/packages/setup-ocaml/src/unix.ts b/packages/setup-ocaml/src/unix.ts index 74162925..abb58704 100644 --- a/packages/setup-ocaml/src/unix.ts +++ b/packages/setup-ocaml/src/unix.ts @@ -56,3 +56,14 @@ export async function installUnixSystemPackages() { } } } + +export async function updateUnixPackageIndexFiles() { + const isGitHubRunner = process.env.GITHUB_ACTIONS === "true"; + if (isGitHubRunner) { + if (PLATFORM === "linux") { + await exec("sudo", ["apt-get", "update"]); + } else if (PLATFORM === "macos") { + await exec("brew", ["update"]); + } + } +}