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

Allow using msys2 instead of cygwin #857

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ jobs:
- windows-latest
ocaml-compiler:
- "5.2"
windows-environment:
- ""
include:
- os: ubuntu-latest
ocaml-compiler: ocaml-variants.5.2.0+options,ocaml-option-flambda
- os: windows-latest
ocaml-compiler: "5.2"
windows-environment: msys2

runs-on: ${{ matrix.os }}

Expand All @@ -66,5 +71,6 @@ jobs:
uses: ./
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
windows-environment: ${{ matrix.windows-environment }}

- run: opam install uri
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ inputs:
description: The prefix of the cache keys.
required: false
default: v1
windows-environment:
description: Whether to use `cygwin` (default) or `msys2` for windows installs.
required: false
github-token:
description: DO NOT SET THIS.
required: false
Expand Down
103 changes: 92 additions & 11 deletions dist/index.js

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

20 changes: 18 additions & 2 deletions dist/post/index.js

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

8 changes: 6 additions & 2 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
OPAM_ROOT,
PLATFORM,
RESOLVED_COMPILER,
WINDOWS_ENVIRONMENT,
} from "./constants.js";
import { getLatestOpamRelease } from "./opam.js";
import { getCygwinVersion } from "./windows.js";
Expand Down Expand Up @@ -49,6 +50,7 @@ async function composeOpamCacheKeys() {
const ocamlCompiler = await RESOLVED_COMPILER;
const repositoryUrls = OPAM_REPOSITORIES.map(([_, value]) => value).join(",");
const osInfo = await system.osInfo();
const msys2 = WINDOWS_ENVIRONMENT === "msys2" ? "msys2" : undefined;
const plainKey = [
PLATFORM,
osInfo.release,
Expand All @@ -57,7 +59,9 @@ async function composeOpamCacheKeys() {
ocamlCompiler,
repositoryUrls,
sandbox,
].join(",");
]
.concat(msys2 ?? [])
.join(",");
const hash = crypto.createHash("sha256").update(plainKey).digest("hex");
const key = `${CACHE_PREFIX}-setup-ocaml-opam-${hash}`;
const restoreKeys = [key];
Expand Down Expand Up @@ -177,7 +181,7 @@ async function restoreOpamCache() {
export async function restoreOpamCaches() {
return await core.group("Retrieve the opam cache", async () => {
const [opamCacheHit, cygwinCacheHit] = await Promise.all(
PLATFORM === "windows"
PLATFORM === "windows" && WINDOWS_ENVIRONMENT === "cygwin"
? [restoreOpamCache(), restoreCygwinCache()]
: [restoreOpamCache()],
);
Expand Down
17 changes: 17 additions & 0 deletions packages/setup-ocaml/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ export const ALLOW_PRERELEASE_OPAM = core.getBooleanInput(
},
);

export const WINDOWS_ENVIRONMENT: "cygwin" | "msys2" = (() => {
const input = core.getInput("windows-environment");

if (!(PLATFORM === "windows" || input === "")) {
core.error("windows-environment is only supported on windows");
}

if (input === "msys2" || input === "cygwin") {
return input;
}

if (input !== "") {
core.error("unrecognized value for windows-environment");
}
return "cygwin";
})();

export const CACHE_PREFIX = core.getInput("cache-prefix", {
required: false,
trimWhitespace: true,
Expand Down
26 changes: 20 additions & 6 deletions packages/setup-ocaml/src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as os from "node:os";
// import * as path from "node:path";
import * as process from "node:process";
import * as core from "@actions/core";
import { exec } from "@actions/exec";
Expand All @@ -9,6 +10,7 @@ import {
saveOpamCache,
} from "./cache.js";
import {
CYGWIN_ROOT,
CYGWIN_ROOT_BIN,
DUNE_CACHE,
DUNE_CACHE_ROOT,
Expand All @@ -17,6 +19,7 @@ import {
OPAM_ROOT,
PLATFORM,
RESOLVED_COMPILER,
WINDOWS_ENVIRONMENT,
} from "./constants.js";
import { installDune } from "./dune.js";
import {
Expand All @@ -27,7 +30,7 @@ import {
setupOpam,
} from "./opam.js";
import { getOpamLocalPackages } from "./packages.js";
import { setupCygwin } from "./windows.js";
import { prepareMsys2, setupCygwin } from "./windows.js";

export async function installer() {
if (core.isDebug()) {
Expand Down Expand Up @@ -62,13 +65,24 @@ export async function installer() {
}
const { opamCacheHit, cygwinCacheHit } = await restoreOpamCaches();
if (PLATFORM === "windows") {
await setupCygwin();
if (!cygwinCacheHit) {
await saveCygwinCache();
switch (WINDOWS_ENVIRONMENT) {
case "msys2": {
const msys2Root = await prepareMsys2();
await setupOpam(msys2Root);
break;
}
case "cygwin":
await setupCygwin();
if (!cygwinCacheHit) {
await saveCygwinCache();
}
core.addPath(CYGWIN_ROOT_BIN);
await setupOpam(CYGWIN_ROOT);
break;
}
core.addPath(CYGWIN_ROOT_BIN);
} else {
await setupOpam();
}
await setupOpam();
await repositoryRemoveAll();
await repositoryAddAll(OPAM_REPOSITORIES);
const ocamlCompiler = await RESOLVED_COMPILER;
Expand Down
Loading