CI setup
This page explains how to install Elm tools from elm-tooling.json in a Continuous Integration (CI) scenario, such as GitHub Actions.
See the Example GitHub Actions workflow for inspiration. Even if you don’t use GitHub Actions it’s still a good resource – there’s a lot of comments and the concepts and steps should be fairly similar regardless of what CI you use.
Basically, you need to:
-
Install npm packages, with
NO_ELM_TOOLING_INSTALLset. It’s nice to cachenode_modules(based on yourpackage.jsonandpackage-lock.json) for speed and reliability.Setting the
NO_ELM_TOOLING_INSTALLenvironment variable turnselm-tooling installinto a no-op, in case you have a"postinstall": "elm-tooling install"script in yourpackage.json. In CI it’s better to install npm packages andelm-tooling.jsontools separately so you can cachenode_modulesand~/.elmseparately. -
Install tools from
elm-tooling.json:npx elm-tooling install. Make sure that~/.elmis cached (orELM_HOMEif you’ve set it), based onelm.json(because it lists your Elm dependencies and the Elm compiler installs packages into~/.elm) andelm-tooling.json(because it lists your tools andelm-toolingdownloads them into~/.elm) as well asreview/elm.jsonif you use elm-review or whatever otherelm.jsonfiles you might have.Note that Windows uses
%APPDATA%\elmrather than~/.elm. If you need to run the same CI workflow both Windows and some other OS, setELM_HOMEto a directory that works everywhere. -
Run whatever commands you want.
mpizenberg/elm-tooling-action
mpizenberg/elm-tooling-action is a GitHub Action that:
- Contains its own copy of
elm-toolingand runselm-tooling installfor you. - Caches
~/.elmfor you (in a way that works on both Windows and other operating systems).
It’s primarily made for projects that don’t have a package.json (it’s up to every contributor to install Elm and elm-format etc themselves). Such projects still need to install the tools in CI somehow, and elm-tooling-action fits exactly that need.
You can use elm-tooling-action even if you have a package.json and have elm-tooling in there. But beware that you might not be running exactly the same version of elm-tooling locally and in CI! So if something works locally but not in CI (or vice versa), that could be the culprit. You don’t save super much YAML config by using the action in this case, so it’s currently not recommended. But you decide!