From a857e2034a353d32430acdbb54cc49434166e336 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Tue, 12 Dec 2023 19:20:34 -0500 Subject: [PATCH 1/4] ci: add coverage check --- .github/workflows/coverage.yml | 26 ++++++++++++++++++++++++++ ci-coverage.sh | 10 ++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .github/workflows/coverage.yml create mode 100755 ci-coverage.sh 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 From 2bdcee7922db827f46d9660ae7a02d19315ccffe Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Tue, 12 Dec 2023 20:16:36 -0500 Subject: [PATCH 2/4] long form expr --- ci-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-coverage.sh b/ci-coverage.sh index 27944b3bc..8524fba9f 100755 --- a/ci-coverage.sh +++ b/ci-coverage.sh @@ -4,7 +4,7 @@ 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 +if [[ $(bc --expression="$cov < $THRESHOLD") ]]; then echo "threshold not met - code must be at or above $THRESHOLD% coverage" exit 1 fi From 4aa73baabf0b85ca267e1b562fbe2da753a3db79 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Tue, 12 Dec 2023 20:22:36 -0500 Subject: [PATCH 3/4] switch to more compatible bc expr --- ci-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-coverage.sh b/ci-coverage.sh index 8524fba9f..f4b0ba3ca 100755 --- a/ci-coverage.sh +++ b/ci-coverage.sh @@ -4,7 +4,7 @@ THRESHOLD=75 # percentage go test -coverprofile c.out ./... cov=$(go tool cover -func c.out | grep '^total:' | awk '{ print $3+0 }') -if [[ $(bc --expression="$cov < $THRESHOLD") ]]; then +if [[ $(echo "$cov < $THRESHOLD" | bc) ]]; then echo "threshold not met - code must be at or above $THRESHOLD% coverage" exit 1 fi From e435a1c27a3fd2d91121296a0b0b7295358cda4b Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Wed, 13 Dec 2023 12:33:01 -0500 Subject: [PATCH 4/4] remove cover enforce --- .github/workflows/coverage.yml | 26 -------------------------- .gitignore | 3 +++ Makefile | 7 ++++++- ci-coverage.sh | 10 ---------- 4 files changed, 9 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/coverage.yml delete mode 100755 ci-coverage.sh diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 4352c8146..000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,26 +0,0 @@ -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/.gitignore b/.gitignore index c92d6105e..2518b3491 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ build/ # VS Code bin/ .vscode/ + +# make +c.out diff --git a/Makefile b/Makefile index 4b3c20937..e66fa8cac 100644 --- a/Makefile +++ b/Makefile @@ -33,13 +33,18 @@ smithy-clean: ################## # Linting/Verify # ################## -.PHONY: verify vet +.PHONY: verify vet cover verify: vet vet: go vet ${BUILD_TAGS} --all ./... +cover: + go test ${BUILD_TAGS} -coverprofile c.out ./... + @cover=`go tool cover -func c.out | grep '^total:' | awk '{ print $$3+0 }'`; \ + echo "total (statements): $$cover%"; + ################ # Unit Testing # ################ diff --git a/ci-coverage.sh b/ci-coverage.sh deleted file mode 100755 index f4b0ba3ca..000000000 --- a/ci-coverage.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -THRESHOLD=75 # percentage - -go test -coverprofile c.out ./... -cov=$(go tool cover -func c.out | grep '^total:' | awk '{ print $3+0 }') -if [[ $(echo "$cov < $THRESHOLD" | bc) ]]; then - echo "threshold not met - code must be at or above $THRESHOLD% coverage" - exit 1 -fi