Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage action in pipeline #569

Merged
merged 12 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ jobs:
bin/golangci-lint run -c=.golangci-required.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-check
bin/golangci-lint run -c=.golangci.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-review
make check-license

- name: Run code coverage
run: |
TEST_MONGODB_IMAGE=${{ matrix.image }} make test-cluster
make test-cover
make test-cluster-clean

- name: Upload coverage results
uses: codecov/codecov-action@v3
with:
file: cover.out
flags: agent
env_vars: GO_VERSION,TEST_MONGODB_IMAGE
fail_ci_if_error: false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
.dist
.env

.vscode/
.idea

bin
build
dist

cover.out
mongodb_exporter
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ endef
env:
@echo $(TEST_ENV) | tr ' ' '\n' >.env

init: ## Install linters.
init: ## Install linters
cd tools && go generate -x -tags=tools

build: ## Compile using plain go build
Expand All @@ -81,30 +81,33 @@ release: ## Build the binaries using goreleaser

FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*")

format: ## Format source code.
format: ## Format source code
go mod tidy
bin/gofumpt -l -w $(FILES)
bin/gci write --section Standard --section Default --section "Prefix(github.com/percona/mongodb_exporter)" .

check: ## Run checks/linters
bin/golangci-lint run

check-license: ## Check license in headers.
check-license: ## Check license in headers
@go run .github/check-license.go

help: ## Display this help message.
help: ## Display this help message
@echo "Please use \`make <target>\` where <target> is one of:"
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'

test: env ## Run all tests.
test: env ## Run all tests
go test -v -count 1 -timeout 30s ./...

test-race: env ## Run all tests with race flag.
test-race: env ## Run all tests with race flag
go test -race -v -timeout 30s ./...

test-cluster: env ## Starts MongoDB test cluster. Use env var TEST_MONGODB_IMAGE to set flavor and version. Example: TEST_MONGODB_IMAGE=mongo:3.6 make test-cluster
test-cover: env ## Run tests and collect cross-package coverage information
go test -race -timeout 30s -coverprofile=cover.out -covermode=atomic -coverpkg=./... ./...

test-cluster: env ## Starts MongoDB test cluster. Use env var TEST_MONGODB_IMAGE to set flavor and version. Example: TEST_MONGODB_IMAGE=mongo:4.4 make test-cluster
docker-compose up -d

test-cluster-clean: env ## Stops MongoDB test cluster.
test-cluster-clean: env ## Stops MongoDB test cluster
docker-compose down --remove-orphans