Skip to content

Commit

Permalink
Merge pull request #16 from ykulazhenkov/cov-report
Browse files Browse the repository at this point in the history
Add support for coverage report
  • Loading branch information
moshe010 committed May 8, 2023
2 parents cb81da7 + 1739c82 commit b90586c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
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

0 comments on commit b90586c

Please sign in to comment.