From ccae458dca616e4b037f3a4819aa522940acda51 Mon Sep 17 00:00:00 2001 From: thepetk Date: Wed, 12 Jul 2023 14:45:40 +0100 Subject: [PATCH 1/7] Add test coverage workflow Signed-off-by: thepetk --- .github/workflows/CI.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 587d9ec7..f9f5f616 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,6 +28,22 @@ jobs: - name: Build binary run: make build + - name: Check test coverage + env: + TESTCOVERAGE_THRESHOLD: 80 + run: | + echo "Quality Gate: checking test coverage is above threshold ..." + echo "Threshold : $TESTCOVERAGE_THRESHOLD %" + totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` + echo "Current test coverage : $totalCoverage %" + if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then + echo "OK" + else + echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value." + echo "Failed" + exit 1 + fi + - name: Run Go tests run: make test @@ -46,4 +62,4 @@ jobs: uses: github/codeql-action/upload-sarif@v2 with: # Path to SARIF file relative to the root of the repository - sarif_file: gosec.sarif \ No newline at end of file + sarif_file: gosec.sarif From fa7b623d0c477cc869ac16a901fd25f2bceb12bd Mon Sep 17 00:00:00 2001 From: thepetk Date: Wed, 12 Jul 2023 14:56:13 +0100 Subject: [PATCH 2/7] Update ci.yaml Signed-off-by: thepetk --- .github/workflows/CI.yml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f9f5f616..153c8b05 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,24 +28,27 @@ jobs: - name: Build binary run: make build + - name: Run Go tests + run: | + go test ./... -coverprofile coverage.out -covermode count + go tool cover -func coverage.out + - name: Check test coverage env: TESTCOVERAGE_THRESHOLD: 80 run: | - echo "Quality Gate: checking test coverage is above threshold ..." - echo "Threshold : $TESTCOVERAGE_THRESHOLD %" - totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` - echo "Current test coverage : $totalCoverage %" - if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then - echo "OK" - else - echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value." - echo "Failed" - exit 1 - fi + echo "Checking if coverage is above threshold..." + echo "Coverage Threshold: $TESTCOVERAGE_THRESHOLD %" + totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` + echo "Current test coverage : $totalCoverage %" + if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then + echo "OK" + else + echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value." + echo "Failed" + exit 1 + fi - - name: Run Go tests - run: make test - name: Run Gosec Security Scanner run: | From b9766ab20fbf2def2d79804fe4140eca2e26341a Mon Sep 17 00:00:00 2001 From: thepetk Date: Thu, 13 Jul 2023 13:21:28 +0100 Subject: [PATCH 3/7] Add separate check for code coverage Signed-off-by: thepetk --- .github/workflows/CI.yml | 21 +-------------------- .github/workflows/codecov.yml | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 153c8b05..2905e0b6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,26 +29,7 @@ jobs: run: make build - name: Run Go tests - run: | - go test ./... -coverprofile coverage.out -covermode count - go tool cover -func coverage.out - - - name: Check test coverage - env: - TESTCOVERAGE_THRESHOLD: 80 - run: | - echo "Checking if coverage is above threshold..." - echo "Coverage Threshold: $TESTCOVERAGE_THRESHOLD %" - totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'` - echo "Current test coverage : $totalCoverage %" - if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then - echo "OK" - else - echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value." - echo "Failed" - exit 1 - fi - + run: make test - name: Run Gosec Security Scanner run: | diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 00000000..cdd7f983 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,21 @@ +name: Code Coverage Report +on: + push: + branches: + - main +jobs: + build-and-deploy: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2.3.1 + with: + persist-credentials: false + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: 1.19 + - name: Run tests + run: go test -coverprofile cover.out -v ./... + - name: Codecov + uses: codecov/codecov-action@v2.1.0 \ No newline at end of file From 52cf09c7ab15f16b6c21ab2d8905e1fed19b6f34 Mon Sep 17 00:00:00 2001 From: thepetk Date: Thu, 13 Jul 2023 13:41:22 +0100 Subject: [PATCH 4/7] Move code report in ci file Signed-off-by: thepetk --- .github/workflows/CI.yml | 16 ++++++++++++++++ .github/workflows/codecov.yml | 21 --------------------- 2 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2905e0b6..8ab58745 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -47,3 +47,19 @@ jobs: with: # Path to SARIF file relative to the root of the repository sarif_file: gosec.sarif + + code-coverage-report: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2.3.1 + with: + persist-credentials: false + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: 1.19 + - name: Run tests + run: go test -coverprofile cover.out -v ./... + - name: Codecov + uses: codecov/codecov-action@v2.1.0 \ No newline at end of file diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml deleted file mode 100644 index cdd7f983..00000000 --- a/.github/workflows/codecov.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Code Coverage Report -on: - push: - branches: - - main -jobs: - build-and-deploy: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v2.3.1 - with: - persist-credentials: false - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: 1.19 - - name: Run tests - run: go test -coverprofile cover.out -v ./... - - name: Codecov - uses: codecov/codecov-action@v2.1.0 \ No newline at end of file From 10756ac44155ecdeb68b507d35a37b565d01fb2f Mon Sep 17 00:00:00 2001 From: thepetk Date: Thu, 13 Jul 2023 13:51:50 +0100 Subject: [PATCH 5/7] Add .codecov.yaml Signed-off-by: thepetk --- .codecov.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .codecov.yaml diff --git a/.codecov.yaml b/.codecov.yaml new file mode 100644 index 00000000..aa78ba62 --- /dev/null +++ b/.codecov.yaml @@ -0,0 +1,36 @@ +# See http://docs.codecov.io/docs/coverage-configuration +coverage: + precision: 2 # 2 = xx.xx%, 0 = xx% + round: down + # For example: 20...60 would result in any coverage less than 20% + # would have a red background. The color would gradually change to + # green approaching 60%. Any coverage over 60% would result in a + # solid green color. + range: "60...80" + + status: + # project will give us the diff in the total code coverage between a commit + # and its parent + project: yes + # Patch gives just the coverage of the patch + patch: yes + # changes tells us if there are unexpected code coverage changes in other files + # which were not changed by the diff + changes: yes + + # See http://docs.codecov.io/docs/ignoring-paths + ignore: + - "docs/*" + - ".github/*" + - "resources/*" + - "test/*" + - "Makefile" + +# See http://docs.codecov.io/docs/pull-request-comments-1 +comment: + layout: "diff, files" + behavior: "" + # default = posts once then update, posts new if delete + # once = post once then updates + # new = delete old, post new + # spammy = post new \ No newline at end of file From 0019c325738050d9106f422877ad298b91f0acee Mon Sep 17 00:00:00 2001 From: thepetk Date: Thu, 13 Jul 2023 15:24:28 +0100 Subject: [PATCH 6/7] Update workflow Signed-off-by: thepetk --- .github/workflows/CI.yml | 6 +++--- Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8ab58745..179d3d7e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2.3.1 + uses: actions/checkout@v3.5.3 with: persist-credentials: false - name: Set up Go 1.x @@ -60,6 +60,6 @@ jobs: with: go-version: 1.19 - name: Run tests - run: go test -coverprofile cover.out -v ./... + run: make test - name: Codecov - uses: codecov/codecov-action@v2.1.0 \ No newline at end of file + uses: codecov/codecov-action@v3.1.4 \ No newline at end of file diff --git a/Makefile b/Makefile index 41340709..3b02c6bb 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,4 @@ buildWin: .PHONY: test test: - go test ./... \ No newline at end of file + go test -coverprofile cover.out -v ./... \ No newline at end of file From 92e92ee87f72f0ad7abfb06c80eaa9e3cee72994 Mon Sep 17 00:00:00 2001 From: thepetk Date: Thu, 13 Jul 2023 15:35:12 +0100 Subject: [PATCH 7/7] Bump up setup-go Signed-off-by:thepetk --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 179d3d7e..2daed1ed 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -56,7 +56,7 @@ jobs: with: persist-credentials: false - name: Set up Go 1.x - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.19 - name: Run tests