marc walter

Installing all Elm dependencies on a CI system


When configuring a CI pipeline for an Elm project, we ran into a couple of issues: The first problem was that the build step (which executes elm make) sometimes failed because downloading the Elm packages failed.
And the second one was that we were not able to easily cache the dependencies between runs in ~/.elm.

A failing pipeline is definitely annoying, and even more so if it looks like invalid code was pushed, if in fact only downloading dependencies failed because the package server is not reachable.

How we solved it:

First we changed the folder where all dependencies are downloaded to using the ELM_HOME environment variable. This allows the CI system to persist the cache easily, without needing access to ~/.elm. So the dependencies only need to get downloaded once and are then cached.

Then we faked a command to install all Elm dependencies. For that we created a minimal Elm file, compiled it (which downloads missing dependencies even though they are not used), and then removed it again.

As a simple script:

export ELM_HOME=elm-stuff/home

# create an Elm source file that definitely will compile
printf 'module InstallElmDeps exposing (main)\nimport Html exposing (text)\n\nmain = text "install"\n' > src/InstallElmDeps.elm
# run the compiler without output
elm make src/InstallElmDeps.elm --output /dev/null
# remove the file
rm src/InstallElmDeps.elm