Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elm ? (How to do Continuous Integration with Travis-CI for Elm-lang projects) #31

Closed
nelsonic opened this issue Jan 3, 2018 · 5 comments

Comments

@nelsonic
Copy link
Member

nelsonic commented Jan 3, 2018

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.

@nelsonic
Copy link
Member Author

nelsonic commented Jan 3, 2018

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

@nelsonic
Copy link
Member Author

nelsonic commented Jan 3, 2018

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 ...

nelsonic added a commit to nelsonic/photo-groove that referenced this issue Jan 3, 2018
nelsonic added a commit to nelsonic/photo-groove that referenced this issue Jan 3, 2018
@nelsonic
Copy link
Member Author

nelsonic commented Jan 3, 2018

This is a very insightful thread if you want to know more about running Elm on CI:
elm/compiler#1473

@nelsonic
Copy link
Member Author

nelsonic commented Jan 3, 2018

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. 🥇

nelsonic added a commit to nelsonic/photo-groove that referenced this issue Jan 3, 2018
nelsonic added a commit to nelsonic/photo-groove that referenced this issue Jan 3, 2018
nelsonic added a commit to nelsonic/photo-groove that referenced this issue Jan 3, 2018
@nelsonic
Copy link
Member Author

nelsonic commented Jan 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant