Skip to content
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
25 changes: 14 additions & 11 deletions dist/github-client.mjs

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

62 changes: 30 additions & 32 deletions dist/index.mjs

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

2 changes: 1 addition & 1 deletion dist/post/index.mjs

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

10 changes: 3 additions & 7 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PLATFORM,
} from "./constants.js";
import type { Inputs, WindowsEnvironment } from "./inputs.js";
import { toCygwinPath, toMsysPath } from "./paths.js";

export const DUNE_CACHE_KEY_STATE = "dune-cache-key";

Expand Down Expand Up @@ -79,16 +80,11 @@ function composeOpamCachePaths(windowsEnvironment: WindowsEnvironment) {
const opamLocalCachePath = path.join(GITHUB_WORKSPACE, "_opam");
const paths = [OPAM_ROOT, opamLocalCachePath];
if (PLATFORM === "windows") {
const {
repo: { repo },
} = github.context;
if (windowsEnvironment === "msys2") {
const opamMsys2LocalCachePath = path.posix.join("/d", "a", repo, repo, "_opam");
paths.push(opamMsys2LocalCachePath);
paths.push(toMsysPath(opamLocalCachePath));
}
if (windowsEnvironment === "cygwin") {
const opamCygwinLocalCachePath = path.posix.join("/cygdrive", "d", "a", repo, repo, "_opam");
paths.push(opamCygwinLocalCachePath);
paths.push(toCygwinPath(opamLocalCachePath));
}
}
return paths;
Expand Down
13 changes: 5 additions & 8 deletions packages/setup-ocaml/src/opam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as semver from "semver";
import { ARCHITECTURE, MSYS2_ROOT, PLATFORM } from "./constants.js";
import type { Octokit } from "./github-client.js";
import type { Inputs, OpamRepository, WindowsCompiler } from "./inputs.js";
import { toMsysPath } from "./paths.js";
import {
installMsys2Packages,
installUnixSystemPackages,
Expand All @@ -22,11 +23,7 @@ const OPAM_DEV_PUBLIC_KEY_URL = "https://opam.ocaml.org/opam-dev-pubkey.pgp";
const OPAM_DEV_PUBLIC_KEY_FINGERPRINT = "92C526AE50DF39470EB2911BED4CF1CA67CBAA92";

function toGpgPath(filePath: string) {
if (PLATFORM !== "windows") {
return filePath;
}
const { root } = path.parse(filePath);
return `/${root.charAt(0).toLowerCase()}/${filePath.slice(root.length).replaceAll("\\", "/")}`;
return PLATFORM === "windows" ? toMsysPath(filePath) : filePath;
}

async function verifyOpamSignature(
Expand Down Expand Up @@ -165,15 +162,15 @@ async function initializeOpam(inputs: Inputs, initialRepository?: OpamRepository
}
if (PLATFORM !== "windows") {
try {
await installUnixSystemPackages();
await installUnixSystemPackages(PLATFORM);
} catch (error) {
if (error instanceof Error) {
core.notice(
`System package installation failed. Re-synchronizing package index files and retrying installation. Error details: ${error.message.toLocaleLowerCase()}`,
);
}
await updateUnixPackageIndexFiles();
await installUnixSystemPackages();
await updateUnixPackageIndexFiles(PLATFORM);
await installUnixSystemPackages(PLATFORM);
}
}
const extraOptions = [];
Expand Down
26 changes: 26 additions & 0 deletions packages/setup-ocaml/src/paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect, it } from "vite-plus/test";
import { toCygwinPath, toMsysPath } from "./paths.js";

it("converts Windows paths for MSYS2 and Cygwin", () => {
const windowsPaths = [
String.raw`D:\a\setup-ocaml\setup-ocaml\_opam`,
String.raw`C:\Users\runneradmin\AppData\Local\Temp\gpg`,
];
const output = windowsPaths
.map((windowsPath) =>
[
windowsPath,
` msys2: ${toMsysPath(windowsPath)}`,
` cygwin: ${toCygwinPath(windowsPath)}`,
].join("\n"),
)
.join("\n");
expect(output).toMatchInlineSnapshot(`
D:\\a\\setup-ocaml\\setup-ocaml\\_opam
msys2: /d/a/setup-ocaml/setup-ocaml/_opam
cygwin: /cygdrive/d/a/setup-ocaml/setup-ocaml/_opam
C:\\Users\\runneradmin\\AppData\\Local\\Temp\\gpg
msys2: /c/Users/runneradmin/AppData/Local/Temp/gpg
cygwin: /cygdrive/c/Users/runneradmin/AppData/Local/Temp/gpg
`);
});
10 changes: 10 additions & 0 deletions packages/setup-ocaml/src/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as path from "node:path";

export function toMsysPath(windowsPath: string) {
const { root } = path.win32.parse(windowsPath);
return `/${root.charAt(0).toLowerCase()}/${windowsPath.slice(root.length).replaceAll("\\", "/")}`;
}

export function toCygwinPath(windowsPath: string) {
return path.posix.join("/cygdrive", toMsysPath(windowsPath));
}
52 changes: 24 additions & 28 deletions packages/setup-ocaml/src/system-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,17 @@ import { exec, getExecOutput } from "@actions/exec";
import { MSYS2_ROOT, PLATFORM, RUNNER_ENVIRONMENT } from "./constants.js";
import type { WindowsCompiler } from "./inputs.js";

async function retrieveInstallableOptionalDependencies(optionalDependencies: string[]) {
switch (PLATFORM) {
case "linux": {
if (optionalDependencies.length === 0) {
return [];
}
const output = await getExecOutput("apt-cache", [
"show",
"--no-all-versions",
...optionalDependencies,
]);
const installablePackages = new Set(
output.stdout
.split("\n")
.filter((line) => line.startsWith("Package: "))
.map((line) => line.slice("Package: ".length)),
);
return optionalDependencies.filter((packageName) => installablePackages.has(packageName));
}
default: {
return [];
}
}
type UnixPlatform = Exclude<typeof PLATFORM, "windows">;

async function retrieveInstallableAptPackages(packages: string[]) {
const output = await getExecOutput("apt-cache", ["show", "--no-all-versions", ...packages]);
const installablePackages = new Set(
output.stdout
.split("\n")
.filter((line) => line.startsWith("Package: "))
.map((line) => line.slice("Package: ".length)),
);
return packages.filter((packageName) => installablePackages.has(packageName));
}

async function skipPackageManagement() {
Expand Down Expand Up @@ -62,14 +50,14 @@ async function disableManDbAutoUpdate() {
}
}

export async function installUnixSystemPackages() {
export async function installUnixSystemPackages(platform: UnixPlatform) {
if (await skipPackageManagement()) {
return;
}
switch (PLATFORM) {
switch (platform) {
case "linux": {
await disableManDbAutoUpdate();
const optionalDependencies = await retrieveInstallableOptionalDependencies([
const optionalDependencies = await retrieveInstallableAptPackages([
"darcs",
"g++-multilib",
"gcc-multilib",
Expand All @@ -90,6 +78,10 @@ export async function installUnixSystemPackages() {
await exec("brew", ["install", "darcs", "mercurial"]);
break;
}
default: {
const unreachable: never = platform;
throw new Error(`Unhandled platform: ${String(unreachable)}`);
}
}
}

Expand All @@ -110,11 +102,11 @@ export async function installMsys2Packages(windowsCompiler: WindowsCompiler) {
]);
}

export async function updateUnixPackageIndexFiles() {
export async function updateUnixPackageIndexFiles(platform: UnixPlatform) {
if (await skipPackageManagement()) {
return;
}
switch (PLATFORM) {
switch (platform) {
case "linux": {
await exec("sudo", ["apt-get", "update"]);
break;
Expand All @@ -123,5 +115,9 @@ export async function updateUnixPackageIndexFiles() {
await exec("brew", ["update"]);
break;
}
default: {
const unreachable: never = platform;
throw new Error(`Unhandled platform: ${String(unreachable)}`);
}
}
}
Loading