GitHub Actions for OCaml / opam now available

I was in the GitHub Actions beta program and forward ported my code to the latest version that just went public. It’s a pretty simple way to get your OCaml code tested on Linux, macOS and Windows, without requiring an external CI service. The action attempts to provide a homogenous interface across all three operating systems, so invoking ‘opam’ from subsequent actions should “just work”.

You can find it here:

This should be considered fairly experimental as GH Actions is so new. If you do use it, then consider updating this issue with your usage. It does not current supporting caching yet, but is pretty fast to bootstrap (~4minutes).

It also doesn’t have any higher level purpose other than to set up an opam environment, since most of the additional functionality such as revdeps testing is planned for addition to the ocurrent DSL. Nevertheless, this GH feature will hopefully be useful for smaller projects without a lot of computational requirements. Let me know how it goes!

Windows is currently supported through @fdopen’s excellent fork that uses Cygwin. As Windows support is being mainlined into opam itself at the moment, I’m hoping that we will gradually move over to that. That should eventually remove the need for two separate opam-repositories, so I won’t be adding any features that are Linux or macOS-specific and do not work on the Cygwin version.

33 Likes

Thank you for publishing this. I’ve been able to migrate my smallish project entirely to github actions :slight_smile: While migrating to actions i’ve also been add a few things I didn’t have on travis (testing on mac + windows, testing formatting + creating automated PR)

1 Like

Glad to hear it! I’ll check out your improvements and see about folding them in :slight_smile:

2 Likes

Is it a substitute for https://github.com/ocaml/ocaml-ci-scripts? Which one should be used by the new projects?

Thank you so much. The action and code you provide completely unblocked me.
I now have a nice CI for my little project.

1 Like

They’re still slightly orthogonal, as ocaml-ci-scripts cover many more Linux distributions via the Docker support. I’ve still not decided whether or not it makes sense to include Docker support into the GH Actions scripts or not.

I did the same thing a while ago https://github.com/fangyi-zhou/actions-ocaml, but didn’t have the windows support.
I was thinking about adding cache to the .opam directory to shorten the build time, but didn’t have time to look into the provided APIs. I think that’ll be a useful feature to have.

Because Travis CI is dying (or walking dead already) I opened an issue in ocaml-ci-scripts to drop its support and switch or just mention these GitHub Actions instead: #353.

4 Likes

Fantastic work @avsm I’ve been porting my CI across from travis to both GH and CircleCI. This looks really useful.

The link to GitHub marketplace should be: Set up OCaml · Actions · GitHub Marketplace · GitHub

1 Like

I would also recommend setting up dependabot to check the versions of the GitHub actions you are using.
Something like this will check you are using the latest version of each action within the build OCaml CI:

version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"
    commit-message:
      prefix: "GA"
      include: "scope"
    labels:
      - "OCaml CI"
2 Likes

Cool. It is enough to add that snippet in the workflow file? Or can you point me to the relevant documentario? :stuck_out_tongue:

Dependabot supports GitHub Actions, but that support is pretty fragile. In general, if you are using the major version style (e.g. @v1, @v2), they should prioritize the major version style, but it will force you to change to the semver style (e.g. v1.0.0, v2.0.0) even if you are using the major version style.
It’s not good in setup-ocaml as described in the documentation: GitHub - avsm/setup-ocaml: GitHub Action for the OCaml programming language

3 Likes

This is great work. I was wondering whether there are any plans to support even more output of the sophisticated GitHub actions – a brief look into what Coq projects are doing (e.g. fiat) displaying comments and warnings from the compiler – something like that (including eventually “ocamlformat”) would be amazing. I’ve no clue what is involved / how to set this up, but eventually someone else is already deep in GitHub actions yaml / json land and could provide some recipes? :wink:

1 Like

If you are using dune, you should be able to use the matcher in the repository in the same way. Also, we can include them in setup-ocaml by default. (It has been planned for a long time and I’m planning to work on it once the review of setup-ocaml v2 is finished.)

2 Likes

that sounds great :slight_smile: yes, I mainly use dune - is there an example on “able to use the matcher in the repository in the same way” (I’ve no clue what I need to do for this - likely edit something in .github/)?

Yes! Just tweak the contents of the directory .github and add it to the same directory of the repository you want to use.

1 Like

I just released the first v2 alpha release.

1 Like