Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
- windows-latest
ocaml-compiler:
- "5.2"
windows-environment:
- ""
allow-prerelease-opam:
- false
include:
Expand All @@ -62,6 +64,10 @@ jobs:
- os: ubuntu-latest
ocaml-compiler: "5.2"
allow-prerelease-opam: true
- os: windows-latest
ocaml-compiler: "5.2"
windows-environment: msys2
allow-prerelease-opam: false

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

Expand All @@ -74,5 +80,6 @@ jobs:
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
allow-prerelease-opam: ${{ matrix.allow-prerelease-opam }}
windows-environment: ${{ matrix.windows-environment }}

- run: opam install ssl
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
102 changes: 91 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 @@ -18,6 +18,7 @@ import {
OPAM_ROOT,
PLATFORM,
RESOLVED_COMPILER,
WINDOWS_ENVIRONMENT,
} from "./constants.js";
import { retrieveLatestOpamRelease } from "./opam.js";
import { retrieveCygwinVersion } from "./windows.js";
Expand Down Expand Up @@ -50,6 +51,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 @@ -58,7 +60,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 @@ -203,7 +207,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 @@ -86,6 +86,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
25 changes: 19 additions & 6 deletions packages/setup-ocaml/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
saveOpamCache,
} from "./cache.js";
import {
CYGWIN_ROOT,
CYGWIN_ROOT_BIN,
DUNE_CACHE,
DUNE_CACHE_ROOT,
Expand All @@ -18,6 +19,7 @@ import {
OPAM_ROOT,
PLATFORM,
RESOLVED_COMPILER,
WINDOWS_ENVIRONMENT,
} from "./constants.js";
import { installDune } from "./dune.js";
import {
Expand All @@ -29,7 +31,7 @@ import {
update,
} from "./opam.js";
import { retrieveOpamLocalPackages } 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 @@ -64,13 +66,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();
if (!opamCacheHit) {
await repositoryRemoveAll();
await repositoryAddAll(OPAM_REPOSITORIES);
Expand Down
Loading
Loading