diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 86f66b4..1d1e186 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,7 +31,14 @@ jobs: - name: Check go.mod Tidiness run: make mod-tidy - name: Test - run: make test + run: make test-coverage + - name: Upload coverage reports to Codecov + # https://github.com/codecov/codecov-action/releases/tag/v3.1.4 + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + directory: .coverage timeout-minutes: 10 strategy: matrix: diff --git a/.gitignore b/.gitignore index e2e2e5c..9c22cdd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +.coverage # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/Makefile b/Makefile index 893c4a6..5113b60 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,10 @@ +.DEFAULT_GOAL := help + +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +MKFILE_DIR := $(dir $(MKFILE_PATH)) +# In seconds +TIMEOUT = 60 + # Parse Makefile and display the help help: ## Show help @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @@ -12,9 +19,25 @@ upload-image-kind: docker-build .PHONY: upload-image-kind test: ## Run tests - go test -v -count=1 -race -timeout 60s ./... + go test -v -count=1 -race -timeout $(TIMEOUT)s ./... .PHONY: test +# Coverage +COVERAGE_MODE = atomic +COVERAGE_PROFILE = coverage.out +COVERAGE_REPORT_DIR = .coverage +COVERAGE_REPORT_DIR_ABS = $(MKFILE_DIR)/$(COVERAGE_REPORT_DIR) +COVERAGE_REPORT_FILE_ABS = $(COVERAGE_REPORT_DIR_ABS)/$(COVERAGE_PROFILE) +$(COVERAGE_REPORT_DIR): + mkdir -p $(COVERAGE_REPORT_DIR) +clean-report-dir: $(COVERAGE_REPORT_DIR) + test $(COVERAGE_REPORT_DIR) && rm -f $(COVERAGE_REPORT_DIR)/* +test-coverage: $(COVERAGE_REPORT_DIR) clean-report-dir ## Test with coverage enabled + set -e ; \ + go test -count=1 -race -timeout $(TIMEOUT)s -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_REPORT_FILE_ABS)" ./... ; \ + go tool cover -html="$(COVERAGE_REPORT_FILE_ABS)" -o "$(COVERAGE_REPORT_DIR_ABS)/coverage.html"; +.PHONY: test-coverage clean-report-dir + build: ## Build the module go build ./... .PHONY: build