From d5c8606908fa033b9d5195fb21d13218047209e1 Mon Sep 17 00:00:00 2001 From: Radu Matei Date: Wed, 17 Apr 2019 18:22:17 +0300 Subject: [PATCH] Add inital code coverage and publish test results Kick off CI again Update display name Temporarily remove container Fix coverage Try gocover-cobertura Add coverage make target Fix makefile indentation Add gocov-xml to make bootstrap Remove gocov-html as Azure Pipelines auto-generates HTML report --- Makefile | 18 ++++++++++++++++++ azure-pipelines.yml | 23 +++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 2edff68c..f16bc4c5 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,9 @@ HAS_DEP := $(shell $(CHECK) dep) HAS_GOLANGCI := $(shell $(CHECK) golangci-lint) HAS_GOIMPORTS := $(shell $(CHECK) goimports) GOLANGCI_VERSION := v1.16.0 +HAS_COCOV_XML := $(shell command -v gocov-xml;) +HAS_GOCOV := $(shell command -v gocov;) +HAS_GO_JUNIT_REPORT := $(shell command -v go-junit-report;) .PHONY: build-drivers build-drivers: @@ -95,6 +98,21 @@ ifndef HAS_GOIMPORTS go get -u golang.org/x/tools/cmd/goimports endif dep ensure -vendor-only -v +ifndef HAS_COCOV_XML + go get github.com/AlekSi/gocov-xml +endif +ifndef HAS_GOCOV + go get -u github.com/axw/gocov/gocov +endif +ifndef HAS_GO_JUNIT_REPORT + go get github.com/jstemmer/go-junit-report +endif + +.PHONY: coverage +coverage: + go test -v -coverprofile=coverage.txt -covermode count ./... 2>&1 | go-junit-report > report.xml + gocov convert coverage.txt > coverage.json + gocov-xml < coverage.json > coverage.xml .PHONY: goimports goimports: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 57bf8b64..b04925c5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,3 @@ -# Go -# Build your Go application. -# Add steps that test, save build artifacts, deploy, and more: -# https://docs.microsoft.com/vsts/pipelines/languages/go - pool: vmImage: 'Ubuntu 16.04' @@ -25,7 +20,19 @@ steps: - script: | go version - go get -v -t -d ./... - make bootstrap build test lint + make bootstrap + make build + make coverage + make lint workingDirectory: '$(modulePath)' - displayName: 'Get dependencies, build, test' + displayName: 'Get dependencies, build, test, pubish, test and coverage results' + +- task: PublishTestResults@2 + inputs: + testRunner: JUnit + testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml + +- task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml \ No newline at end of file