Elm ? (How to do Continuous Integration with Travis-CI for Elm-lang projects)
nelsonic opened this issue ยท 5 comments
What is the bare minimum required in the .travis.yml
file to test an Elm project on Travis-CI?
Examples:
- https://github.com/elm-community/elm-test/blob/2.1.0/.travis.yml
- https://github.com/rtfeldman/elm-css/blob/master/.travis.yml
- https://github.com/elm-community/elm-time/blob/master/.travis.yml
The available examples include quite a lot of uncommented code ...
We need to clarify why each line exists so other people can understand the file.
The elm-time
.travis.yml
file appears to be the most simple:
https://github.com/elm-community/elm-time/blob/d7f786013ae92cf44752e8bb0d79354733a73f8d/.travis.yml#L1-L27
language: node_js
node_js: node
cache:
directories:
- elm-stuff/build-artifacts
- elm-stuff/packages
- test/elm-stuff/build-artifacts
- test/elm-stuff/packages
- sysconfcpus
before_install:
- if [ ${TRAVIS_OS_NAME} == "osx" ];
then brew update; brew install nvm; mkdir ~/.nvm; export NVM_DIR=~/.nvm; source $(brew --prefix nvm)/nvm.sh;
fi
- | # epic build time improvement - see https://github.com/elm-lang/elm-compiler/issues/1473#issuecomment-245704142
if [ ! -d sysconfcpus/bin ];
then
git clone https://github.com/obmarg/libsysconfcpus.git;
cd libsysconfcpus;
./configure --prefix=$TRAVIS_BUILD_DIR/sysconfcpus;
make && make install;
cd ..;
fi
install:
- npm install -g elm elm-test@0.18.6
I thought it looked "too simple" ... ๐
the elm-time
build is not actually running any tests ...
https://travis-ci.org/elm-community/elm-time/builds/324008461#L1135
So looks like we need a bit more detail ...
This is a very insightful thread if you want to know more about running Elm on CI:
elm/compiler#1473
Test https://travis-ci.org/nelsonic/photo-groove/jobs/324609782 ran for 19 minutes ... โณ ๐
Subsequent test: https://travis-ci.org/nelsonic/photo-groove/builds/324618841 took 2 mins.
then using elm/compiler#1473 (comment) (compiler CPU config script)
it goes down to: https://travis-ci.org/nelsonic/photo-groove/builds/324621112 1 minute. ๐ฅ
confirmed that libsysconfcpus
script is worth it. cuts build time by at least half.
Without sysconfcpus
: https://travis-ci.org/nelsonic/photo-groove/builds/324627709 (2 min 12 sec)
With sysconfcpus
: https://travis-ci.org/nelsonic/photo-groove/builds/324629892 (1 min 35 sec)
No elm code changed. (only .travis.yml
script)
Conclusion
The following .travis.yml
file is the "Bare Minimum" to run your Elm project on Travis-CI:
language: node_js # elm is installed from npm (see install below)
node_js: node # use "latest" version of Node.js
env:
- ELM_VERSION=0.18.0 ELM_TEST=0.18.12
cache:
directories: # so subsequent builds run faster
- elm-stuff/build-artifacts
- elm-stuff/packages
- tests/elm-stuff/build-artifacts # elm-test init creates a "tests/" dir
- tests/elm-stuff/packages # cache files that haven't changed
- sysconfcpus
- $HOME/.npm # https://stackoverflow.com/a/42523517/1148249
before_install:
- | # build time improvement see: https://git.io/vQcqz
if [ ! -d sysconfcpus/bin ];
then
git clone https://github.com/obmarg/libsysconfcpus.git;
cd libsysconfcpus;
./configure --prefix=$TRAVIS_BUILD_DIR/sysconfcpus;
make && make install;
cd ..;
fi
install: # install specific versions of elm & elm-test
- npm install -g elm@$ELM_VERSION elm-test@$ELM_TEST
# the next 3 lines are courtesy of @rtfeldman https://git.io/vbj0j
- mv $(npm config get prefix)/bin/elm-make $(npm config get prefix)/bin/elm-make-old
- printf "#\041/bin/bash\n\necho \"Running elm-make with sysconfcpus -n 2\"\n\n$TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 elm-make-old \"\$@\"" > $(npm config get prefix)/bin/elm-make
- chmod +x $(npm config get prefix)/bin/elm-make
- travis_retry elm package install --yes # install main project dependencies
script:
- elm-test --verbose
- If you want to run
elm-format
on your code before running the tests: https://github.com/nelsonic/photo-groove/blob/5f0de123b304ab6a55b9eba3cf717730d2e0c61c/.travis.yml - If you need to run your tests on OSX: https://github.com/nelsonic/photo-groove/blob/adfa150d0d45139d63a861a987c28f6e88ecbbe2/.travis.yml