From f2f1fb2a14599c6405308254c7064e217bbebf57 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Wed, 26 Mar 2025 02:54:06 +0900 Subject: [PATCH 1/2] Add `RUNNER_ENVIRONMENT` constant Signed-off-by: Sora Morimoto --- packages/setup-ocaml/src/constants.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/setup-ocaml/src/constants.ts b/packages/setup-ocaml/src/constants.ts index 84ba56fb..8fd6f8e0 100644 --- a/packages/setup-ocaml/src/constants.ts +++ b/packages/setup-ocaml/src/constants.ts @@ -87,6 +87,10 @@ export const OPAM_ROOT = (() => { return path.join(os.homedir(), ".opam"); })(); +export const RUNNER_ENVIRONMENT = process.env.RUNNER_ENVIRONMENT as + | "github-hosted" + | "self-hosted"; + export const ALLOW_PRERELEASE_OPAM = core.getBooleanInput( "allow-prerelease-opam", ); From 60cd58a3cb5a2c37285f60eacfa5124d60ab89cb Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Wed, 26 Mar 2025 12:04:45 +0900 Subject: [PATCH 2/2] Fix package installation logic for the self-hosted runner environment Signed-off-by: Sora Morimoto --- dist/index.js | 48 ++++++++++++++++++--------- dist/post/index.js | 11 ++++++ packages/setup-ocaml/src/constants.ts | 17 ++++++++-- packages/setup-ocaml/src/unix.ts | 42 ++++++++++++++--------- 4 files changed, 84 insertions(+), 34 deletions(-) diff --git a/dist/index.js b/dist/index.js index f7a4b2f5..365c98c2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -146994,6 +146994,17 @@ const OPAM_ROOT = (() => { } return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".opam"); })(); +const RUNNER_ENVIRONMENT = (() => { + const ImageOS = external_node_process_.env.ImageOS; + const RUNNER_ENVIRONMENT = external_node_process_.env.RUNNER_ENVIRONMENT; + if (ImageOS) { + return "github-hosted"; + } + if (!RUNNER_ENVIRONMENT) { + return "self-hosted"; + } + return RUNNER_ENVIRONMENT; +})(); const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam"); const CACHE_PREFIX = lib_core.getInput("cache-prefix"); const constants_GITHUB_TOKEN = lib_core.getInput("github-token"); @@ -147141,7 +147152,6 @@ var semver = __nccwpck_require__(90084); ;// CONCATENATED MODULE: ./src/unix.ts - async function checkAptInstallability(packageName) { const output = await (0,lib_exec.getExecOutput)("sudo", [ "apt-cache", @@ -147169,15 +147179,17 @@ async function retrieveInstallableOptionalDependencies(optionalDependencies) { } } async function installUnixSystemPackages() { - const isGitHubRunner = external_node_process_.env.GITHUB_ACTIONS === "true"; - const optionalDependencies = await retrieveInstallableOptionalDependencies([ - "darcs", - "g++-multilib", - "gcc-multilib", - "mercurial", - ]); - if (isGitHubRunner) { - if (PLATFORM === "linux") { + if (RUNNER_ENVIRONMENT === "self-hosted") { + return; + } + switch (PLATFORM) { + case "linux": { + const optionalDependencies = await retrieveInstallableOptionalDependencies([ + "darcs", + "g++-multilib", + "gcc-multilib", + "mercurial", + ]); await (0,lib_exec.exec)("sudo", [ "apt-get", "--yes", @@ -147187,20 +147199,26 @@ async function installUnixSystemPackages() { "rsync", ...optionalDependencies, ]); + break; } - else if (PLATFORM === "macos") { + case "macos": { await (0,lib_exec.exec)("brew", ["install", "darcs", "gpatch", "mercurial"]); + break; } } } async function updateUnixPackageIndexFiles() { - const isGitHubRunner = external_node_process_.env.GITHUB_ACTIONS === "true"; - if (isGitHubRunner) { - if (PLATFORM === "linux") { + if (RUNNER_ENVIRONMENT === "self-hosted") { + return; + } + switch (PLATFORM) { + case "linux": { await (0,lib_exec.exec)("sudo", ["apt-get", "update"]); + break; } - else if (PLATFORM === "macos") { + case "macos": { await (0,lib_exec.exec)("brew", ["update"]); + break; } } } diff --git a/dist/post/index.js b/dist/post/index.js index e0f35c83..c808988a 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -111634,6 +111634,17 @@ const constants_OPAM_ROOT = (() => { } return external_node_path_namespaceObject.join(external_node_os_.homedir(), ".opam"); })(); +const RUNNER_ENVIRONMENT = (() => { + const ImageOS = external_node_process_.env.ImageOS; + const RUNNER_ENVIRONMENT = external_node_process_.env.RUNNER_ENVIRONMENT; + if (ImageOS) { + return "github-hosted"; + } + if (!RUNNER_ENVIRONMENT) { + return "self-hosted"; + } + return RUNNER_ENVIRONMENT; +})(); const ALLOW_PRERELEASE_OPAM = lib_core.getBooleanInput("allow-prerelease-opam"); const constants_CACHE_PREFIX = lib_core.getInput("cache-prefix"); const GITHUB_TOKEN = lib_core.getInput("github-token"); diff --git a/packages/setup-ocaml/src/constants.ts b/packages/setup-ocaml/src/constants.ts index 8fd6f8e0..26296f2e 100644 --- a/packages/setup-ocaml/src/constants.ts +++ b/packages/setup-ocaml/src/constants.ts @@ -87,9 +87,20 @@ export const OPAM_ROOT = (() => { return path.join(os.homedir(), ".opam"); })(); -export const RUNNER_ENVIRONMENT = process.env.RUNNER_ENVIRONMENT as - | "github-hosted" - | "self-hosted"; +export const RUNNER_ENVIRONMENT = ((): "github-hosted" | "self-hosted" => { + const ImageOS = process.env.ImageOS; + const RUNNER_ENVIRONMENT = process.env.RUNNER_ENVIRONMENT as + | "github-hosted" + | "self-hosted" + | undefined; + if (ImageOS) { + return "github-hosted"; + } + if (!RUNNER_ENVIRONMENT) { + return "self-hosted"; + } + return RUNNER_ENVIRONMENT; +})(); export const ALLOW_PRERELEASE_OPAM = core.getBooleanInput( "allow-prerelease-opam", diff --git a/packages/setup-ocaml/src/unix.ts b/packages/setup-ocaml/src/unix.ts index 91958593..d5fd44f0 100644 --- a/packages/setup-ocaml/src/unix.ts +++ b/packages/setup-ocaml/src/unix.ts @@ -1,6 +1,5 @@ -import * as process from "node:process"; import { exec, getExecOutput } from "@actions/exec"; -import { PLATFORM } from "./constants.js"; +import { PLATFORM, RUNNER_ENVIRONMENT } from "./constants.js"; async function checkAptInstallability(packageName: string) { const output = await getExecOutput("sudo", [ @@ -33,15 +32,18 @@ async function retrieveInstallableOptionalDependencies( } export async function installUnixSystemPackages() { - const isGitHubRunner = process.env.GITHUB_ACTIONS === "true"; - const optionalDependencies = await retrieveInstallableOptionalDependencies([ - "darcs", - "g++-multilib", - "gcc-multilib", - "mercurial", - ]); - if (isGitHubRunner) { - if (PLATFORM === "linux") { + if (RUNNER_ENVIRONMENT === "self-hosted") { + return; + } + switch (PLATFORM) { + case "linux": { + const optionalDependencies = + await retrieveInstallableOptionalDependencies([ + "darcs", + "g++-multilib", + "gcc-multilib", + "mercurial", + ]); await exec("sudo", [ "apt-get", "--yes", @@ -51,19 +53,27 @@ export async function installUnixSystemPackages() { "rsync", ...optionalDependencies, ]); - } else if (PLATFORM === "macos") { + break; + } + case "macos": { await exec("brew", ["install", "darcs", "gpatch", "mercurial"]); + break; } } } export async function updateUnixPackageIndexFiles() { - const isGitHubRunner = process.env.GITHUB_ACTIONS === "true"; - if (isGitHubRunner) { - if (PLATFORM === "linux") { + if (RUNNER_ENVIRONMENT === "self-hosted") { + return; + } + switch (PLATFORM) { + case "linux": { await exec("sudo", ["apt-get", "update"]); - } else if (PLATFORM === "macos") { + break; + } + case "macos": { await exec("brew", ["update"]); + break; } } }