From 2d8305123667fe339518fc0d0acccaa697352498 Mon Sep 17 00:00:00 2001 From: Andrea Panattoni Date: Wed, 6 Apr 2022 14:31:45 +0200 Subject: [PATCH] Add coverage evidence to the project Configure CI to collect coverage and integrate with coveralls.io service. Move plugin packages out of `pkg` package, as they aren't exportable as library and their presence conflicts with `-coverpkg=./...` cover parameter. Add Makefile rules for merging coverage profiles from multiple sources, as tests are usually run by `make test-pkg` and `make test-controllers`. Add Makefile's rules to download gocovmerge and gcov2lcov. Signed-off-by: Andrea Panattoni --- .github/workflows/go.yml | 12 ++++++++++++ Makefile | 14 ++++++++++++-- hack/build-plugins.sh | 2 +- {pkg/plugins => plugins}/generic/generic_plugin.go | 0 {pkg/plugins => plugins}/intel/intel_plugin.go | 0 {pkg/plugins => plugins}/k8s/k8s_plugin.go | 0 .../mellanox/mellanox_plugin.go | 0 {pkg/plugins => plugins}/virtual/virtual_plugin.go | 0 8 files changed, 25 insertions(+), 3 deletions(-) rename {pkg/plugins => plugins}/generic/generic_plugin.go (100%) rename {pkg/plugins => plugins}/intel/intel_plugin.go (100%) rename {pkg/plugins => plugins}/k8s/k8s_plugin.go (100%) rename {pkg/plugins => plugins}/mellanox/mellanox_plugin.go (100%) rename {pkg/plugins => plugins}/virtual/virtual_plugin.go (100%) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ca3c1ecc92..3bfe1dfae9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -42,3 +42,15 @@ jobs: - name: test controllers on opensfhit run: CLUSTER_TYPE=openshift make test-controllers + - name: merge test coverage + run: make merge-test-coverage + + - uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: cover.out + + - name: Coveralls + uses: coverallsapp/github-action@1.1.3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: lcov.out diff --git a/Makefile b/Makefile index 286d6173cc..12ab278d80 100644 --- a/Makefile +++ b/Makefile @@ -201,7 +201,7 @@ test-e2e-validation-only: test-e2e: generate vet manifests skopeo mkdir -p ${ENVTEST_ASSETS_DIR} test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); source hack/env.sh; go test ./test/e2e/... -timeout 60m -coverprofile cover.out -v + source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); source hack/env.sh; go test ./test/e2e/... -timeout 60m coverprofile cover.out -v test-e2e-k8s: export NAMESPACE=sriov-network-operator test-e2e-k8s: test-e2e @@ -209,13 +209,23 @@ test-e2e-k8s: test-e2e test-%: generate vet manifests mkdir -p ${ENVTEST_ASSETS_DIR} test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh - source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./$*/... -coverprofile cover.out -v + source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./$*/... -coverprofile cover-$*.out -coverpkg ./... -v # deploy-setup-k8s: export NAMESPACE=sriov-network-operator # deploy-setup-k8s: export ENABLE_ADMISSION_CONTROLLER=false # deploy-setup-k8s: export CNI_BIN_PATH=/opt/cni/bin # test-e2e-k8s: test-e2e +gocovmerge: ## Download gocovmerge locally if necessary. + go install -mod=readonly github.com/shabbyrobe/gocovmerge/cmd/gocovmerge@latest + +gcov2lcov: + go install -mod=readonly github.com/jandelgado/gcov2lcov@v1.0.5 + +merge-test-coverage: gocovmerge gcov2lcov + gocovmerge cover-*.out > cover.out + gcov2lcov -infile cover.out -outfile lcov.out + deploy-wait: hack/deploy-wait.sh diff --git a/hack/build-plugins.sh b/hack/build-plugins.sh index 6412236220..990977c7d3 100755 --- a/hack/build-plugins.sh +++ b/hack/build-plugins.sh @@ -35,5 +35,5 @@ mkdir -p ${BIN_PATH} CGO_ENABLED=1 echo "Building ${REPO}/pkg/plugins (${VERSION_OVERRIDE})" -CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -buildmode=plugin -ldflags "${GLDFLAGS} -s -w" ${GOFLAGS} -o ${BIN_PATH}/plugins/$1_plugin.so ${REPO}/pkg/plugins/$1 +CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -buildmode=plugin -ldflags "${GLDFLAGS} -s -w" ${GOFLAGS} -o ${BIN_PATH}/plugins/$1_plugin.so ${REPO}/plugins/$1 #CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -buildmode=plugin -gcflags='all=-N -l' -ldflags "${GLDFLAGS} -s -w" ${GOFLAGS} -o ${BIN_PATH}/plugins/$1_plugin.so ${REPO}/pkg/plugins/$1 diff --git a/pkg/plugins/generic/generic_plugin.go b/plugins/generic/generic_plugin.go similarity index 100% rename from pkg/plugins/generic/generic_plugin.go rename to plugins/generic/generic_plugin.go diff --git a/pkg/plugins/intel/intel_plugin.go b/plugins/intel/intel_plugin.go similarity index 100% rename from pkg/plugins/intel/intel_plugin.go rename to plugins/intel/intel_plugin.go diff --git a/pkg/plugins/k8s/k8s_plugin.go b/plugins/k8s/k8s_plugin.go similarity index 100% rename from pkg/plugins/k8s/k8s_plugin.go rename to plugins/k8s/k8s_plugin.go diff --git a/pkg/plugins/mellanox/mellanox_plugin.go b/plugins/mellanox/mellanox_plugin.go similarity index 100% rename from pkg/plugins/mellanox/mellanox_plugin.go rename to plugins/mellanox/mellanox_plugin.go diff --git a/pkg/plugins/virtual/virtual_plugin.go b/plugins/virtual/virtual_plugin.go similarity index 100% rename from pkg/plugins/virtual/virtual_plugin.go rename to plugins/virtual/virtual_plugin.go