Skip to content

Commit

Permalink
build: add code coverage reporting to project
Browse files Browse the repository at this point in the history
  • Loading branch information
padamstx committed Jan 27, 2021
1 parent 99e24bb commit 31adbc2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ package-lock.json

# IDE files
*.idea

.vscode/
*.log

# coverage
coverage.txt
26 changes: 15 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ env:
- GO111MODULE=on

before_install:
- sudo apt-get update
- sudo apt-get install python
- nvm install 12
- npm install -g [email protected]
- sudo apt-get update
- sudo apt-get install python
- nvm install 12
- npm install -g [email protected]

install:
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
- curl -s https://codecov.io/bash > $HOME/codecov-bash.sh && chmod +x $HOME/codecov-bash.sh

script:
- make all
- make travis-ci

after_success:
- build/publishCodeCoverage.sh

before_deploy:
- pip install --user bump2version
- npm install @semantic-release/changelog
- npm install @semantic-release/exec
- npm install @semantic-release/git
- npm install @semantic-release/github
- pip install --user bump2version
- npm install @semantic-release/changelog
- npm install @semantic-release/exec
- npm install @semantic-release/git
- npm install @semantic-release/github

deploy:
- provider: script
Expand Down
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Makefile to build go-sdk-template
# Makefile to build the project

all: build unittest lint tidy
COVERAGE = -coverprofile=coverage.txt -covermode=atomic

travis-ci: build alltest lint tidy
all: test lint tidy
travis-ci: test-cov lint tidy

build:
go build ./...
test:
go test `go list ./...`

unittest:
go test `go list ./... | grep -v samples`
test-cov:
go test `go list ./...` ${COVERAGE}

alltest:
go test `go list ./... | grep -v samples` -tags=integration
test-int:
go test `go list ./...` -tags=integration

test-int-cov:
go test `go list ./...` -tags=integration ${COVERAGE}

lint:
golangci-lint run
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
[![Release](https://img.shields.io/github/v/release/IBM/platform-services-go-sdk)](https://github.com/IBM/platform-services-go-sdk/releases/latest)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/IBM/platform-services-go-sdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![codecov](https://codecov.io/gh/IBM/platform-services-go-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/IBM/platform-services-go-sdk)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![CLA assistant](https://cla-assistant.io/readme/badge/ibm/platform-services-go-sdk)](https://cla-assistant.io/ibm/platform-services-go-sdk)


# IBM Cloud Platform Services Go SDK Version 0.17.6
Expand Down
12 changes: 12 additions & 0 deletions build/publishCodeCoverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# This script will publish code coverage info for a build of the master branch
# or a tagged release.

if [[ -n "${TRAVIS_TAG}" || ${TRAVIS_BRANCH} == "master" ]]; then
printf ">>>>> Publishing code coverage info for branch: %s\n" ${TRAVIS_BRANCH}
$HOME/codecov-bash.sh -f coverage.txt -t $CODECOV_TOKEN
else
printf ">>>>> Bypassing code coverage publish step for feature branch/PR build.\n"
fi

0 comments on commit 31adbc2

Please sign in to comment.