Skip to content

Commit

Permalink
Code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jun 17, 2023
1 parent f5dfe90 commit 4b6a139
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
run: go build -v ./...

- name: Go test
run: go test -v ./...


run: go test -v -coverprofile=coverage.out ./...

- name: Go coverage
env:
CODE_COVERAGE_THRESHOLD: 100
run: bash ./scripts/coverage.sh
25 changes: 25 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

COVERAGE_FILE=coverage.out

if [ -z "$CODE_COVERAGE_THRESHOLD" ]
then
echo "No code coverage threshold is set."
exit 0
fi

echo "Code coverage threshold ${CODE_COVERAGE_THRESHOLD}%"

if [ ! -e "$COVERAGE_FILE" ]
then
echo "Coverage file ${COVERAGE_FILE} is not found."
exit 1
fi

CODE_COVERAGE=$(go tool cover -func=coverage.out | grep "total:" | grep -E -o '[0-9]+\.[0-9]+')

if awk "BEGIN { exit !($CODE_COVERAGE < $CODE_COVERAGE_THRESHOLD)}"
then
echo "Current code coverage ${CODE_COVERAGE}% is below the ${CODE_COVERAGE_THRESHOLD}% threshold."
exit 1
fi

0 comments on commit 4b6a139

Please sign in to comment.