dwyl/learn-travis

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:

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
image

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)
image

With sysconfcpus: https://travis-ci.org/nelsonic/photo-groove/builds/324629892 (1 min 35 sec)
image

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