Skip to content

Commit

Permalink
add circleci and codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
linsheng.yu@okcoin.com committed Apr 10, 2020
1 parent d90293d commit 8c26893
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 1 deletion.
118 changes: 118 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
version: 2.1

commands:
make:
parameters:
description:
type: string
target:
type: string
steps:
- attach_workspace:
at: /tmp/bin
- restore_cache:
name: "Restore source code cache"
keys:
- go-src-v1-{{ .Revision }}
- checkout
- restore_cache:
name: "Restore go modules cache"
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: << parameters.description >>
command: |
export BINDIR=/tmp/bin
make << parameters.target >>
jobs:
build:
docker:
- image: circleci/golang:1.14
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
steps:
- checkout
- restore_cache:
name: Restore go modules cache
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Cache go modules
command: make go-mod-cache
- run:
name: Build
command: make build
- run:
name: Unit Test
command: make test-unit
- save_cache:
name: Save go modules cache
key: go-mod-v1-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- save_cache:
name: Save source code cache
key: go-src-v1-{{ .Revision }}
paths:
- ".git"
- run:
name: Run tests with coverage and upload codecov
command: |
set -ex
echo "--> Run tests with coverage:"
export VERSION="$(git describe --tags --long | sed 's/v\(.*\)/\1/')"
export GO111MODULE=on
mkdir -p /tmp/logs /tmp/workspace/profiles
for pkg in $(go list ./... | grep -v '/simulation' | circleci tests split); do
id=$(echo "$pkg" | sed 's|[/.]|_|g')
go test -mod=readonly -timeout 8m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic -tags='ledger test_ledger_mock' "$pkg" | tee "/tmp/logs/$id-$RANDOM.log"
done
echo "--> Gather coverage:"
ls /tmp/workspace/profiles/
echo "mode: atomic" > coverage.txt
for prof in $(ls /tmp/workspace/profiles/); do
tail -n +2 /tmp/workspace/profiles/"$prof" >> coverage.txt
done
echo "--> Filter out DONTCOVER:"
excludelist="$(find . -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/okex\/okchain/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
echo "--> upload codecov:"
bash <(curl -s https://codecov.io/bash) -f coverage.txt
# - persist_to_workspace:
# root: /tmp/workspace
# paths:
# - "profiles/*"
# - store_artifacts:
# path: /tmp/logs
# - attach_workspace:
# at: /tmp/workspace
# - run:
# name: gather coverage
# command: |
# set -ex
#
# echo "--> Concatenating profiles:"
# ls /tmp/workspace/profiles/
# echo "mode: atomic" > coverage.txt
# for prof in $(ls /tmp/workspace/profiles/); do
# tail -n +2 /tmp/workspace/profiles/"$prof" >> coverage.txt
# done
# - run:
# name: filter out DONTCOVER
# command: |
# excludelist="$(find . -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
# for filename in ${excludelist}; do
# filename=$(echo $filename | sed 's/^./github.com\/okex\/okchain/g')
# echo "Excluding ${filename} from coverage report..."
# sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
# done
# - run:
# name: upload codecov
# command: bash <(curl -s https://codecov.io/bash) -f coverage.txt
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ okchain:
go install -v $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" ./cmd/okchaind
go install -v $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" ./cmd/okchaincli


test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./...

get_vendor_deps:
@echo "--> Generating vendor directory via dep ensure"
Expand Down
42 changes: 42 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# This codecov.yml is the default configuration for
# all repositories on Codecov. You may adjust the settings
# below in your own codecov.yml in your repository.
#
coverage:
precision: 2
round: down
range: 70...100

status:
# Learn more at https://docs.codecov.io/docs/commit-status
project:
default:
threshold: 1% # allow this much decrease on project
app:
target: 80%
paths: "app/"
module:
target: 80%
paths:
- "x/"
- "!x/**/client/" # ignore client package
changes: false

comment:
layout: "reach, diff, files"
behavior: default # update if exists else create new
require_changes: true

ignore:
- "*.md"
- "*.rst"
- "contrib/"
- "docs/"
- "networks/"
- "**/*.pb.go"
- "types/*.pb.go"
- "tests/*"
- "tests/**/*"
- "x/**/*.pb.go"
- "x/**/test_common.go"

0 comments on commit 8c26893

Please sign in to comment.