|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +# Determine the Haskell package we're building. |
| 6 | +PACKAGE=$(echo "$TRAVIS_REPO_SLUG" | sed -e 's|^[^/]*/hs-||') |
| 7 | + |
| 8 | +# Usage: bash <(curl -s https://raw.githubusercontent.com/TokTok/hs-tools/master/bin/travis-haskell) script |
| 9 | +travis-script() { |
| 10 | + # Install the latest CI support tools. |
| 11 | + VERSION=$(curl -L -s -H 'Accept: application/json' \ |
| 12 | + "https://github.com/TokTok/hs-tools/releases/latest" \ |
| 13 | + | egrep -o '"v[0-9][^"]+"' \ |
| 14 | + | egrep -o '[^"]+') |
| 15 | + TOOLS_URL="https://github.com/Toktok/hs-tools/releases/download/$VERSION/hs-tools-$VERSION.tar.gz" |
| 16 | + curl -L -s "$TOOLS_URL" | tar xz -C "$HOME" |
| 17 | + |
| 18 | + # Where to find libraries. |
| 19 | + export LD_LIBRARY_PATH=$HOME/.local/lib |
| 20 | + export PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig |
| 21 | + |
| 22 | + NEED_SODIUM=$(stack ls dependencies --test | grep saltine > /dev/null && echo 1) |
| 23 | + NEED_TOXCORE=$(grep 'extra-libraries:.*toxcore' *.cabal > /dev/null && echo 1) |
| 24 | + |
| 25 | + if [ -n "$NEED_SODIUM" ]; then |
| 26 | + NEED_TOXCORE=1 |
| 27 | + fi |
| 28 | + |
| 29 | + # libsodium |
| 30 | + if [ "$NEED_SODIUM" == 1 -a ! -f $HOME/.local/lib/libsodium.so ]; then |
| 31 | + git clone --depth=1 --branch=stable https://github.com/jedisct1/libsodium |
| 32 | + cd libsodium |
| 33 | + ./configure --prefix=$HOME/.local |
| 34 | + make install -j$(nproc) |
| 35 | + fi |
| 36 | + |
| 37 | + # c-toxcore |
| 38 | + if [ "$NEED_SODIUM" == 1 -a ! -f $HOME/.local/lib/libtoxcore.so ]; then |
| 39 | + git clone --depth=1 https://github.com/TokTok/c-toxcore |
| 40 | + cd c-toxcore |
| 41 | + cmake -B_build -H. -DCMAKE_INSTALL_PREFIX:PATH=$HOME/.local \ |
| 42 | + -DBUILD_TOXAV=OFF \ |
| 43 | + -DBOOTSTRAP_DAEMON=OFF \ |
| 44 | + -DAUTOTEST=OFF \ |
| 45 | + -DDHT_BOOTSTRAP=OFF |
| 46 | + make -C_build install -j$(nproc) |
| 47 | + fi |
| 48 | + |
| 49 | + # Run the build/test/deploy (optional) cycle. |
| 50 | + hlint . |
| 51 | + stylish-haskell-lhs -i . |
| 52 | + git diff --exit-code |
| 53 | + stack --no-terminal test --coverage \ |
| 54 | + --extra-include-dirs=$HOME/.local/include \ |
| 55 | + --extra-lib-dirs=$HOME/.local/lib |
| 56 | + shc "$PACKAGE" testsuite |
| 57 | + stack sdist --tar-dir . |
| 58 | +} |
| 59 | + |
| 60 | +# Usage: eval $(travis-haskell env) |
| 61 | +travis-env() { |
| 62 | + # Check that the tag we're building and trying to release agrees with the |
| 63 | + # version number in Cabal. |
| 64 | + if [ -n "$TRAVIS_TAG" ]; then |
| 65 | + VERSION="${TRAVIS_TAG/v/}" |
| 66 | + if [ ! -f "$PACKAGE-$VERSION.tar.gz" ]; then |
| 67 | + echo 'echo "Package versions or name mismatch"' |
| 68 | + echo 'ls' |
| 69 | + echo 'exit 1' |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + else |
| 73 | + VERSION="" |
| 74 | + fi |
| 75 | + |
| 76 | + # Export variables here to make them available in the deploy step. |
| 77 | + cat <<EOF |
| 78 | +export PACKAGE="$PACKAGE" |
| 79 | +export VERSION="$VERSION" |
| 80 | +EOF |
| 81 | +} |
| 82 | + |
| 83 | +# Usage: travis-haskell deploy |
| 84 | +travis-deploy() { |
| 85 | + # No "set -x" here, because we don't want to print the username/password on the |
| 86 | + # Travis console. |
| 87 | + set +x |
| 88 | + |
| 89 | + mkdir -p "$HOME/.stack/upload" |
| 90 | + echo "{\"username\":\"$HACKAGE_USERNAME\",\"password\":\"$HACKAGE_PASSWORD\"}" \ |
| 91 | + > "$HOME/.stack/upload/credentials.json" |
| 92 | + stack --no-terminal upload . |
| 93 | +} |
| 94 | + |
| 95 | +travis-$1 |
0 commit comments