OPAM 1.2 and Travis CI
The new pinning feature of OPAM 1.2 enables new interesting workflows for your day-to-day development in OCaml projects. I will briefly describe one of them here: simplifying continuous testing with Travis CI and GitHub.
Creating an opam
file
As explained in the previous post, adding an opam
file at the
root of your project now lets you pin development versions of your
project directly. It's very easy to create a default template with OPAM 1.2:
$ opam pin add <my-project-name> . --edit
[... follow the instructions ...]
That command should create a fresh opam
file; if not, you might
need to fix the warnings in the file by re-running the command. Once
the file is created, you can edit it directly and use opam lint
to
check that is is well-formed.
If you want to run tests, you can also mark test-only dependencies with the
{test}
constraint, and add a build-test
field. For instance, if you use
oasis
and ounit
, you can use something like:
build: [
["./configure" "--prefix=%{prefix}%" "--%{ounit:enable}%-tests"]
[make]
]
build-test: [make "test"]
depends: [
...
"ounit" {test}
...
]
Without the build-test
field, the continuous integration scripts
will just test the compilation of your project for various OCaml
compilers.
OPAM doesn't run tests by default, but you can make it do so by
using opam install -t
or setting the OPAMBUILDTEST
environment variable in your local setup.
Installing the Travis CI scripts
Travis CI is a free service that enables continuous testing on your GitHub projects. It uses Ubuntu containers and runs the tests for at most 50 minutes per test run.
To use Travis CI with your OCaml project, you can follow the instructions on https://github.com/ocaml/ocaml-travisci-skeleton. Basically, this involves:
- adding
.travis.yml
at the root of your project. You can tweak this file to test your
project with different versions of OCaml. By default, it will use
the latest stable version (today: 4.02.1, but it will be updated for
each new compiler release). For every OCaml version that you want to
test (supported values for
<VERSION>
are3.12
,4.00
,4.01
and4.02
) add the line:
env:
- OCAML_VERSION=<VERSION>
- signing in at TravisCI using your GitHub account and
enabling the tests for your project (click on the
+
button on the left pane).
And that's it, your project now has continuous integration, using the OPAM 1.2 pinning feature and Travis CI scripts.
Testing Optional Dependencies
By default, the script will not try to install the optional
dependencies specified in your opam
file. To do so, you
need to manually specify which combination of optional dependencies
you want to tests using the DEPOPTS
environment variable. For
instance, to test cohttp
first with lwt
, then with async
and
finally with both lwt
and async
(but only on the 4.01
compiler)
you should write:
env:
- OCAML_VERSION=latest DEPOPTS=lwt
- OCAML_VERSION=latest DEPOPTS=async
- OCAML_VERSION=4.01 DEPOPTS="lwt async"
As usual, your contributions and feedback on this new feature are gladly welcome.
About OCamlPro:
OCamlPro is a R&D lab founded in 2011, with the mission to help industrial users benefit from experts with a state-of-the-art knowledge of programming languages theory and practice.
- We provide audit, support, custom developer tools and training for both the most modern languages, such as Rust, Wasm and OCaml, and for legacy languages, such as COBOL or even home-made domain-specific languages;
- We design, create and implement software with great added-value for our clients. High complexity is not a problem for our PhD-level experts. For example, we helped the French Income Tax Administration re-adapt and improve their internally kept M language, we designed a DSL to model and express revenue streams in the Cinema Industry, codename Niagara, and we also developed the prototype of the Tezos proof-of-stake blockchain from 2014 to 2018.
- We have a long history of creating open-source projects, such as the Opam package manager, the LearnOCaml web platform, and contributing to other ones, such as the Flambda optimizing compiler, or the GnuCOBOL compiler.
- We are also experts of Formal Methods, developing tools such as our SMT Solver Alt-Ergo (check our Alt-Ergo Users' Club) and using them to prove safety or security properties of programs.
Please reach out, we'll be delighted to discuss your challenges: contact@ocamlpro.com or book a quick discussion.
Most Recent Articles
2024
- opam 2.3.0 release!
- Optimisation de Geneweb, 1er logiciel français de Généalogie depuis près de 30 ans
- Alt-Ergo 2.6 is Out!
- Flambda2 Ep. 3: Speculative Inlining
- opam 2.2.0 release!
- Flambda2 Ep. 2: Loopifying Tail-Recursive Functions
- Fixing and Optimizing the GnuCOBOL Preprocessor
- OCaml Backtraces on Uncaught Exceptions
- Opam 102: Pinning Packages
- Flambda2 Ep. 1: Foundational Design Decisions
- Behind the Scenes of the OCaml Optimising Compiler Flambda2: Introduction and Roadmap
- Lean 4: When Sound Programs become a Choice
- Opam 101: The First Steps
2023
- Maturing Learn-OCaml to version 1.0: Gateway to the OCaml World
- The latest release of Alt-Ergo version 2.5.1 is out, with improved SMT-LIB and bitvector support!
- 2022 at OCamlPro
- Autofonce, GNU Autotests Revisited
- Sub-single-instruction Peano to machine integer conversion
- Statically guaranteeing security properties on Java bytecode: Paper presentation at VMCAI 23
- Release of ocplib-simplex, version 0.5