Skip to content

Commit

Permalink
Add the sonar code coverage support. (#115)
Browse files Browse the repository at this point in the history
* Add the sonar code coverage support.

* Update gitignore and fix the go executable mode.
  • Loading branch information
schmidtw authored Aug 28, 2020
1 parent d6fbf32 commit 5f6c19f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gungnir
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.txt
report.json

*vendor/

Expand Down
33 changes: 33 additions & 0 deletions .sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Reference:
# https://github.com/SonarSource/sonarcloud_example_go-sqscanner-travis/blob/master/sonar-project.properties


# =====================================================
# Standard properties
# =====================================================

sonar.projectKey=xmidt-org_gungnir
sonar.projectName=gungnir

sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**

# =====================================================
# Meta-data for the project
# =====================================================

sonar.links.homepage=https://github.com/xmidt-org/gungnir
sonar.links.ci=https://travis-ci.org/xmidt-org/gungnir
sonar.links.scm=https://github.com/xmidt-org/gungnir
sonar.links.issue=https://github.com/xmidt-org/gungnir/issues

# =====================================================
# Properties specific to Go
# =====================================================

sonar.go.tests.reportPaths=report.json
sonar.go.coverage.reportPaths=coverage.txt
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ branches:
- main
- /^v[0-9]+\.[0-9]+\.[0-9]+$/

addons:
sonarcloud:
organization: "xmidt-org"
token:
secure: "WHln/Wrsr/2dfkNcK9jBta2idx/IhO9JGbmZUAxVpCs7ki0SptyFluC9hV9RT4Ccsgyhoj42gFqy5XTqCyM3OhS45uJ464/lmiUu7VRm8nlDRaCjYEoDYX9HKo3vlIJCGuHdbtJqZMRB0VvlqeChnbBszgx61yqQDxd+3mwDJKzpqPrvrSSefxS7+6BKi+yR73tTRoDHXBH4z45kQGqo6jexyGXfgfHXrPrmqsIEroih8oQKLRqXL4EsZQZDO11te9VtCn+80WMiEzd6cyUK6ECvYosrCe+HGDsqdH6lfK99/YlFU+mREJDPNjBaqUnxLnhul0evYgQ1GiPWFO1BROVjtf43CDMjNXRDnde7Exef1/SJWhNPI2UpY7Aw7Smd7E46yIaHG+DX3SWzj0mcqPI5RReKih8q7cT3lMe3XYxA3qgtsPsl9FBgCpC96VWHq/RWPksPWBhZ2gbMPknMd2pwfd7GS4/eji+6cG4kgv+v3m7TkiNtRaulIL79DOTiYCyqwGotZiHBmvUZOEQfxuMA5V8rBWwvrUxVViVnummtZb1YJlA5LXFhegJZppquoU6wOCrkJm+UtlXsBsSPEEWz892B7JSRd7dG/9na682NaStCVqH1PoVjkj3udPRyOa29tXo5ItCrThp+i7bK+i+3iW3ZqQMcFjkfGhEdtaw="


script:
- make style codecov

after_success:
- sonar-scanner -Dproject.settings=./.sonar-project.properties

jobs:
include:
- stage: integration
Expand All @@ -38,6 +48,8 @@ jobs:
- export TODAY=`date +'%m/%d/%Y'`
- export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$ENV{TODAY}\n\n$1\n" if /.*## \[$ENV{TAG}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s')
- if [[ "$TAG" != "" && "$TAG" != "$OLD_VERSION" ]]; then git tag -a "$TAG" -m "$NOTES"; git push origin --tags; echo $?; fi
after_success: skip

- stage: release
name: "Make a Release"
if: branch != main
Expand All @@ -52,4 +64,3 @@ jobs:
file_glob: true
api_key: "$GH_TOKEN"
file: ./.ignore/*
skip_cleanup: true
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ style:

.PHONY: test
test: go-mod-vendor
GO111MODULE=on $(GO) test -v -race -coverprofile=cover.out ./...
GO111MODULE=on $(GO) test -v -race -coverprofile=coverage.txt ./...
GO111MODULE=on $(GO) test -v -race -json ./... > report.json

.PHONY: test-cover
test-cover: test
$(GO) tool cover -html=cover.out
$(GO) tool cover -html=coverage.txt

.PHONY: codecov
codecov: test
Expand All @@ -83,4 +84,4 @@ it:

.PHONY: clean
clean:
rm -rf ./$(APP) ./.ignore ./coverage.txt ./vendor
rm -rf ./$(APP) ./.ignore ./coverage.txt ./vendor report.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/xmidt-org/gungnir)](https://goreportcard.com/report/github.com/xmidt-org/gungnir)
[![Apache V2 License](http://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/xmidt-org/gungnir/blob/main/LICENSE)
[![GitHub release](https://img.shields.io/github/release/xmidt-org/gungnir.svg)](CHANGELOG.md)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xmidt-org_gungnir&metric=alert_status)](https://sonarcloud.io/dashboard?id=xmidt-org_gungnir)


## Summary
Expand Down

0 comments on commit 5f6c19f

Please sign in to comment.