Set up an OCaml and opam environment in GitHub Actions and add to PATH.
The action does the following:
- Change the file system behavioral parameters
- Windows only
- Retrieve the Cygwin cache
- Windows only
- If the cache already exists
- Retrieve the opam cache
- If the cache already exists
- Prepare the Cygwin environment
- Windows only
- Save the Cygwin cache
- Windows only
- Install opam
- Initialise the opam state
- Install the OCaml compiler
- If the opam cache was not hit
- Remove the opam repositories
- Save the opam cache
- If the opam cache was not hit
- Initialise the opam repositories
- Retrieve the opam download cache
- Install depext
- On Windows, not only
opam-depext
is installed, butdepext-cygwinports
is installed as well
- On Windows, not only
- Retrieve the dune cache
- If the dune cache feature is enabled
- If the cache already exists
- Install the latest dune and enable the dune cache feature
- If the dune cache feature is enabled
- Pin the opam files, if they exist
- If the opam pin feature is not disabled
- If there is an opam file in the workspace that matches the glob pattern
- Install the system dependencies required by the opam files via depext
- If the opam depext feature is enabled
- If there is an opam file in the workspace that matches the glob pattern
The reason for not caching opam stuff in the post stage (more precisely, why you can't) is due to the size of the cache and repeatability. They should be cached immediately after initialisation to minimize the size of the cache.
- Remove oldest dune cache files to free space
- If the dune cache feature is enabled
- Save the dune cache
- If the dune cache feature is enabled
- Save the opam download cache
- opam dependencies: opam packages installed by
opam install
. - depext dependencies: System packages installed by
apt-get install
,yum install
,brew install
, etc.
We adhere to semantic versioning, it's safe to use the
major version (v2
) in your workflow. If you use the master branch, this could
break your workflow when we publish a breaking update and increase the major
version.
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
# ^^^
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
steps:
# Reference the major version of a release (most recommended)
- uses: ocaml/setup-ocaml@v2
# Reference a specific commit (most strict)
- uses: ocaml/setup-ocaml@<SHA>
# Reference a semver version of a release (not recommended)
- uses: ocaml/setup-ocaml@v2.0.0
# Reference a branch (most dangerous)
- uses: ocaml/setup-ocaml@master
See the Hello World OCaml Action that uses Dune and opam to build a simple library.
It's possible to feed different values to the input depending on the platform of the runner. The syntax of GitHub's workflows is flexible enough to offer several methods to do this.
name: Main workflow
on:
pull_request:
push:
schedule:
# Prime the caches every Monday
- cron: 0 1 * * MON
jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
ocaml-compiler:
- 4.13.x
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
- run: opam install . --deps-only --with-test
- run: opam exec -- dune build
- run: opam exec -- dune runtest
See Examples for more complex patterns.
Name | Required | Description | Type | Default |
---|---|---|---|---|
ocaml-compiler |
Yes | The OCaml compiler packages to initialise. The packages must be separated by the comma. (e.g. 4.13.x , ocaml-base-compiler.4.13.0 , ocaml-variants.4.13.0+options,ocaml-option-flambda,ocaml-option-musl,ocaml-option-static ) |
string | |
opam-repositories |
No | The name and URL pair of the repository to fetch the packages from. | string | |
opam-pin |
No | Enable the automation feature for opam pin. | bool | true |
opam-depext |
No | Enable the automation feature for opam depext. | bool | true |
opam-depext-flags |
No | The flags for the opam depext command. The flags must be separated by the comma. | string | |
opam-local-packages |
No | The local packages to be used by opam-pin or opam-depext . See @actions/glob for supported patterns. |
string | *.opam |
opam-disable-sandboxing |
No | Disable the opam sandboxing feature. | bool | false |
dune-cache |
No | Enable the dune cache feature. This feature requires dune 2.8.5 or later on the Windows runners. | bool | false |
cache-prefix |
No | The prefix of the cache keys. | string | v1 |
This action aims to provide an OS-neutral interface to opam
, and so will not
add features that only work on one operating system. It will also track the
latest stable release of opam.
Please feel free to post to the discuss.ocaml.org forum with any questions you have about this action.
Previous discussions include: