|
| 1 | +# This file is heavily inspired by these pages: |
| 2 | +# - https://circleci.com/docs/2.0/language-haskell/ |
| 3 | +# - https://circleci.com/blog/publishing-to-github-releases-via-circleci/ |
| 4 | +# |
| 5 | +version: 2 |
| 6 | +jobs: |
| 7 | + build-test-and-publish: |
| 8 | + docker: |
| 9 | + - image: fpco/stack-build-small:lts |
| 10 | + - image: postgres:11-alpine |
| 11 | + environment: |
| 12 | + POSTGRES_DB: postgres_ws_test |
| 13 | + POSTGRES_USER: root |
| 14 | + steps: |
| 15 | + - checkout |
| 16 | + - restore_cache: |
| 17 | + name: Restore Cached Dependencies |
| 18 | + keys: |
| 19 | + - postgres-websockets-v1-{{ checksum "postgres-websockets.cabal" }} |
| 20 | + - run: |
| 21 | + name: Install curl |
| 22 | + command: apt-get update && apt-get -qq -y install curl libpq-dev |
| 23 | + - run: |
| 24 | + name: Download and run hlint |
| 25 | + command: curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s . |
| 26 | + - run: |
| 27 | + name: Download ghr |
| 28 | + command: | |
| 29 | + curl -sSLO https://github.com/tcnksm/ghr/releases/download/v0.12.0/ghr_v0.12.0_linux_386.tar.gz |
| 30 | + curl -sSLO https://github.com/tcnksm/ghr/releases/download/v0.12.0/v0.12.0_SHASUMS |
| 31 | + sha256sum --check --ignore-missing v0.12.0_SHASUMS |
| 32 | + tar --strip-components=1 -zxvf ghr_v0.12.0_linux_386.tar.gz ghr_v0.12.0_linux_386/ghr |
| 33 | + - run: |
| 34 | + name: Resolve and update dependencies |
| 35 | + command: stack setup |
| 36 | + - run: |
| 37 | + name: Build the dependencies and the library |
| 38 | + command: stack --silent build |
| 39 | + - run: |
| 40 | + name: Run tests |
| 41 | + command: stack test |
| 42 | + - run: |
| 43 | + name: Install executable |
| 44 | + command: stack --silent install |
| 45 | + - run: |
| 46 | + name: Calculate and save checksum |
| 47 | + command: sha256sum ~/.local/bin/postgres-websockets > /root/postgres-websockets.sha256 |
| 48 | + - save_cache: |
| 49 | + name: Cache Dependencies |
| 50 | + key: postgres-websockets-v1-{{ checksum "postgres-websockets.cabal" }} |
| 51 | + paths: |
| 52 | + - ".stack" |
| 53 | + - ".stack-work" |
| 54 | + - run: |
| 55 | + name: Publish Release on GitHub |
| 56 | + command: | |
| 57 | + mkdir /root/result/ |
| 58 | + cp /root/postgres-websockets.sha256 /root/.local/bin/postgres-websockets /root/result/ |
| 59 | + VERSION=$(awk '/^version: / { print $2 };' < postgres-websockets.cabal) |
| 60 | + ./ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} /root/result/ |
| 61 | +
|
| 62 | +workflows: |
| 63 | + version: 2 |
| 64 | + main: |
| 65 | + jobs: |
| 66 | + - build-test-and-publish: |
| 67 | + filters: |
| 68 | + branches: |
| 69 | + only: master |
| 70 | + tags: |
| 71 | + only: /^[\d.]+$/ |
0 commit comments