Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix package installation logic for the self-hosted runner environment #958

Merged
merged 2 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions dist/post/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions packages/setup-ocaml/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ export const OPAM_ROOT = (() => {
return path.join(os.homedir(), ".opam");
})();

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",
);
Expand Down
42 changes: 26 additions & 16 deletions packages/setup-ocaml/src/unix.ts
Original file line number Diff line number Diff line change
@@ -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", [
Expand Down Expand Up @@ -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",
Expand All @@ -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;
}
}
}