From 58b27a1ccf4ee1b5b81c04ed250f32f77d0bb7cc Mon Sep 17 00:00:00 2001 From: Sudarsan Reddy Date: Wed, 31 May 2023 14:59:05 +0100 Subject: [PATCH] TUN-7447: Add a cover build to report code coverage --- Makefile | 12 +++++++++++- cfsetup.yaml | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 06fa0050..df4c3482 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,7 @@ container: generate-docker-version: echo latest $(VERSION) > versions + .PHONY: test test: vet ifndef CI @@ -147,9 +148,18 @@ ifndef CI else @mkdir -p .cover go test -v -mod=vendor -race $(LDFLAGS) -coverprofile=".cover/c.out" ./... - go tool cover -html ".cover/c.out" -o .cover/all.html endif +.PHONY: cover +cover: + @echo "" + @echo "=====> Total test coverage: <=====" + @echo "" + # Print the overall coverage here for quick access. + $Q go tool cover -func ".cover/c.out" | grep "total:" | awk '{print $$3}' + # Generate the HTML report that can be viewed from the browser in CI. + $Q go tool cover -html ".cover/c.out" -o .cover/all.html + .PHONY: test-ssh-server test-ssh-server: docker-compose -f ssh_server_tests/docker-compose.yml up diff --git a/cfsetup.yaml b/cfsetup.yaml index 45177dcb..1131c256 100644 --- a/cfsetup.yaml +++ b/cfsetup.yaml @@ -29,6 +29,12 @@ buster: &buster - export GOARCH=amd64 - export FIPS=true - make cloudflared + cover: + build_dir: *build_dir + builddeps: *build_deps + pre-cache: *build_pre_cache + post-cache: + - make cover # except FIPS (handled in github-fips-release-pkgs) and macos (handled in github-release-macos-amd64) github-release-pkgs: build_dir: *build_dir