From cad6111054e1d71293717337296a32c92deaaed7 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Thu, 4 Jun 2020 19:00:08 +0100 Subject: [PATCH] Move to Travis CI and add deploy script (#24) * Use travis CI * Remove .github --- .github/workflows/main.yml | 15 --------------- .travis.yml | 22 ++++++++++++++++++++++ tools/attach-binary.sh | 22 ++++++++++++++++++++++ tools/install-ghr.sh | 20 ++++++++++++++++++++ tools/install-stack.sh | 17 +++++++++++++++++ 5 files changed, 81 insertions(+), 15 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 .travis.yml create mode 100755 tools/attach-binary.sh create mode 100755 tools/install-ghr.sh create mode 100755 tools/install-stack.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 18218a1..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: CI - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: Run stack build - run: stack build - - name: Run stack test - run: stack test diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2647be0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +addons: + apt: + packages: + - libgmp-dev +language: c +sudo: false +cache: + directories: + - $HOME/.local/bin + - $HOME/.stack +os: +- linux +- osx +before_install: +- sh tools/install-stack.sh +- sh tools/install-ghr.sh +script: +- stack setup +- stack test +- stack build --ghc-options -O2 --pedantic +after_success: +- sh tools/attach-binary.sh diff --git a/tools/attach-binary.sh b/tools/attach-binary.sh new file mode 100755 index 0000000..aa857b5 --- /dev/null +++ b/tools/attach-binary.sh @@ -0,0 +1,22 @@ +set -o errexit -o verbose + +if 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 "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 diff --git a/tools/install-ghr.sh b/tools/install-ghr.sh new file mode 100755 index 0000000..d8f6621 --- /dev/null +++ b/tools/install-ghr.sh @@ -0,0 +1,20 @@ +set -o errexit -o verbose + +if 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 diff --git a/tools/install-stack.sh b/tools/install-stack.sh new file mode 100755 index 0000000..3bd667b --- /dev/null +++ b/tools/install-stack.sh @@ -0,0 +1,17 @@ +set -o errexit -o verbose + +if test -f "$HOME/.local/bin/stack" +then + echo 'Stack is already installed.' +else + echo "Installing Stack for $TRAVIS_OS_NAME..." + URL="https://www.stackage.org/stack/$TRAVIS_OS_NAME-x86_64" + curl --location "$URL" > stack.tar.gz + gunzip stack.tar.gz + tar -x -f stack.tar --strip-components 1 + mkdir -p "$HOME/.local/bin" + mv stack "$HOME/.local/bin/" + rm stack.tar +fi + +stack --version