Skip to content

Commit

Permalink
CCI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyRaga committed Jun 15, 2018
1 parent 75ab6b0 commit af345fe
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 47 deletions.
101 changes: 101 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
defaults: &defaults
working_directory: ~/build
docker:
- image: quay.io/haskell_works/stack-build-cabal

# - image: confluentinc/cp-zookeeper:3.1.2
# environment:
# ZOOKEEPER_CLIENT_PORT: 2181

# - image: confluentinc/cp-kafka:3.1.2
# environment:
# KAFKA_ZOOKEEPER_CONNECT: "localhost:2181"
# KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://localhost:9092"
# KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

steps:
- checkout

- restore_cache:
keys:
- dot-stack-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.yaml" }}
- dot-stack-{{ arch }}-{{ .Environment.CIRCLE_JOB }}

- restore_cache:
key: stack-work-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.yaml" }}

- run: stack setup --resolver ${LTS} ${STACK_ARGS}
- run: stack build --test --no-run-tests --haddock --no-haddock-deps --resolver ${LTS} ${STACK_ARGS}

- save_cache:
key: dot-stack-{{ arch }}-{{ .Environment.CIRCLE_JOB }}
paths:
- ~/.stack

- run:
name: Running unit tests
command: stack test --resolver ${LTS} ${STACK_ARGS}

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

- save_cache:
key: stack-work-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package.yaml" }}
paths: ~/build/.stack-work

version: 2.0
jobs:
lts-7:
environment:
- LTS: "lts-7"
<<: *defaults

lts-9:
environment:
- LTS: "lts-9"
<<: *defaults

lts-11:
environment:
- LTS: "lts-11"
<<: *defaults

nightly:
environment:
- LTS: "nightly"
- STACK_ARGS: "--stack-yaml=stack-nightly.yaml"
<<: *defaults

release:
working_directory: ~/build
docker:
- image: quay.io/haskell_works/stack-build-cabal

steps:
- checkout

- run:
name: Making a release
command: ./scripts/release


workflows:
version: 2
multiple-ghcs:
jobs:
# - lts-7
- lts-9
- lts-11
# - nightly
- release:
requires:
# - lts-7
- lts-9
- lts-11
# - nightly
filters:
branches:
only: master

41 changes: 0 additions & 41 deletions circle.yml

This file was deleted.

47 changes: 47 additions & 0 deletions scripts/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

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

_version=$(cat package.yaml | grep -i -e "^version:" | 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"

set -x

_release=$(
curl -H "Authorization: token $GITHUB_TOKEN" \
-X POST https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/releases \
--data "$_release_data"
)

_release_id=$(
echo "$_release" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=' | cut -d '=' -f 2
)

echo "Released on GitHub as as v$_version"
13 changes: 9 additions & 4 deletions src/Kafka/Avro/SchemaRegistry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Kafka.Avro.SchemaRegistry
) where

import Control.Arrow (first)
import Control.Lens (view, (^.))
import Control.Lens (view, (&), (.~), (^.))
import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Aeson
Expand Down Expand Up @@ -80,10 +80,15 @@ sendSchema sr subj sc = do

------------------ PRIVATE: HELPERS --------------------------------------------

wreqOpts :: Wreq.Options
wreqOpts =
let accept = ["application/vnd.schemaregistry.v1+json", "application/vnd.schemaregistry+json", "application/json"]
in Wreq.defaults & Wreq.header "Accept" .~ accept

getSchemaById :: String -> SchemaId -> IO (Either SchemaRegistryError RegisteredSchema)
getSchemaById baseUrl sid@(SchemaId i) = do
let schemaUrl = baseUrl ++ "/schemas/ids/" ++ show i
resp <- Wreq.get schemaUrl
resp <- Wreq.getWith wreqOpts schemaUrl
pure $ bimap (const (SchemaRegistryLoadError sid)) (view Wreq.responseBody) (Wreq.asJSON resp)
where
wrapError :: SomeException -> SchemaRegistryError
Expand All @@ -95,8 +100,8 @@ getSchemaById baseUrl sid@(SchemaId i) = do

putSchema :: String -> Subject -> RegisteredSchema -> IO (Either SchemaRegistryError SchemaId)
putSchema baseUrl (Subject sbj) schema = do
let schemaUrl = baseUrl ++ "/subject/" ++ unpack sbj ++ "/versions"
resp <- Wreq.post schemaUrl (toJSON schema)
let schemaUrl = baseUrl ++ "/subjects/" ++ unpack sbj ++ "/versions"
resp <- Wreq.postWith wreqOpts schemaUrl (toJSON schema)
pure $ bimap wrapError (view Wreq.responseBody) (Wreq.asJSON resp)
where
wrapError :: SomeException -> SchemaRegistryError
Expand Down
17 changes: 17 additions & 0 deletions stack-nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resolver: nightly
allow-newer: true

packages:
- '.'

# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:
- avro-0.3.0.4
- pure-zlib-0.6.3

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []
4 changes: 2 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ packages:
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:
- avro-0.2.1.1
- pure-zlib-0.6
- avro-0.3.0.4
- pure-zlib-0.6.3

# Override default flag values for local packages and extra-deps
flags: {}
Expand Down

0 comments on commit af345fe

Please sign in to comment.