From db554be53046731ff035cf4eed90eccdae78e631 Mon Sep 17 00:00:00 2001 From: sbp-bvanb Date: Fri, 30 Aug 2024 08:37:13 +0200 Subject: [PATCH] feat: [#63] Enforce a minimum code coverage --- action.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/action.yml b/action.yml index 7ef5a1b..c8363a2 100644 --- a/action.yml +++ b/action.yml @@ -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. @@ -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 "${code_coverage_actual} > ${{ inputs.code_coverage_expected }}" | 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: |