Skip to content

Commit

Permalink
Add code coverage action in pipeline (#569)
Browse files Browse the repository at this point in the history
* Add code coverage action in pipeline

* Trigger pipeline

* Fix configuration of test sandbox

---------

Co-authored-by: Taras Shcherban <[email protected]>
Co-authored-by: Artem Gavrilov <[email protected]>
Co-authored-by: Nurlan Moldomurov <[email protected]>
Co-authored-by: Jiří Čtvrtka <[email protected]>
  • Loading branch information
5 people authored Nov 12, 2024
1 parent 0239f77 commit 02d5d2f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ jobs:
with:
go-version-file: ${{ github.workspace }}/go.mod

- name: Test
- name: Run tests with code coverage
run: |
TEST_MONGODB_IMAGE=${{ matrix.image }} make test-cluster
sleep 10
make test-race
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

- name: Run debug commands on failure
if: ${{ failure() }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
.dist
.env

.vscode/
.idea

bin
build
dist

cover.out
mongodb_exporter
.DS_Store
22 changes: 12 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ define TEST_ENV
TEST_MONGODB_S1_PRIMARY_PORT=$(TEST_MONGODB_S1_PRIMARY_PORT) \
TEST_MONGODB_S1_SECONDARY1_PORT=$(TEST_MONGODB_S1_SECONDARY1_PORT) \
TEST_MONGODB_S1_SECONDARY2_PORT=$(TEST_MONGODB_S1_SECONDARY2_PORT) \
TEST_MONGODB_S1_ARTBITER_PORT=$(TEST_MONGODB_S1_ARBITER_PORT) \
TEST_MONGODB_S1_ARBITER_PORT=$(TEST_MONGODB_S1_ARBITER_PORT) \
TEST_MONGODB_S2_RS=$(TEST_MONGODB_S2_RS) \
TEST_MONGODB_S2_PRIMARY_PORT=$(TEST_MONGODB_S2_PRIMARY_PORT) \
TEST_MONGODB_S2_SECONDARY1_PORT=$(TEST_MONGODB_S2_SECONDARY1_PORT) \
TEST_MONGODB_S2_SECONDARY2_PORT=$(TEST_MONGODB_S2_SECONDARY2_PORT) \
TEST_MONGODB_S2_ARTBITER_PORT=$(TEST_MONGODB_S2_ARBITER_PORT) \
TEST_MONGODB_S2_ARBITER_PORT=$(TEST_MONGODB_S2_ARBITER_PORT) \
TEST_MONGODB_CONFIGSVR_RS=$(TEST_MONGODB_CONFIGSVR_RS) \
TEST_MONGODB_CONFIGSVR1_PORT=$(TEST_MONGODB_CONFIGSVR1_PORT) \
TEST_MONGODB_CONFIGSVR2_PORT=$(TEST_MONGODB_CONFIGSVR2_PORT) \
Expand All @@ -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 @@ -82,32 +82,34 @@ 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-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:3.6 make test-cluster
docker compose up --build -d
./docker/scripts/setup-pbm.sh

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

docker compose down --remove-orphans --volumes
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ services:
container_name: "mongo-cnf-2"
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
ports:
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
networks:
- cnf-serv
Expand All @@ -185,7 +185,7 @@ services:
container_name: "mongo-cnf-3"
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
ports:
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
networks:
- cnf-serv
Expand All @@ -194,7 +194,7 @@ services:
container_name: "mongo-cnf-1"
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
ports:
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
networks:
- cnf-serv
Expand Down
1 change: 1 addition & 0 deletions docker/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function general_servers() {
EOF
}


case $1 in
cnf_servers)
cnf_servers
Expand Down

0 comments on commit 02d5d2f

Please sign in to comment.