|
| 1 | +# Travis CI |
| 2 | + |
| 3 | +For many use cases, the |
| 4 | +[Travis caching section of the user guide](GUIDE.html#travis-with-caching) |
| 5 | +will be sufficient. |
| 6 | + |
| 7 | +This page documents how to use Stack on [Travis CI](https://travis-ci.org/). We |
| 8 | +assume you have basic familiarity with Travis. |
| 9 | + |
| 10 | +*Note:* both Travis and Stack infrastructures are actively developed. We try to |
| 11 | + document best practices at the moment. |
| 12 | + |
| 13 | +## Container infrastructure |
| 14 | + |
| 15 | +For Stack on Travis to be practical, we must use caching. Otherwise build times |
| 16 | +will take an incredibly long time, about 30 minutes versus 3-5. Caching is |
| 17 | +currently available only for |
| 18 | +[container-based Travis infrastructure](http://docs.travis-ci.com/user/workers/container-based-infrastructure/). |
| 19 | +Shortly we have to add |
| 20 | + |
| 21 | +```yaml |
| 22 | +sudo: false |
| 23 | + |
| 24 | +# Caching so the next build will be fast too. |
| 25 | +cache: |
| 26 | + directories: |
| 27 | + - $HOME/.stack |
| 28 | +``` |
| 29 | +
|
| 30 | +To the `.travis.yml`. This however restricts how we can install GHC and Stack on |
| 31 | +the Travis machines. |
| 32 | + |
| 33 | +## Installing Stack |
| 34 | + |
| 35 | +Currently there is only one reasonable way to install Stack: fetch precompiled |
| 36 | +binary from the Github. |
| 37 | + |
| 38 | +```yaml |
| 39 | +before_install: |
| 40 | +# Download and unpack the stack executable |
| 41 | +- mkdir -p ~/.local/bin |
| 42 | +- export PATH=$HOME/.local/bin:$PATH |
| 43 | +- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' |
| 44 | +``` |
| 45 | + |
| 46 | +Once Travis whitelists the stack .deb files, we'll be able to simply include |
| 47 | +stack in the `addons` section, and automatically use the newest version of |
| 48 | +stack, avoiding that complicated `before_install` section This is being |
| 49 | +tracked in the |
| 50 | +[apt-source-whitelist](https://github.com/travis-ci/apt-source-whitelist/pull/7) |
| 51 | +and |
| 52 | +[apt-package-whitelist](https://github.com/travis-ci/apt-package-whitelist/issues/379) |
| 53 | +issue trackers. |
| 54 | + |
| 55 | +## Installing GHC |
| 56 | + |
| 57 | +There are two ways to install GHC: |
| 58 | + |
| 59 | +- Let Stack download GHC |
| 60 | +- Install GHC using [apt plugin](http://docs.travis-ci.com/user/apt/) |
| 61 | + |
| 62 | +See the |
| 63 | +[Travis caching section of the user guide](GUIDE.html#travis-with-caching) for |
| 64 | +an example of the first option (letting Stack download GHC). Here, we will |
| 65 | +explain the second option. With single GHC the situation is simple: |
| 66 | + |
| 67 | +```yaml |
| 68 | +before_install: |
| 69 | + - export PATH=/opt/ghc/7.8.4/bin:$PATH |
| 70 | +
|
| 71 | +addons: |
| 72 | + apt: |
| 73 | + sources: |
| 74 | + - hvr-ghc |
| 75 | + packages: |
| 76 | + - ghc-7.10.2 |
| 77 | +``` |
| 78 | + |
| 79 | +### Multiple GHC - parametrised builds |
| 80 | + |
| 81 | +Travis apt plugin doesn't yet support installing apt packages dynamically |
| 82 | +(https://github.com/travis-ci/travis-ci/issues/4291). That for we need to write |
| 83 | +a bit repetetive `.travis.yml`. |
| 84 | + |
| 85 | +Also for different GHC versions, you probably want to use different `stack.yaml` |
| 86 | +files. |
| 87 | + |
| 88 | +```yaml |
| 89 | +# N.B. No top-level env: declaration! |
| 90 | +
|
| 91 | +matrix: |
| 92 | + include: |
| 93 | + - env: GHCVER=7.8.4 STACK_YAML=stack.yaml |
| 94 | + addons: |
| 95 | + apt: |
| 96 | + sources: |
| 97 | + - hvr-ghc |
| 98 | + packages: |
| 99 | + - ghc-7.8.4 |
| 100 | + - env: GHCVER=7.10.1 STACK_YAML=stack-7.10.yaml |
| 101 | + addons: |
| 102 | + apt: |
| 103 | + sources: |
| 104 | + - hvr-ghc |
| 105 | + packages: |
| 106 | + - ghc-7.10.1 |
| 107 | + - env: GHCVER=head STACK_YAML=stack-head.yaml |
| 108 | + addons: |
| 109 | + apt: |
| 110 | + sources: |
| 111 | + - hvr-ghc |
| 112 | + packages: |
| 113 | + - ghc-head |
| 114 | + allow_failures: |
| 115 | + - env: GHCVER=head STACK_YAML=stack-head.yaml |
| 116 | +
|
| 117 | +before_install: |
| 118 | + # ghc |
| 119 | + - export PATH=/opt/ghc/$GHCVER/bin:$PATH |
| 120 | +``` |
| 121 | + |
| 122 | +Especially to use ghc `HEAD` you need to pass `--skip-ghc-check` option to Stack. |
| 123 | + |
| 124 | +## Running tests |
| 125 | + |
| 126 | +After the environment setup, actual test running is simple: |
| 127 | + |
| 128 | +```yaml |
| 129 | +script: |
| 130 | + - stack --no-terminal --skip-ghc-check test |
| 131 | +``` |
| 132 | + |
| 133 | +## Other details |
| 134 | + |
| 135 | +Some Stack commands will run for long time (when cache is cold) without |
| 136 | +producing any output. For Travis not to timeout, one can wrap commands in |
| 137 | +[a simple script](https://github.com/futurice/fum2github/blob/master/travis_long). |
| 138 | + |
| 139 | +```yaml |
| 140 | +install: |
| 141 | + - ./travis_long stack --no-terminal --skip-ghc-check setup |
| 142 | + - ./travis_long stack --no-terminal --skip-ghc-check test --only-snapshot |
| 143 | +``` |
| 144 | + |
| 145 | +## Examples |
| 146 | + |
| 147 | +- [futurice/fum2github](https://github.com/futurice/fum2github/blob/master/.travis.yml) |
| 148 | +- [haskell-distributed/cloud-haskell](https://github.com/haskell-distributed/cloud-haskell/blob/master/.travis.yml) |
| 149 | +- [simonmichael/hledger](https://github.com/simonmichael/hledger/blob/master/.travis.yml) |
| 150 | +- [fpco/wai-middleware-crowd](https://github.com/fpco/wai-middleware-crowd/blob/master/.travis.yml) |
| 151 | +- [commercialhaskell/all-cabal-hashes-tool](https://github.com/commercialhaskell/all-cabal-hashes-tool/blob/master/.travis.yml) |
0 commit comments