Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Makefile for generating Go coverage reports for Jenkins (for projects containing multiple packages)
GO=$(firstword $(subst :, ,$(GOPATH)))
GOCOV=$(GO)/bin/gocov
GOCOVXML=$(GO)/bin/gocov-xml
# List of pkgs for the project
PKGS=$(shell go list ./...)
# Coverage output: coverage/$PKG/coverage.out
COVPKGS=$(addsuffix /coverage.out,$(addprefix coverage/,$(PKGS)))
jenkins: coverage/cobertura-coverage.xml
coverage/cobertura-coverage.xml: coverage/all.out $(GOCOV) $(GOCOVXML)
$(GOCOV) convert $< | $(GOCOVXML) >$@
coverage/all.out: $(COVPKGS)
echo "mode: set" >$@
grep -hv "mode: set" $(wildcard $^) >>$@
$(COVPKGS): .FORCE
@ mkdir -p $(dir $@)
@ go test -coverprofile $@ $(patsubst coverage/%/coverage.out,%,$@)
$(GOCOV):
go get github.com/axw/gocov/gocov
$(GOCOVXML):
go get github.com/AlekSi/gocov-xml
.FORCE:
.PHONY: jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.