enable travis

This commit is contained in:
Sandy Maguire 2019-04-10 00:03:31 -04:00
parent 1d9e35d122
commit 0b627c9898
4 changed files with 120 additions and 0 deletions

45
.travis.yml Normal file
View File

@ -0,0 +1,45 @@
# Adapted from https://github.com/commercialhaskell/stack
language: c
sudo: false
cache:
directories:
- $HOME/.ghc
- $HOME/.cabal
- $HOME/.stack
- .stack-work
matrix:
include:
# ghc 8.6.3
- env: STACK='stack --resolver=lts-13.0' CACHE_NAME=8.6.3
addons: {apt: {packages: [libgmp-dev]}}
# Use the resolver in stack.yaml
- env: STACK=stack CACHE_NAME=stack-linux
addons: {apt: {packages: [libgmp-dev]}}
- env: STACK=stack CACHE_NAME=stack-osx
os: osx
addons: {apt: {packages: [libgmp-dev]}}
install:
- unset CC
- export PATH=$HOME/.local/bin:/opt/ghc/$GHCVER/bin:$PATH
- ./.travis/install-ghr.sh
- ./.travis/install-stack.sh
script:
- echo "$(stack ghc -- --version) [$(stack ghc -- --print-project-git-commit-id 2> /dev/null || echo '?')]"
- GHC_OPTIONS="-Werror"
- |
set -ex
$STACK --no-terminal build --ghc-options="$GHC_OPTIONS"
set +ex
after_success:
- |
# Build and ship binary
./.travis/attach-binary.sh

25
.travis/attach-binary.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
set -o errexit -o verbose
if test ! "$BUILD_BINARY" || test ! "$TRAVIS_TAG"
then
echo 'This is not a release build.'
elif test ! "$GITHUB_TOKEN"
then
echo 'The GITHUB_TOKEN environment variable is not set!'
exit 1
else
echo "Building binary for $TRAVIS_OS_NAME to $TRAVIS_TAG..."
stack build --ghc-options -O2 --pedantic
echo "Attaching binary for $TRAVIS_OS_NAME to $TRAVIS_TAG..."
OWNER="$(echo "$TRAVIS_REPO_SLUG" | cut -f1 -d/)"
REPO="$(echo "$TRAVIS_REPO_SLUG" | cut -f2 -d/)"
BIN="$(stack path --local-install-root)/bin/$REPO"
BUNDLE_NAME="$REPO-$TRAVIS_TAG-$TRAVIS_OS_NAME.tar.gz"
cp "$BIN" "./$REPO"
chmod +x "./$REPO"
tar -czf "$BUNDLE_NAME" "$REPO"
echo "SHA256:"
shasum -a 256 "$BUNDLE_NAME"
ghr -t "$GITHUB_TOKEN" -u "$OWNER" -r "$REPO" --replace "$(git describe --tags)" "$BUNDLE_NAME"
fi

21
.travis/install-ghr.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
set -o errexit -o verbose
if test ! "$BUILD_BINARY" || test ! "$TRAVIS_TAG"
then
echo 'This is not a release build.'
else
if [ "$TRAVIS_OS_NAME" = "linux" ]
then
ARCH="linux"
else
ARCH="darwin"
fi
echo "Installing ghr"
URL="https://github.com/tcnksm/ghr/releases/download/v0.5.4/ghr_v0.5.4_${ARCH}_386.zip"
curl -L ${URL} > ghr.zip
mkdir -p "$HOME/bin"
export PATH="$HOME/bin:$PATH"
unzip ghr.zip -d "$HOME/bin"
rm ghr.zip
fi

29
.travis/install-stack.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
# Adapted from https://github.com/commercialhaskell/stack
set -eux
travis_retry() {
cmd=$*
$cmd || (sleep 2 && $cmd) || (sleep 10 && $cmd)
}
fetch_stack_osx() {
curl -skL https://www.stackage.org/stack/osx-x86_64 | tar xz --strip-components=1 --include '*/stack' -C ~/.local/bin;
}
fetch_stack_linux() {
curl -sL https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack';
}
# We need stack to generate cabal files with precise bounds, even for cabal
# builds.
mkdir -p ~/.local/bin;
if [ "$(uname)" = "Darwin" ]; then
travis_retry fetch_stack_osx
else
travis_retry fetch_stack_linux
fi
travis_retry stack --no-terminal setup;