From a78f2558f02d87dd2fb42b0e2ca80a110f725492 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Fri, 14 Jun 2024 07:59:17 +0900 Subject: [PATCH] opam env Signed-off-by: Sora Morimoto --- EXAMPLES.md | 2 +- README.md | 4 ++-- dist/index.js | 28 +++++++++++++++++---------- dist/post/index.js | 9 +-------- lint-doc/dist/index.js | 2 +- lint-fmt/dist/index.js | 2 +- lint-opam/dist/index.js | 2 +- packages/lint-doc/src/odoc.ts | 2 +- packages/lint-fmt/src/lint.ts | 2 +- packages/lint-opam/src/lint.ts | 2 +- packages/setup-ocaml/src/dune.ts | 9 +-------- packages/setup-ocaml/src/installer.ts | 5 +++-- packages/setup-ocaml/src/opam.ts | 16 +++++++++++++++ 13 files changed, 48 insertions(+), 37 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index db75c5ca..c31c0ed8 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -44,7 +44,7 @@ jobs: run: opam install . --deps-only --with-doc - name: Build documentation - run: opam exec -- dune build @doc + run: dune build @doc - name: Set-up Pages uses: actions/configure-pages@v5 diff --git a/README.md b/README.md index c7dac2d5..a5e1e6d3 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,9 @@ jobs: - run: opam install . --deps-only --with-test - - run: opam exec -- dune build + - run: dune build - - run: opam exec -- dune runtest + - run: dune runtest ``` ### Versioning diff --git a/dist/index.js b/dist/index.js index f9c3efc7..b15fd767 100644 --- a/dist/index.js +++ b/dist/index.js @@ -92818,6 +92818,21 @@ async function setupOpam() { await initializeOpam(); }); } +function setupOpamEnv() { + const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); + const OPAM_SWITCH_PREFIX = external_node_path_namespaceObject.join(githubWorkspace, "_opam"); + const CAML_LD_LIBRARY_PATH = [ + external_node_path_namespaceObject.join(OPAM_SWITCH_PREFIX, "lib", "stublibs"), + external_node_path_namespaceObject.join(OPAM_SWITCH_PREFIX, "lib", "ocaml", "stublibs"), + external_node_path_namespaceObject.join(OPAM_SWITCH_PREFIX, "lib", "ocaml"), + ].join(external_node_path_namespaceObject.delimiter); + const OCAML_TOPLEVEL_PATH = external_node_path_namespaceObject.join(OPAM_SWITCH_PREFIX, "lib", "toplevel"); + const OPAM_SWITCH_BIN = external_node_path_namespaceObject.join(OPAM_SWITCH_PREFIX, "bin"); + lib_core.exportVariable("OPAM_SWITCH_PREFIX", OPAM_SWITCH_PREFIX); + lib_core.exportVariable("CAML_LD_LIBRARY_PATH", CAML_LD_LIBRARY_PATH); + lib_core.exportVariable("OCAML_TOPLEVEL_PATH", OCAML_TOPLEVEL_PATH); + lib_core.addPath(OPAM_SWITCH_BIN); +} async function installOcaml(ocamlCompiler) { await lib_core.group("Install OCaml", async () => { await (0,lib_exec.exec)("opam", [ @@ -110482,14 +110497,7 @@ async function trimDuneCache() { run_id, }); const cacheSize = Math.floor(5000 / totalCount); - await exec("opam", [ - "exec", - "--", - "dune", - "cache", - "trim", - `--size=${cacheSize}MB`, - ]); + await exec("dune", ["cache", "trim", `--size=${cacheSize}MB`]); }); } @@ -110558,6 +110566,7 @@ async function installer() { await installOcaml(ocamlCompiler); await saveOpamCache(); } + setupOpamEnv(); if (DUNE_CACHE) { await restoreDuneCache(); await installDune(); @@ -110565,7 +110574,6 @@ async function installer() { lib_core.exportVariable("DUNE_CACHE_TRANSPORT", "direct"); lib_core.exportVariable("DUNE_CACHE_STORAGE_MODE", "copy"); } - lib_core.exportVariable("CLICOLOR_FORCE", "1"); const fnames = await getOpamLocalPackages(); if (fnames.length > 0) { if (OPAM_PIN) { @@ -110573,7 +110581,7 @@ async function installer() { } } await (0,lib_exec.exec)("opam", ["--version"]); - await (0,lib_exec.exec)("opam", ["exec", "--", "ocaml", "-version"]); + await (0,lib_exec.exec)("ocaml", ["-version"]); } ;// CONCATENATED MODULE: ./src/index.ts diff --git a/dist/post/index.js b/dist/post/index.js index 3d77ca75..3eeba0cc 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -84985,14 +84985,7 @@ async function trimDuneCache() { run_id, }); const cacheSize = Math.floor(5000 / totalCount); - await (0,lib_exec.exec)("opam", [ - "exec", - "--", - "dune", - "cache", - "trim", - `--size=${cacheSize}MB`, - ]); + await (0,lib_exec.exec)("dune", ["cache", "trim", `--size=${cacheSize}MB`]); }); } diff --git a/lint-doc/dist/index.js b/lint-doc/dist/index.js index ac1c2a25..f2b5e52c 100644 --- a/lint-doc/dist/index.js +++ b/lint-doc/dist/index.js @@ -27920,7 +27920,7 @@ var exec = __nccwpck_require__(6473); async function lintOdoc() { - const exitCode = await (0,exec.exec)("opam", ["exec", "--", "dune", "build", "@doc"], { + const exitCode = await (0,exec.exec)("dune", ["build", "@doc"], { env: { ...external_node_process_namespaceObject.env, PATH: external_node_process_namespaceObject.env.PATH ?? "", diff --git a/lint-fmt/dist/index.js b/lint-fmt/dist/index.js index 4168291c..82f2519f 100644 --- a/lint-fmt/dist/index.js +++ b/lint-fmt/dist/index.js @@ -27919,7 +27919,7 @@ var exec = __nccwpck_require__(6473); ;// CONCATENATED MODULE: ./src/lint.ts async function checkFmt() { - await (0,exec.exec)("opam", ["exec", "--", "dune", "build", "@fmt"]); + await (0,exec.exec)("dune", ["build", "@fmt"]); } ;// CONCATENATED MODULE: external "node:fs" diff --git a/lint-opam/dist/index.js b/lint-opam/dist/index.js index dbb4929b..8ccfd9f2 100644 --- a/lint-opam/dist/index.js +++ b/lint-opam/dist/index.js @@ -27922,7 +27922,7 @@ async function opamLint() { await (0,exec.exec)("opam", ["lint"]); } async function opamDuneLint() { - await (0,exec.exec)("opam", ["exec", "--", "opam-dune-lint"]); + await (0,exec.exec)("opam-dune-lint"); } ;// CONCATENATED MODULE: ./src/opam.ts diff --git a/packages/lint-doc/src/odoc.ts b/packages/lint-doc/src/odoc.ts index 2514f916..d11d9acb 100644 --- a/packages/lint-doc/src/odoc.ts +++ b/packages/lint-doc/src/odoc.ts @@ -2,7 +2,7 @@ import * as process from "node:process"; import { exec } from "@actions/exec"; export async function lintOdoc() { - const exitCode = await exec("opam", ["exec", "--", "dune", "build", "@doc"], { + const exitCode = await exec("dune", ["build", "@doc"], { env: { ...process.env, PATH: process.env.PATH ?? "", diff --git a/packages/lint-fmt/src/lint.ts b/packages/lint-fmt/src/lint.ts index eba1ab5c..3301eda5 100644 --- a/packages/lint-fmt/src/lint.ts +++ b/packages/lint-fmt/src/lint.ts @@ -1,5 +1,5 @@ import { exec } from "@actions/exec"; export async function checkFmt() { - await exec("opam", ["exec", "--", "dune", "build", "@fmt"]); + await exec("dune", ["build", "@fmt"]); } diff --git a/packages/lint-opam/src/lint.ts b/packages/lint-opam/src/lint.ts index 2ef46e2c..5c13353f 100644 --- a/packages/lint-opam/src/lint.ts +++ b/packages/lint-opam/src/lint.ts @@ -5,5 +5,5 @@ export async function opamLint() { } export async function opamDuneLint() { - await exec("opam", ["exec", "--", "opam-dune-lint"]); + await exec("opam-dune-lint"); } diff --git a/packages/setup-ocaml/src/dune.ts b/packages/setup-ocaml/src/dune.ts index 2c3c49bd..e7245a50 100644 --- a/packages/setup-ocaml/src/dune.ts +++ b/packages/setup-ocaml/src/dune.ts @@ -27,14 +27,7 @@ export async function trimDuneCache() { run_id, }); const cacheSize = Math.floor(5000 / totalCount); - await exec("opam", [ - "exec", - "--", - "dune", - "cache", - "trim", - `--size=${cacheSize}MB`, - ]); + await exec("dune", ["cache", "trim", `--size=${cacheSize}MB`]); }, ); } diff --git a/packages/setup-ocaml/src/installer.ts b/packages/setup-ocaml/src/installer.ts index 3e271a0f..dbe8974f 100644 --- a/packages/setup-ocaml/src/installer.ts +++ b/packages/setup-ocaml/src/installer.ts @@ -24,6 +24,7 @@ import { repositoryAddAll, repositoryRemoveAll, setupOpam, + setupOpamEnv, } from "./opam.js"; import { getOpamLocalPackages } from "./packages.js"; import { resolveCompiler } from "./version.js"; @@ -71,6 +72,7 @@ export async function installer() { await installOcaml(ocamlCompiler); await saveOpamCache(); } + setupOpamEnv(); if (DUNE_CACHE) { await restoreDuneCache(); await installDune(); @@ -78,7 +80,6 @@ export async function installer() { core.exportVariable("DUNE_CACHE_TRANSPORT", "direct"); core.exportVariable("DUNE_CACHE_STORAGE_MODE", "copy"); } - core.exportVariable("CLICOLOR_FORCE", "1"); const fnames = await getOpamLocalPackages(); if (fnames.length > 0) { if (OPAM_PIN) { @@ -86,5 +87,5 @@ export async function installer() { } } await exec("opam", ["--version"]); - await exec("opam", ["exec", "--", "ocaml", "-version"]); + await exec("ocaml", ["-version"]); } diff --git a/packages/setup-ocaml/src/opam.ts b/packages/setup-ocaml/src/opam.ts index a3e8bdfc..7b96f08c 100644 --- a/packages/setup-ocaml/src/opam.ts +++ b/packages/setup-ocaml/src/opam.ts @@ -120,6 +120,22 @@ export async function setupOpam() { }); } +export function setupOpamEnv() { + const githubWorkspace = process.env.GITHUB_WORKSPACE ?? process.cwd(); + const OPAM_SWITCH_PREFIX = path.join(githubWorkspace, "_opam"); + const CAML_LD_LIBRARY_PATH = [ + path.join(OPAM_SWITCH_PREFIX, "lib", "stublibs"), + path.join(OPAM_SWITCH_PREFIX, "lib", "ocaml", "stublibs"), + path.join(OPAM_SWITCH_PREFIX, "lib", "ocaml"), + ].join(path.delimiter); + const OCAML_TOPLEVEL_PATH = path.join(OPAM_SWITCH_PREFIX, "lib", "toplevel"); + const OPAM_SWITCH_BIN = path.join(OPAM_SWITCH_PREFIX, "bin"); + core.exportVariable("OPAM_SWITCH_PREFIX", OPAM_SWITCH_PREFIX); + core.exportVariable("CAML_LD_LIBRARY_PATH", CAML_LD_LIBRARY_PATH); + core.exportVariable("OCAML_TOPLEVEL_PATH", OCAML_TOPLEVEL_PATH); + core.addPath(OPAM_SWITCH_BIN); +} + export async function installOcaml(ocamlCompiler: string) { await core.group("Install OCaml", async () => { await exec("opam", [