Skip to content

Commit

Permalink
[gh workflow] Add CodeCov integration (#212)
Browse files Browse the repository at this point in the history
* gh workflow, codecov: Add codecov gh actions integration for unit & integration tests (#175)

* codecov: Create and set up repository codecov.yaml config (#175)

* makefile, refactor: Update Makefile for unit & integration tests (#175)

- Added UNIT_DIRS and INTEGRATION_DIRS variables to specify directories test packages.
- Modified the 'test-unit' and 'integration-test' recipes to run tests for the directories specified in UNIT_DIRS/INTEGRATION_DIRS and generate separate coverage reports for each directory.

- Changed 'clean-cov' target to remove the 'coverage' directory instead of just 'cover.out'.

These changes improve the test organization and ensure separate coverage reports for unit and integration tests. The 'clean-cov' target now removes the entire 'coverage' directory, cleaning up all coverage reports.

* gitignore: Add folder with test coverages to .gitignore (#175)

* codecov, refactor: Remove CODECOV_TOKEN because the repo is public

* readme, codecov: Add codecov status badge to README (#175)

* codecov: Add api/ to codecov report & exclude api/external (#175)

* Makefile, refactor: Implemented recursive directory scanning (#175)

kudos to @KevFan

* codecov, refactor: Update .github/codecov.yaml api/v1beta1 component (#175)

Co-authored-by: Kevin Fan <[email protected]>

* codecov, refactor: Ignore controller-gen generated code (#175)

Co-authored-by: Kevin Fan <[email protected]>

* codecov: Add CODECOV_TOKEN despite repo being public to make CI/CD stable (#175)

Read more at: https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954

Co-authored-by: Kevin Fan <[email protected]>

---------

Co-authored-by: Kevin Fan <[email protected]>
  • Loading branch information
2 people authored and alexsnaps committed Aug 9, 2023
1 parent 6b84d91 commit 41ec36b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
60 changes: 60 additions & 0 deletions .github/codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Find more at https://docs.codecov.com/docs/codecovyml-reference
codecov:
bot: "Codecov Bot"
max_report_age: 12
require_ci_to_pass: yes
notify:
after_n_builds: 1
wait_for_ci: yes

# Layout of the PR comment produced by Codecov bot
comment:
layout: "header, diff, flags, components, files"

ignore:
- api/external/** # ignoring external vendor code
- **/*.deepcopy.go # ignore controller-gen generated code

flag_management:
individual_flags:
- name: unit
paths:
- pkg/**
- api/**
carryforward: true
- name: integration
paths:
- controllers/**
carryforward: true

component_management:
individual_components:
- component_id: api-v1beta1
name: api/v1beta1 (u)
paths:
- api/v1beta1
- component_id: common
name: pkg/common (u)
paths:
- pkg/common
- component_id: istio
name: pkg/istio (u)
paths:
- pkg/istio
- component_id: log
name: pkg/log (u)
paths:
- pkg/log
- component_id: reconcilers
name: pkg/reconcilers (u)
paths:
- pkg/reconcilers
- component_id: rlptools
name: pkg/rlptools (u)
paths:
- pkg/rlptools
- component_id: controllers
name: controllers (i)
paths:
- controllers

14 changes: 14 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ jobs:
- name: Run make test
run: |
make test-unit
- name: Upload unit-test coverage reports to CodeCov # more at https://github.com/codecov/codecov-action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unit
fail_ci_if_error: true
verbose: true

integration-tests:
name: Integration Tests
Expand Down Expand Up @@ -75,6 +82,13 @@ jobs:
- name: Run integration tests
run: |
make test-integration
- name: Upload integration-test coverage reports to CodeCov # more at https://github.com/codecov/codecov-action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: integration
fail_ci_if_error: true
verbose: true

verify-manifests:
name: Verify manifests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tmp

/catalog/kuadrant-operator-catalog
/catalog/kuadrant-operator-catalog.Dockerfile
/coverage/

# Vendor dependencies
vendor
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22

# Directories containing unit & integration test packages
UNIT_DIRS := ./pkg/... ./api/...
INTEGRATION_DIRS := ./controllers...

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -250,20 +254,22 @@ vet: ## Run go vet against code.
go vet ./...

.PHONY: clean-cov
clean-cov: ## Remove coverage report
rm -rf cover.out
clean-cov: ## Remove coverage reports
rm -rf coverage

.PHONY: test
test: test-unit test-integration ## Run all tests

test-integration: clean-cov generate fmt vet envtest ## Run Integration tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) $(ARCH_PARAM) use $(ENVTEST_K8S_VERSION) -p path)" USE_EXISTING_CLUSTER=true go test ./... -coverprofile $(PROJECT_PATH)/cover.out -tags integration -ginkgo.v -ginkgo.progress -v -timeout 0
mkdir -p coverage/integration
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) $(ARCH_PARAM) use $(ENVTEST_K8S_VERSION) -p path)" USE_EXISTING_CLUSTER=true go test $(INTEGRATION_DIRS) -coverprofile $(PROJECT_PATH)/coverage/integration/cover.out -tags integration -ginkgo.v -ginkgo.progress -v -timeout 0

ifdef TEST_NAME
test-unit: TEST_PATTERN := --run $(TEST_NAME)
endif
test-unit: clean-cov generate fmt vet ## Run Unit tests.
go test ./... -coverprofile $(PROJECT_PATH)/cover.out -tags unit -v -timeout 0 $(TEST_PATTERN)
mkdir -p coverage/unit
go test $(UNIT_DIRS) -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -tags unit -v -timeout 0 $(TEST_PATTERN)

.PHONY: namespace
namespace: ## Creates a namespace where to deploy Kuadrant Operator
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Code Style](https://github.com/Kuadrant/kuadrant-operator/actions/workflows/code-style.yaml/badge.svg)](https://github.com/Kuadrant/kuadrant-operator/actions/workflows/code-style.yaml)
[![Testing](https://github.com/Kuadrant/kuadrant-operator/actions/workflows/test.yaml/badge.svg)](https://github.com/Kuadrant/kuadrant-operator/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/Kuadrant/kuadrant-operator/branch/main/graph/badge.svg?token=4Z16KPS3HT)](https://codecov.io/gh/Kuadrant/kuadrant-operator)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)

The Operator to install and manage the lifecycle of the [Kuadrant](https://github.com/Kuadrant/) components deployments.
Expand Down

0 comments on commit 41ec36b

Please sign in to comment.