Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <[email protected]>
  • Loading branch information
smorimoto committed Jun 12, 2024
1 parent a696e17 commit e92f8be
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 470 deletions.
599 changes: 288 additions & 311 deletions dist/index.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions dist/post/index.js

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

10 changes: 6 additions & 4 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ async function saveCache(key: string, paths: string[]) {
}

export async function restoreCygwinCache() {
await core.group("Retrieve the Cygwin cache", async () => {
return await core.group("Retrieve the Cygwin cache", async () => {
const { key, restoreKeys } = await composeCygwinCacheKeys();
const paths = composeCygwinCachePaths();
await restoreCache(key, restoreKeys, paths);
const cacheKey = await restoreCache(key, restoreKeys, paths);
return cacheKey;
});
}

Expand All @@ -172,10 +173,11 @@ export async function saveCygwinCache() {
}

export async function restoreDuneCache() {
await core.group("Retrieve the dune cache", async () => {
return await core.group("Retrieve the dune cache", async () => {
const { key, restoreKeys } = composeDuneCacheKeys();
const paths = composeDuneCachePaths();
await restoreCache(key, restoreKeys, paths);
const cacheKey = await restoreCache(key, restoreKeys, paths);
return cacheKey;
});
}

Expand Down
18 changes: 8 additions & 10 deletions packages/setup-ocaml/src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from "node:path";
import * as process from "node:process";

import * as core from "@actions/core";
Expand All @@ -8,6 +7,7 @@ import {
restoreCygwinCache,
restoreDuneCache,
restoreOpamCache,
saveCygwinCache,
saveOpamCache,
} from "./cache.js";
import {
Expand All @@ -27,6 +27,7 @@ import {
} from "./opam.js";
import { getOpamLocalPackages } from "./packages.js";
import { resolveCompiler } from "./version.js";
import { setupCygwin } from "./windows.js";

export async function installer() {
if (core.isDebug()) {
Expand All @@ -37,10 +38,6 @@ export async function installer() {
core.exportVariable("OPAMERRLOGLEN", 0);
core.exportVariable("OPAMPRECISETRACKING", 1);
core.exportVariable("OPAMYES", 1);
if (PLATFORM === "windows") {
const opamRoot = path.join("D:", ".opam");
core.exportVariable("OPAMROOT", opamRoot);
}
if (PLATFORM === "windows") {
await core.group("Change the file system behavior parameters", async () => {
await exec("fsutil", ["behavior", "query", "SymlinkEvaluation"]);
Expand All @@ -54,13 +51,14 @@ export async function installer() {
]);
await exec("fsutil", ["behavior", "query", "SymlinkEvaluation"]);
});
}
if (PLATFORM === "windows") {
core.exportVariable("HOME", process.env.USERPROFILE);
core.exportVariable("MSYS", "winsymlinks:native");
}
if (PLATFORM === "windows") {
await restoreCygwinCache();
core.exportVariable("CYGWIN", "winsymlinks:native");
const cygwinCacheHit = await restoreCygwinCache();
if (!cygwinCacheHit) {
await setupCygwin();
await saveCygwinCache();
}
}
const opamCacheHit = await restoreOpamCache();
await setupOpam();
Expand Down
150 changes: 21 additions & 129 deletions packages/setup-ocaml/src/opam.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import { promises as fs } from "node:fs";
import * as path from "node:path";
import * as process from "node:process";

import * as core from "@actions/core";
import { exec, getExecOutput } from "@actions/exec";
import * as github from "@actions/github";
import * as io from "@actions/io";
import * as toolCache from "@actions/tool-cache";
import * as semver from "semver";

import { saveCygwinCache } from "./cache.js";
import {
ALLOW_PRERELEASE_OPAM,
ARCHITECTURE,
CYGWIN_MIRROR,
CYGWIN_ROOT,
GITHUB_TOKEN,
OPAM_DISABLE_SANDBOXING,
PLATFORM,
} from "./constants.js";
import {
getSystemIdentificationInfo,
installUnixSystemPackages,
updateUnixPackageIndexFiles,
} from "./system.js";
import { getCygwinVersion } from "./windows.js";
} from "./unix.js";

export async function getLatestOpamRelease() {
const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.3.0";
Expand Down Expand Up @@ -86,149 +81,46 @@ async function acquireOpam() {
}
}

async function installUnixSystemPackages() {
const isGitHubRunner = process.env.GITHUB_ACTIONS === "true";
if (isGitHubRunner) {
if (PLATFORM === "linux") {
const { version: systemVersion } = await getSystemIdentificationInfo();
if (systemVersion === "18.04") {
// [INFO]: musl-tools bug in ubuntu 18.04;
// <https://github.com/ocaml/ocaml/issues/9131#issuecomment-599765888>
await exec("sudo", ["add-apt-repository", "ppa:avsm/musl"]);
async function initializeOpam() {
if (PLATFORM !== "windows") {
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 exec("sudo", [
"apt-get",
"--yes",
"install",
"bubblewrap",
"darcs",
"g++-multilib",
"gcc-multilib",
"mercurial",
"musl-tools",
"rsync",
]);
} else if (PLATFORM === "macos") {
await exec("brew", ["install", "darcs", "gpatch", "mercurial"]);
await updateUnixPackageIndexFiles();
await installUnixSystemPackages();
}
}
}

async function initializeOpamUnix() {
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 disableSandboxing = [];
if (OPAM_DISABLE_SANDBOXING) {
disableSandboxing.push("--disable-sandboxing");
}
await exec("opam", [
"init",
"--auto-setup",
"--bare",
...disableSandboxing,
"--enable-shell-hook",
]);
}

async function setupOpamUnix() {
await core.group("Install opam", async () => {
await acquireOpam();
});
await core.group("Initialise the opam state", async () => {
await initializeOpamUnix();
});
}

async function setupCygwin() {
const version = await getCygwinVersion();
const cachedPath = toolCache.find("cygwin", version, "x86_64");
if (cachedPath === "") {
const downloadedPath = await toolCache.downloadTool(
"https://cygwin.com/setup-x86_64.exe",
);
const cachedPath = await toolCache.cacheFile(
downloadedPath,
"setup-x86_64.exe",
"cygwin",
version,
"x86_64",
);
core.addPath(cachedPath);
} else {
core.addPath(cachedPath);
const extraOptions = [];
if (PLATFORM === "windows") {
extraOptions.push("--cygwin-local-install");
extraOptions.push(`--cygwin-location=${CYGWIN_ROOT}`);
}
const packages = [
"curl",
"diffutils",
"m4",
"make",
"mingw64-i686-gcc-core",
"mingw64-i686-gcc-g++",
"mingw64-x86_64-gcc-core",
"mingw64-x86_64-gcc-g++",
"patch",
"perl",
"rsync",
"unzip",
].join(",");
await exec("setup-x86_64", [
`--packages=${packages}`,
"--quiet-mode",
`--root=${CYGWIN_ROOT}`,
`--site=${CYGWIN_MIRROR}`,
"--symlink-type=sys",
]);
const setup = await io.which("setup-x86_64");
await io.cp(setup, CYGWIN_ROOT);
}

async function initializeOpamWindows() {
const disableSandboxing = [];
if (OPAM_DISABLE_SANDBOXING) {
disableSandboxing.push("--disable-sandboxing");
extraOptions.push("--disable-sandboxing");
}
await exec("opam", [
"init",
"--auto-setup",
"--bare",
"--cygwin-local-install",
`--cygwin-location=${CYGWIN_ROOT}`,
...disableSandboxing,
...extraOptions,
"--enable-shell-hook",
]);
}

async function setupOpamWindows() {
await core.group("Prepare the Cygwin environment", async () => {
core.exportVariable("CYGWIN", "winsymlinks:native");
await setupCygwin();
});
await saveCygwinCache();
export async function setupOpam() {
await core.group("Install opam", async () => {
await acquireOpam();
});
await core.group("Initialise the opam state", async () => {
await initializeOpamWindows();
await initializeOpam();
});
}

export async function setupOpam() {
if (PLATFORM === "windows") {
await setupOpamWindows();
} else {
await setupOpamUnix();
}
}

export async function installOcaml(ocamlCompiler: string) {
await core.group("Install OCaml", async () => {
await exec("opam", [
Expand Down
13 changes: 1 addition & 12 deletions packages/setup-ocaml/src/system.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs } from "node:fs";
import * as os from "node:os";

import { exec, getExecOutput } from "@actions/exec";
import { getExecOutput } from "@actions/exec";

import { PLATFORM } from "./constants.js";

Expand Down Expand Up @@ -35,14 +35,3 @@ export async function getSystemIdentificationInfo() {
}
throw new Error("The system is not supported.");
}

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"]);
}
}
}
43 changes: 43 additions & 0 deletions packages/setup-ocaml/src/unix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { exec } from "@actions/exec";

import { PLATFORM } from "./constants.js";
import { getSystemIdentificationInfo } from "./system.js";

export async function installUnixSystemPackages() {
const isGitHubRunner = process.env.GITHUB_ACTIONS === "true";
if (isGitHubRunner) {
if (PLATFORM === "linux") {
const { version: systemVersion } = await getSystemIdentificationInfo();
if (systemVersion === "18.04") {
// [INFO]: musl-tools bug in ubuntu 18.04;
// <https://github.com/ocaml/ocaml/issues/9131#issuecomment-599765888>
await exec("sudo", ["add-apt-repository", "ppa:avsm/musl"]);
}
await exec("sudo", [
"apt-get",
"--yes",
"install",
"bubblewrap",
"darcs",
"g++-multilib",
"gcc-multilib",
"mercurial",
"musl-tools",
"rsync",
]);
} else if (PLATFORM === "macos") {
await exec("brew", ["install", "darcs", "gpatch", "mercurial"]);
}
}
}

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"]);
}
}
}
Loading

0 comments on commit e92f8be

Please sign in to comment.