Skip to content

Commit

Permalink
Enable CircleCI builds
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Feb 28, 2018
1 parent 6e45e4d commit f908115
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 8 deletions.
119 changes: 119 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
version: 2.0
jobs:
build:
working_directory: ~/project
docker:
- image: quay.io/haskell_works/stack-build-cabal:2018-01-29

steps:
- checkout

##### Copying scripts
- run:
name: Copying scripts
command: |
mkdir -p ~/.local/bin
cp ./scripts/* ~/.local/bin
##### Updating cabval package list
- run:
name: Updating cabal package list date stamp
command: date +%F > dot-cabal-cache-date

- restore_cache:
keys:
- dot-cabal-{{ checksum "dot-cabal-cache-date" }}
- dot-cabal

- run:
name: Updating cabal package list
command: cabal update

- save_cache:
key: dot-cabal-{{ checksum "dot-cabal-cache-date" }}
paths:
- ~/.cabal
- save_cache:
key: dot-cabal
paths:
- ~/.cabal

##### Building library
- restore_cache:
keys:
- dot-stack-{{ checksum "stack.yaml" }}-{{ checksum "package.yaml" }}
- dot-stack-{{ checksum "stack.yaml" }}-build
- dot-stack-{{ checksum "stack.yaml" }}-setup

##### Fetching latest organisation package versions
- run:
name: Fetching latest organisation package versions
command: |
fetch
echo "== stack-ci.yaml =="
cat stack-ci.yaml
- restore_cache:
key: dot-stack-work-{{ checksum "stack.yaml" }}

- run:
name: Stack setup
command: stack setup

- save_cache:
key: dot-stack-{{ checksum "stack.yaml" }}-setup
paths:
- ~/.stack

- run:
name: Building dependencies
command: stack --stack-yaml stack-ci.yaml build --only-dependencies

- run:
name: Compiling
command: stack --stack-yaml stack-ci.yaml build --test --no-run-tests

- save_cache:
key: dot-stack-{{ checksum "stack.yaml" }}-{{ checksum "package.yaml" }}
paths:
- ~/.stack
- save_cache:
key: dot-stack-{{ checksum "stack.yaml" }}-build
paths:
- ~/.stack

- save_cache:
key: dot-stack-work-{{ checksum "stack.yaml" }}
paths: ~/project/.stack-work

##### Running tests
- run:
name: Running tests against latest on hackage
command: stack --stack-yaml stack-ci.yaml test

- deploy:
command: |
if [ "$CIRCLE_PROJECT_USERNAME" == "haskell-works" ]; then
if [[ "$CIRCLE_BRANCH" == master ]]; then
when tag autotag
elif [[ "$CIRCLE_TAG" =~ v.* ]]; then
publish
fi
fi
workflows:
version: 2
un-tagged-build:
jobs:
- build:
filters:
tags:
ignore: /^v.*/
tagged-build:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
30 changes: 27 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
.stack-work/
bits-extra.cabal
*~
dist
dist-newstyle
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp

