Skip to content

Instantly share code, notes, and snippets.

@wadey
Created December 5, 2013 19:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wadey/7811454 to your computer and use it in GitHub Desktop.
Save wadey/7811454 to your computer and use it in GitHub Desktop.
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