From 8476145d0608252cf1786f62c131990c8ead2f99 Mon Sep 17 00:00:00 2001 From: Dmytro Leshchenko Date: Wed, 1 May 2024 23:49:10 +0200 Subject: [PATCH 1/4] Add support for the Coveralls --- .github/workflows/go.yaml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 9cc5dce..6a7b6df 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -41,13 +41,15 @@ jobs: with: go-version: '1.22' - - name: Run tests with coverage - run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./... - - - name: Check tests coverage - uses: vladopajic/go-test-coverage@v2 - with: - config: ./.testcoverage.yml + - name: Run Unit tests + run: | + go test -race -covermode atomic -coverprofile=covprofile ./... + - name: Install goveralls + run: go install github.com/mattn/goveralls@latest + - name: Send coverage + env: + COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + run: goveralls -coverprofile=covprofile -service=github benchmark: runs-on: ubuntu-latest steps: From 5628e998732505d80825a38bd1221b48aeebf3f5 Mon Sep 17 00:00:00 2001 From: Dmytro Leshchenko Date: Thu, 2 May 2024 00:18:30 +0200 Subject: [PATCH 2/4] Add step to remove paths from the test coverage --- .github/workflows/go.yaml | 2 ++ exclude_from_tests.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 exclude_from_tests.sh diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 6a7b6df..2dc1185 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -44,6 +44,8 @@ jobs: - name: Run Unit tests run: | go test -race -covermode atomic -coverprofile=covprofile ./... + - name: Exclude paths from test coverage + run: ./exclude_from_tests.sh covprofile examples/* cmd/* internal/* - name: Install goveralls run: go install github.com/mattn/goveralls@latest - name: Send coverage diff --git a/exclude_from_tests.sh b/exclude_from_tests.sh new file mode 100755 index 0000000..f115564 --- /dev/null +++ b/exclude_from_tests.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Usage: ./exclude_from_tests.sh [-v] file [paths...] +# -v: verbose mode + +verbose=0 +if [ "$1" == "-v" ]; then + verbose=1 + shift +fi + +file=$1 +shift + +tmpfile=$(mktemp) + +while read -r line; do + exclude=0 + for path in "$@"; do + if [[ $line == *"$path"* ]]; then + exclude=1 + [ $verbose -eq 1 ] && echo "Excluding: $line" + break + fi + done + if [ $exclude -eq 0 ]; then + echo "$line" >> "$tmpfile" + fi +done < "$file" + +mv "$tmpfile" "$file" + +echo "Excluded paths from the file." From 1e68f20470338b104dfa91bb86cfbde3aea6c971 Mon Sep 17 00:00:00 2001 From: Dmytro Leshchenko Date: Thu, 2 May 2024 00:25:25 +0200 Subject: [PATCH 3/4] Add coverage report badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d0e17ec..1cefb39 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/dl1998/go-logging.svg)](https://pkg.go.dev/github.com/dl1998/go-logging) [![Go Report Card](https://goreportcard.com/badge/github.com/dl1998/go-logging)](https://goreportcard.com/report/github.com/dl1998/go-logging) +[![Coverage Status](https://coveralls.io/repos/github/dl1998/go-logging/badge.svg)](https://coveralls.io/github/dl1998/go-logging) Go logger implements logger for Golang, current implementation is majorly inspired by Python logger. From 2d33fc75aa5ef98f2967b165d47b47caa97584e8 Mon Sep 17 00:00:00 2001 From: Dmytro Leshchenko Date: Thu, 2 May 2024 00:26:00 +0200 Subject: [PATCH 4/4] Remove old file with coverage report configuration --- .testcoverage.yml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 .testcoverage.yml diff --git a/.testcoverage.yml b/.testcoverage.yml deleted file mode 100644 index df89ced..0000000 --- a/.testcoverage.yml +++ /dev/null @@ -1,43 +0,0 @@ -# (mandatory) -# Path to coverprofile file (output of `go test -coverprofile` command) -profile: cover.out - -# (optional) -# When specified reported file paths will not contain local prefix in the output -local-prefix: "github.com/dl1998/go-logging" - -# Holds coverage thresholds percentages, values should be in range [0-100] -threshold: - # (optional; default 0) - # The minimum coverage that each file should have - file: 80 - - # (optional; default 0) - # The minimum coverage that each package should have - package: 80 - - # (optional; default 0) - # The minimum total coverage project should have - total: 95 - -# Holds regexp rules which will override thresholds for matched files or packages using their paths. -# -# First rule from this list that matches file or package is going to apply new threshold to it. -# If project has multiple rules that match same path, override rules should be listed in order from -# specific to more general rules. -override: - # Increase coverage threshold to 100% for `foo` package (default is 80, as configured above) - # - threshold: 100 - # path: ^internal/testutils$ - -# Holds regexp rules which will exclude matched files or packages from coverage statistics -exclude: - # Exclude files or packages matching their paths - paths: - - \.pb\.go$ # excludes all protobuf generated files - - ^internal/testutils # exclude package `pkg/bar` - - ^examples # exclude examples - -# NOTES: -# - symbol `/` in all path regexps will be replaced by -# current OS file path separator to properly work on Windows \ No newline at end of file