/*.submodules
/.stack-work/
/result
/deps
/data
/*.json
/*.json.ib
/*.json.bp
/snapshot.yaml
/stack-ci.yaml
65 changes: 65 additions & 0 deletions bits-extra.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- This file has been generated from package.yaml by hpack version 0.20.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 8d7819db83540e115415947ac8394d40c7fb84df4c06d935ab3ddf02cd743bff

name: bits-extra
version: 0.0.0.1
description: Please see the README on Github at <https://github.com/githubuser/bits-extra#readme>
homepage: https://github.com/githubuser/bits-extra#readme
bug-reports: https://github.com/githubuser/bits-extra/issues
author: John Ky
maintainer: newhoggy@gmail.com
copyright: 2018 John Ky
license: BSD3
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10

extra-source-files:
ChangeLog.md
README.md

source-repository head
type: git
location: https://github.com/githubuser/bits-extra

library
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, hw-prim
exposed-modules:
Lib
other-modules:
Paths_bits_extra
default-language: Haskell2010

executable bits-extra-exe
main-is: Main.hs
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, bits-extra
, hw-prim
other-modules:
Paths_bits_extra
default-language: Haskell2010

test-suite bits-extra-test
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, bits-extra
, hw-prim
other-modules:
Paths_bits_extra
default-language: Haskell2010
8 changes: 4 additions & 4 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: bits-extra
version: 0.1.0.0
version: 0.0.0.1
github: "githubuser/bits-extra"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2018 Author name here"
author: "John Ky"
maintainer: "newhoggy@gmail.com"
copyright: "2018 John Ky"

extra-source-files:
- README.md
Expand Down
39 changes: 39 additions & 0 deletions scripts/autotag
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

if [ "$_system_type" == "Darwin" ]; then
sed () {
gsed "$@"
}
fi

_repo_name=$(basename `git rev-parse --show-toplevel`)

_version="$(cat package.yaml | grep '^version:' | head -n 1 | cut -d : -f 2 | xargs)"

_branch=$(git rev-parse --abbrev-ref HEAD)
_branch_prefix=${_branch%-branch}

if [[ $(git ls-remote origin "refs/tags/v$_version") ]]; then
echo "The tag v$_version already exists. Will not tag"
exit 0
fi

_commit=$(git rev-parse --verify HEAD)

_release_data=$(cat <<EOF
{
"tag_name": "v$_version",
"target_commitish": "$_commit",
"name": "v$_version",
"body": "New release",
"draft": false,
"prerelease": false
}
EOF
)

echo "Creating release v$_version from commit $_commit in branch $_branch"

curl -H "Authorization: token $GITHUB_TOKEN" \
-X POST https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/releases \
--data "$_release_data"
38 changes: 38 additions & 0 deletions scripts/fetch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

stack query

cabal update

mkdir -p deps

_project="$(cat package.yaml | grep '^name:' | head -n 1 | cut -d : -f 2 | xargs)"

direct_deps() {
cat ../package.yaml | grep '# \+use-latest-in-ci' | cut -d '#' -f 1 | sed 's|^ *- *||g' | sed 's| .*$||g'
}

pushd deps > /dev/null

cp ../$_project.cabal ./

projects() {
for x in $(direct_deps | sort | uniq); do
cabal install $x --dry-run | grep -v "^${_project}-[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+$" | tail -n 1
done
}

if grep '^ *# extra-deps-insertion-point' ../stack.yaml; then
_indent="$(grep '^ *# extra-deps-insertion-point' ../stack.yaml | head -n 1 | cut -d '#' -f 1 | tr -d '\n')"
projects | sort | uniq | sed "s|^|$_indent- |g" > stack-b.yaml
grep '^ *# extra-deps-insertion-point' -B 1000 ../stack.yaml > stack-a.yaml
grep '^ *# extra-deps-insertion-point' -A 1000 ../stack.yaml | grep -v '^ *# extra-deps-insertion-point' > stack-c.yaml
else
cp ../stack.yaml stack-a.yaml
rm -f stack-b.yaml; touch stack-b.yaml
echo > stack-c.yaml
fi

cat stack-a.yaml stack-b.yaml stack-c.yaml > ../stack-ci.yaml

popd > /dev/null
33 changes: 33 additions & 0 deletions scripts/publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

if [ "$_system_type" == "Darwin" ]; then
sed () {
gsed "$@"
}
fi

if [ "$HACKAGE_USER" == "" ] || [ "$HACKAGE_PASS" == "" ]; then
echo "Must supply credentials"
exit 1
fi

_repo_name=$(basename `git rev-parse --show-toplevel`)
_project="$(cat package.yaml | grep '^name:' | head -n 1 | cut -d : -f 2 | xargs)"
_version="$(cat package.yaml | grep '^version:' | head -n 1 | cut -d : -f 2 | xargs)"

if [ "v$_version" != "$CIRCLE_TAG" ]; then
echo "Tag mismatch: "v$_version != $CIRCLE_TAG""
exit 1
fi

cabal configure

cabal sdist

if [ "$ALLOW_UPLOAD" != "" ]; then
cabal upload \
--username=$HACKAGE_USER \
--password=$HACKAGE_PASS \
"dist/${_project}-${_version}.tar.gz" \
${PUBLISH+--publish}
fi
9 changes: 9 additions & 0 deletions scripts/setup-cred
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

cred=~/.stack/upload/credentials.json
if [ ! -f "${cred}" ]; then
if [ ! -e ~/.stack/upload ]; then
mkdir -p ~/.stack/upload
fi
echo "{\"username\":\"${HACKAGE_USER}\",\"password\":\"${HACKAGE_PASS}\"}" > ${cred}
fi
Loading

0 comments on commit f908115

Please sign in to comment.