Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for coverage report #16

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down