Skip to content

Commit

Permalink
test: Add Codecov (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyo authored Dec 20, 2023
1 parent 5b0689b commit a7a426c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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}'
Expand All @@ -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
Expand Down

0 comments on commit a7a426c

Please sign in to comment.