Skip to content

add alpine linux compatibility #940

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

Closed
wants to merge 1 commit into from
Closed
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
94 changes: 68 additions & 26 deletions dist/index.js

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

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

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

10 changes: 10 additions & 0 deletions packages/setup-ocaml/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as os from "node:os";
import * as path from "node:path";
import * as fs from "node:fs";
import * as process from "node:process";
import * as core from "@actions/core";
import * as yaml from "yaml";
Expand Down Expand Up @@ -55,6 +56,15 @@ export const PLATFORM = (() => {
}
})();

export const DISTRO = (() => {
try {
const osRelease = fs.readFileSync("/etc/os-release")
const match = osRelease.toString().match(/^ID=(.*)$/m)
return match ? match[1] : "(unknown)"
} catch (e) {
return "(unknown)"
}
})();
export const CYGWIN_MIRROR = "https://mirrors.kernel.org/sourceware/cygwin/";

export const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE ?? process.cwd();
Expand Down
79 changes: 54 additions & 25 deletions packages/setup-ocaml/src/unix.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import * as process from "node:process";
import { exec, getExecOutput } from "@actions/exec";
import { PLATFORM } from "./constants.js";
import { PLATFORM, DISTRO } from "./constants.js";

async function checkAptInstallability(packageName: string) {
const output = await getExecOutput("sudo", [
"apt-cache",
"search",
"--names-only",
`'^${packageName}$'`,
]);
async function checkInstallability(packageName: string) {
let output;
if (DISTRO === "alpine") {
output = await getExecOutput("apk", [
"search",
"--exact",
packageName,
]);
} else {
output = await getExecOutput("sudo", [
"apt-cache",
"search",
"--names-only",
`'^${packageName}$'`,
]);
}
return output.stdout.length > 0;
}

Expand All @@ -19,7 +28,7 @@ async function retrieveInstallableOptionalDependencies(
case "linux": {
const installableOptionalDependencies: string[] = [];
for (const optionalDependency of optionalDependencies) {
const isInstallable = await checkAptInstallability(optionalDependency);
const isInstallable = await checkInstallability(optionalDependency);
if (isInstallable) {
installableOptionalDependencies.push(optionalDependency);
}
Expand All @@ -34,23 +43,39 @@ 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") {
await exec("sudo", [
"apt-get",
"--yes",
"install",
"bubblewrap",
"musl-tools",
"rsync",
...optionalDependencies,
]);
if (DISTRO === "alpine") {
const optionalDependencies = await retrieveInstallableOptionalDependencies([
//"darcs", does not exist on alpine?
"mercurial",
]);
await exec("apk", [
"add",
"make",
"build-base",
"bubblewrap",
"rsync",
...optionalDependencies,
]);
} else {
const optionalDependencies = await retrieveInstallableOptionalDependencies([
"darcs",
"g++-multilib",
"gcc-multilib",
"mercurial",
]);
await exec("sudo", [
"apt-get",
"--yes",
"install",
"bubblewrap",
"musl-tools",
"rsync",
...optionalDependencies,
]);
}
} else if (PLATFORM === "macos") {
await exec("brew", ["install", "darcs", "gpatch", "mercurial"]);
}
Expand All @@ -61,7 +86,11 @@ export async function updateUnixPackageIndexFiles() {
const isGitHubRunner = process.env.GITHUB_ACTIONS === "true";
if (isGitHubRunner) {
if (PLATFORM === "linux") {
await exec("sudo", ["apt-get", "update"]);
if (DISTRO === "alpine") {
await exec("apk", ["update"]);
} else {
await exec("sudo", ["apt-get", "update"]);
}
} else if (PLATFORM === "macos") {
await exec("brew", ["update"]);
}
Expand Down