diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index 85242a8..4a17da3 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -68,3 +68,19 @@ jobs: # if this fails, run go mod vendor - name: Check if vendor directory is consistent with go modules run: go mod vendor && git diff --exit-code + coverage: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.20.x + - name: Generate coverage report + run: make cov-report + - name: Upload to Coveralls + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: lcov.info diff --git a/.gitignore b/.gitignore index bb35f7b..0e5697e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ testbin/* # Output of the go coverage tool, specifically when used with LiteIDE *.out +*.info # Kubernetes Generated files - skip generated files, except for vendored files diff --git a/Makefile b/Makefile index 52a1590..34e606c 100644 --- a/Makefile +++ b/Makefile @@ -63,19 +63,21 @@ help: ## Display this help. lint: golangci-lint ## Lint code. $(GOLANGCILINT) run --timeout 10m -COVERAGE_MODE = set -COVER_PROFILE = cover.out +COVERAGE_MODE = atomic +COVER_PROFILE = $(PROJECT_DIR)/cover.out +LCOV_PATH = $(PROJECT_DIR)/lcov.info .PHONY: unit-test unit-test: envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -covermode=$(COVERAGE_MODE) -coverprofile=$(COVER_PROFILE) + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile=$(COVER_PROFILE) .PHONY: test test: lint unit-test .PHONY: cov-report -cov-report: unit-test - go tool cover -func=$(COVER_PROFILE) +cov-report: gcov2lcov unit-test ## Build test coverage report in lcov format + $(GCOV2LCOV) -infile $(COVER_PROFILE) -outfile $(LCOV_PATH) + ##@ Build @@ -117,10 +119,11 @@ $(LOCALBIN): ## Tool Binaries ENVTEST ?= $(LOCALBIN)/setup-envtest GOLANGCILINT ?= $(LOCALBIN)/golangci-lint +GCOV2LCOV ?= $(LOCALBIN)/gcov2lcov ## Tool Versions GOLANGCILINT_VERSION ?= v1.52.2 - +GCOV2LCOV_VERSION ?= v1.0.5 .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. @@ -132,6 +135,12 @@ golangci-lint: $(GOLANGCILINT) ## Download golangci-lint locally if necessary. $(GOLANGCILINT): | $(LOCALBIN) GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION) +.PHONY: gcov2lcov +gcov2lcov: $(GCOV2LCOV) ## Download gcov2lcov locally if necessary. +$(GCOV2LCOV): | $(LOCALBIN) + GOBIN=$(LOCALBIN) go install github.com/jandelgado/gcov2lcov@$(GCOV2LCOV_VERSION) + + .PHONY: clean clean: ## Remove downloaded tools and compiled binaries @rm -rf $(LOCALBIN)