Skip to content

Commit

Permalink
Better optional dependencies management
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <sora@morimoto.io>
  • Loading branch information
smorimoto committed Oct 16, 2024
1 parent 96de1ac commit ffd7014
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 56 deletions.
4 changes: 2 additions & 2 deletions analysis/dist/index.js

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

46 changes: 26 additions & 20 deletions dist/index.js

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

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

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

4 changes: 2 additions & 2 deletions lint-fmt/dist/index.js

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

4 changes: 2 additions & 2 deletions packages/analysis/src/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import type { Output } from "./opam-detector.js";
import { createBuildTarget } from "./opam-detector.js";

async function getOpamLocalPackages() {
async function retrieveOpamLocalPackages() {
const globber = await glob.create("*.opam");
const fpaths = await globber.glob();
return fpaths;
Expand All @@ -23,7 +23,7 @@ export async function analysis() {
url: "https://github.com/ocaml/setup-ocaml/tree/master/analysis",
version: "0.0.0",
});
const fpaths = await getOpamLocalPackages();
const fpaths = await retrieveOpamLocalPackages();
for (const fpath of fpaths) {
const temp = await fs.mkdtemp(
path.join(os.tmpdir(), "setup-ocaml-opam-tree-"),
Expand Down
4 changes: 2 additions & 2 deletions packages/lint-fmt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as process from "node:process";
import * as core from "@actions/core";
import { checkFmt } from "./lint.js";
import { getOcamlformatVersion } from "./ocamlformat.js";
import { retrieveOcamlformatVersion } from "./ocamlformat.js";
import { installDune, installOcamlformat } from "./opam.js";

async function run() {
try {
const version = await getOcamlformatVersion();
const version = await retrieveOcamlformatVersion();
if (version) {
await installOcamlformat(version);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/lint-fmt/src/ocamlformat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function parse() {
}
}

export async function getOcamlformatVersion() {
export async function retrieveOcamlformatVersion() {
const config = await parse();
if (config === undefined) {
core.warning(".ocamlformat file is not found");
Expand Down
8 changes: 4 additions & 4 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {
PLATFORM,
RESOLVED_COMPILER,
} from "./constants.js";
import { getLatestOpamRelease } from "./opam.js";
import { getCygwinVersion } from "./windows.js";
import { retrieveLatestOpamRelease } from "./opam.js";
import { retrieveCygwinVersion } from "./windows.js";

async function composeCygwinCacheKeys() {
const cygwinVersion = await getCygwinVersion();
const cygwinVersion = await retrieveCygwinVersion();
const key = `${CACHE_PREFIX}-setup-ocaml-cygwin-${cygwinVersion}`;
const restoreKeys = [key];
return { key, restoreKeys };
Expand All @@ -44,7 +44,7 @@ async function composeDuneCacheKeys() {
}

async function composeOpamCacheKeys() {
const { version: opamVersion } = await getLatestOpamRelease();
const { version: opamVersion } = await retrieveLatestOpamRelease();
const sandbox = OPAM_DISABLE_SANDBOXING ? "nosandbox" : "sandbox";
const ocamlCompiler = await RESOLVED_COMPILER;
const repositoryUrls = OPAM_REPOSITORIES.map(([_, value]) => value).join(",");
Expand Down
4 changes: 2 additions & 2 deletions packages/setup-ocaml/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
repositoryRemoveAll,
setupOpam,
} from "./opam.js";
import { getOpamLocalPackages } from "./packages.js";
import { retrieveOpamLocalPackages } from "./packages.js";
import { setupCygwin } from "./windows.js";

export async function installer() {
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function installer() {
core.exportVariable("DUNE_CACHE_TRANSPORT", "direct");
}
core.exportVariable("CLICOLOR_FORCE", "1");
const fnames = await getOpamLocalPackages();
const fnames = await retrieveOpamLocalPackages();
if (fnames.length > 0) {
if (OPAM_PIN) {
await pin(fnames);
Expand Down
4 changes: 2 additions & 2 deletions packages/setup-ocaml/src/opam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
updateUnixPackageIndexFiles,
} from "./unix.js";

export async function getLatestOpamRelease() {
export async function retrieveLatestOpamRelease() {
const semverRange = ALLOW_PRERELEASE_OPAM ? "*" : "<2.3.0";
const octokit = github.getOctokit(GITHUB_TOKEN);
const { data: releases } = await octokit.rest.repos.listReleases({
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function getLatestOpamRelease() {

async function acquireOpam() {
await core.group("Install opam", async () => {
const { version, browserDownloadUrl } = await getLatestOpamRelease();
const { version, browserDownloadUrl } = await retrieveLatestOpamRelease();
const cachedPath = toolCache.find("opam", version, ARCHITECTURE);
const opam = PLATFORM !== "windows" ? "opam" : "opam.exe";
if (cachedPath === "") {
Expand Down
2 changes: 1 addition & 1 deletion packages/setup-ocaml/src/packages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as glob from "@actions/glob";
import { OPAM_LOCAL_PACKAGES } from "./constants.js";

export async function getOpamLocalPackages() {
export async function retrieveOpamLocalPackages() {
const globber = await glob.create(OPAM_LOCAL_PACKAGES);
const fpaths = await globber.glob();
return fpaths;
Expand Down
31 changes: 21 additions & 10 deletions packages/setup-ocaml/src/unix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as process from "node:process";
import { exec, getExecOutput } from "@actions/exec";
import { PLATFORM } from "./constants.js";

async function checkInstallability(packageName: string) {
async function checkAptInstallability(packageName: string) {
const output = await getExecOutput("sudo", [
"apt-cache",
"search",
Expand All @@ -12,28 +12,39 @@ async function checkInstallability(packageName: string) {
return output.stdout.length !== 0;
}

async function retrieveInstallableOptionalDependencies(
optionalDependencies: string[],
) {
switch (PLATFORM) {
case "linux": {
return optionalDependencies.filter(
async (dep) => await checkAptInstallability(dep),
);
}
default: {
return [];
}
}
}

export async function installUnixSystemPackages() {
const isGitHubRunner = process.env.GITHUB_ACTIONS === "true";
const optionalDependencies = await retrieveInstallableOptionalDependencies([
"darcs",
"mercurial",
]);
if (isGitHubRunner) {
if (PLATFORM === "linux") {
const darcs = await (async () => {
const installability = await checkInstallability("darcs");
if (installability) {
return ["darcs"];
}
return [];
})();
await exec("sudo", [
"apt-get",
"--yes",
"install",
"bubblewrap",
"g++-multilib",
"gcc-multilib",
"mercurial",
"musl-tools",
"rsync",
...darcs,
...optionalDependencies,
]);
} else if (PLATFORM === "macos") {
await exec("brew", ["install", "darcs", "gpatch", "mercurial"]);
Expand Down
Loading

0 comments on commit ffd7014

Please sign in to comment.