Skip to content

Commit

Permalink
Add unit test coverage to workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
szabolcs-horvath committed Dec 19, 2024
1 parent 15e9733 commit 921fdc7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
55 changes: 55 additions & 0 deletions .github/.testcoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# (mandatory)
# Path to coverage profile file (output of `go test -coverprofile` command).
#
# For cases where there are many coverage profiles, such as when running
# unit tests and integration tests separately, you can combine all those
# profiles into one. In this case, the profile should have a comma-separated list
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
profile: cover.out

# (optional; but recommended to set)
# When specified reported file paths will not contain local prefix in the output.
local-prefix: "github.com/szabolcs-horvath/nutrition-tracker"

# # Holds coverage thresholds percentages, values should be in range [0-100].
# threshold:
# # (optional; default 0)
# # Minimum coverage percentage required for individual files.
# file: 70
#
# # (optional; default 0)
# # Minimum coverage percentage required for each package.
# package: 80
#
# # (optional; default 0)
# # Minimum overall project coverage percentage required.
# 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 in this example).
# - path: ^pkg/lib/foo$
# threshold: 100

# # 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
# - ^pkg/bar # exclude package `pkg/bar`

# # File name of go-test-coverage breakdown file, which can be used to
# # analyze coverage difference.
# breakdown-file-name: ''
#
# diff:
# # File name of go-test-coverage breakdown file which will be used to
# # report coverage difference.
# base-breakdown-file-name: ''
16 changes: 11 additions & 5 deletions .github/workflows/go-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ on:

jobs:

build:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
- uses: actions/setup-go@v4
with:
go-version: '1.23.1'

Expand All @@ -33,5 +32,12 @@ jobs:
- name: Build
run: make build

# - name: Test
# run: go test -v ./...
- name: Generate test coverage
run: go test ./... -v -coverprofile=./cover.out -covermode=atomic -coverpkg=./...

- name: Check test coverage
uses: vladopajic/go-test-coverage@v2
with:
config: ./.github/.testcoverage.yml
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
git-branch: badges
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![coverage](https://raw.githubusercontent.com/szabolcs-horvath/nutrition-tracker/badges/.badges/main/coverage.svg)

# Nutrition Tracker for Kinga
This project's purpose is to help Kinga track and plan her diet.

Expand Down

0 comments on commit 921fdc7

Please sign in to comment.