From b87c8676fbddabbec485e7a79eb7928fc89a8837 Mon Sep 17 00:00:00 2001 From: Anish Ramasekar Date: Wed, 13 Jan 2021 09:45:45 -0800 Subject: [PATCH] ci: add code coverage as part of CI (#360) --- .gitignore | 3 +++ Makefile | 4 ++-- README.md | 1 + azure-pipelines.yml | 4 ++++ codecov.yml | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 codecov.yml diff --git a/.gitignore b/.gitignore index 30fbf9198..a9b1cdc77 100644 --- a/.gitignore +++ b/.gitignore @@ -347,3 +347,6 @@ manifest_staging/charts/csi-secrets-store-provider-azure/charts/ # website website/public website/resources + +# cover profile +coverage.txt diff --git a/Makefile b/Makefile index a6ded7f31..9e2ecf029 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ BUILD_VERSION_VAR := $(REPO_PATH)/pkg/version.BuildVersion VCS_VAR := $(REPO_PATH)/pkg/version.Vcs LDFLAGS ?= "-X $(BUILD_DATE_VAR)=$(BUILD_DATE) -X $(BUILD_VERSION_VAR)=$(IMAGE_VERSION) -X $(VCS_VAR)=$(BUILD_COMMIT)" -GO_FILES=$(shell go list ./...) +GO_FILES=$(shell go list ./... | grep -v /test/e2e) ALL_DOCS := $(shell find . -name '*.md' -type f | sort) TOOLS_MOD_DIR := ./tools TOOLS_DIR := $(abspath ./.tools) @@ -66,7 +66,7 @@ lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell .PHONY: unit-test unit-test: - go test $(GO_FILES) -v + CGO_ENABLED=1 go test -race -coverprofile=coverage.txt -covermode=atomic $(GO_FILES) -v .PHONY: build build: diff --git a/README.md b/README.md index 2611981a0..51b9e9abf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Azure Key Vault Provider for Secrets Store CSI Driver [![Build Status](https://dev.azure.com/azure/secrets-store-csi-driver-provider-azure/_apis/build/status/secrets-store-csi-driver-provider-azure-ci?branchName=master)](https://dev.azure.com/azure/secrets-store-csi-driver-provider-azure/_build/latest?definitionId=67&branchName=master) +[![codecov](https://codecov.io/gh/Azure/secrets-store-csi-driver-provider-azure/branch/master/graph/badge.svg)](https://codecov.io/gh/Azure/secrets-store-csi-driver-provider-azure) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/Azure/secrets-store-csi-driver-provider-azure) [![Go Report Card](https://goreportcard.com/badge/Azure/secrets-store-csi-driver-provider-azure)](https://goreportcard.com/report/Azure/secrets-store-csi-driver-provider-azure) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/Azure/secrets-store-csi-driver-provider-azure) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 95dcba6c8..225a2b714 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -31,6 +31,10 @@ jobs: displayName: Build - script: make unit-test displayName: Run unit tests + - script: bash <(curl -s https://codecov.io/bash) + displayName: Upload coverage to codecov + env: + CODECOV_TOKEN: $(CODECOV_TOKEN) - script: make helm-lint displayName: Run helm lint - template: .pipelines/templates/scan-images.yaml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..8070a09c4 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,32 @@ +codecov: + notify: + require_ci_to_pass: no + +coverage: + precision: 2 + round: down + range: "50...100" + status: + project: + default: + threshold: 0.5 + patch: + default: + threshold: 0.5 + changes: no + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "header, diff" + behavior: default + require_changes: no + +ignore: + - "test/**/*.go"