diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..4352c8146 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,26 @@ +name: Coverage + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + coverage: + name: SDK Unit Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + go-version: ["1.21"] + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Coverage + run: ./ci-coverage.sh diff --git a/ci-coverage.sh b/ci-coverage.sh new file mode 100755 index 000000000..27944b3bc --- /dev/null +++ b/ci-coverage.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +THRESHOLD=75 # percentage + +go test -coverprofile c.out ./... +cov=$(go tool cover -func c.out | grep '^total:' | awk '{ print $3+0 }') +if [[ $(bc -e "$cov < $THRESHOLD") ]]; then + echo "threshold not met - code must be at or above $THRESHOLD% coverage" + exit 1 +fi