Skip to content

Commit

Permalink
feat: [#63] Enforce a minimum code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-bvanb committed Aug 30, 2024
1 parent 2f63fc2 commit f66f784
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and a [.golangci.yml](https://golangci-lint.run/usage/configuration/).

| option | default |
| ---------------------------------- | ------- |
| code_coverage_expected | 80 |
| golang-unit-tests-exclusions | ' ' |
| golangci-lint-version | v1.55.2 |
| golang-number-of-tests-in-parallel | 4 |
Expand Down
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: mcvs-golang-action
description: |
The Mission Critical Vulnerability Scanner (MCVS) Golang action.
inputs:
code_coverage_expected:
description: |
The minimum code coverage.
default: "80"
golang-unit-tests-exclusions:
description: |
The Golang paths that should be excluded from unit testing.
Expand Down Expand Up @@ -91,6 +95,18 @@ runs:
#
# Unit tests.
#
- name: code coverage
shell: bash
run: |
go test -v -coverpkg=./... -coverprofile=profile.cov ./...
code_coverage_actual=$(go tool cover -func profile.cov |\
grep total: |\
awk '{print $3}' |\
sed 's/%//')
if (( $(echo "${{ inputs.code_coverage_expected }} > ${code_coverage_actual}" | bc -l) )); then
echo "The actual code coverage: '${code_coverage_actual}' is too low. Expected: '${{ inputs.code_coverage_expected }}'"
exit 1
fi
- name: unit tests
shell: bash
run: |
Expand Down

0 comments on commit f66f784

Please sign in to comment.