Skip to content

Commit

Permalink
opam env
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <sora@morimoto.io>
  • Loading branch information
smorimoto committed Jun 13, 2024
1 parent 1c4e8e9 commit a9e1cf9
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 37 deletions.
2 changes: 1 addition & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 18 additions & 10 deletions dist/index.js

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

9 changes: 1 addition & 8 deletions dist/post/index.js

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

2 changes: 1 addition & 1 deletion lint-doc/dist/index.js

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

2 changes: 1 addition & 1 deletion lint-fmt/dist/index.js

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

2 changes: 1 addition & 1 deletion lint-opam/dist/index.js

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

2 changes: 1 addition & 1 deletion packages/lint-doc/src/odoc.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 } 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 ?? "",
Expand Down
2 changes: 1 addition & 1 deletion packages/lint-fmt/src/lint.ts
Original file line number Diff line number Diff line change
@@ -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"]);
}
2 changes: 1 addition & 1 deletion packages/lint-opam/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export async function opamLint() {
}

export async function opamDuneLint() {
await exec("opam", ["exec", "--", "opam-dune-lint"]);
await exec("opam-dune-lint");
}
9 changes: 1 addition & 8 deletions packages/setup-ocaml/src/dune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", ["dune", "cache", "trim", `--size=${cacheSize}MB`]);
},
);
}
5 changes: 3 additions & 2 deletions packages/setup-ocaml/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
repositoryAddAll,
repositoryRemoveAll,
setupOpam,
setupOpamEnv,
} from "./opam.js";
import { getOpamLocalPackages } from "./packages.js";
import { resolveCompiler } from "./version.js";
Expand Down Expand Up @@ -71,20 +72,20 @@ export async function installer() {
await installOcaml(ocamlCompiler);
await saveOpamCache();
}
setupOpamEnv();
if (DUNE_CACHE) {
await restoreDuneCache();
await installDune();
core.exportVariable("DUNE_CACHE", "enabled");
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) {
await pin(fnames);
}
}
await exec("opam", ["--version"]);
await exec("opam", ["exec", "--", "ocaml", "-version"]);
await exec("ocaml", ["-version"]);
}
16 changes: 16 additions & 0 deletions packages/setup-ocaml/src/opam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", [
Expand Down

0 comments on commit a9e1cf9

Please sign in to comment.