From e346a44540d1d85653ef6f2cf16e4087c7b59948 Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:30:59 +0000 Subject: [PATCH 1/9] Add GitHub Actions workflow for test coverage gate --- .github/workflows/coverage.yaml | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/coverage.yaml diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 00000000..7c6ab9fc --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,55 @@ +name: Test Coverage Quality Gate + +on: + pull_request: + branches: [ main ] + workflow_dispatch: + +permissions: + contents: read + +jobs: + coverage-gate: + name: Go Coverage Gate + runs-on: [self-hosted, linux, eks] + + steps: + - name: Checkout PR code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed to compare with base branch + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run coverage on PR branch + run: | + chmod +x ./scripts/coverage.sh + ./scripts/coverage.sh + mv coverage.percent coverage.pr + + - name: Checkout base branch + run: | + git checkout origin/${{ github.base_ref }} + + - name: Run coverage on base branch + run: | + ./scripts/coverage.sh + mv coverage.percent coverage.base + + - name: Compare coverage (PR vs base) + run: | + PR_COV=$(cat coverage.pr) + BASE_COV=$(cat coverage.base) + + echo "PR Coverage : $PR_COV%" + echo "Base Coverage : $BASE_COV%" + + if (( $(echo "$PR_COV < $BASE_COV" | bc -l) )); then + echo "❌ Coverage reduced from $BASE_COV% → $PR_COV%" + exit 1 + fi + + echo "✅ Coverage not reduced" From 3b07bf66c4ddd8c507e3a3c4620e75cf09d4715a Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:32:25 +0000 Subject: [PATCH 2/9] Add coverage.sh for test coverage reporting This script runs tests, generates coverage reports, filters out specified files, and checks if coverage meets the minimum threshold. --- scripts/coverage.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/coverage.sh diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100644 index 00000000..aea698cc --- /dev/null +++ b/scripts/coverage.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Running tests and generating raw coverage..." +go test ./... -coverprofile=coverage.raw.out + +echo "Filtering coverage (excluding generated & entry code)..." + +{ + head -n 1 coverage.raw.out + grep -vE '(/cmd/|/ent/|wire\.go|wire_gen\.go|\.pb\.go|mock_|/vendor/|/main\.go)' coverage.raw.out | tail -n +2 +} > coverage.out + +echo "Calculating final coverage..." +COVERAGE=$(go tool cover -func=coverage.out | grep '^total:' | awk '{print $3}' | sed 's/%//') + +if [[ -z "$COVERAGE" ]]; then + echo "❌ ERROR: Coverage could not be calculated" + exit 1 +fi + +echo "Final coverage: $COVERAGE%" + +if (( $(echo "$COVERAGE < 80" | bc -l) )); then + echo "❌ Coverage gate failed (minimum 80%)" + exit 1 +fi + +echo "Coverage gate passed" From 5e050b44f3bd544be03c86a27c24d66157953e7e Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:34:59 +0000 Subject: [PATCH 3/9] Change runner to ubuntu-latest for coverage job --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 7c6ab9fc..39c93336 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -11,7 +11,7 @@ permissions: jobs: coverage-gate: name: Go Coverage Gate - runs-on: [self-hosted, linux, eks] + runs-on: ubuntu-latest steps: - name: Checkout PR code From 0d77499fbc5726b9f8cdb9eb68479d6c4aa263f3 Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:43:12 +0000 Subject: [PATCH 4/9] Update coverage workflow to use self-hosted runners --- .github/workflows/coverage.yaml | 43 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 39c93336..918b87ac 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -10,14 +10,13 @@ permissions: jobs: coverage-gate: - name: Go Coverage Gate - runs-on: ubuntu-latest + runs-on: [self-hosted, linux, eks] steps: - name: Checkout PR code uses: actions/checkout@v4 with: - fetch-depth: 0 # Needed to compare with base branch + fetch-depth: 0 - name: Setup Go uses: actions/setup-go@v5 @@ -27,28 +26,40 @@ jobs: - name: Run coverage on PR branch run: | chmod +x ./scripts/coverage.sh - ./scripts/coverage.sh - mv coverage.percent coverage.pr + COV_OUTPUT=$(./scripts/coverage.sh) + + echo "$COV_OUTPUT" + + PR_COVERAGE=$(echo "$COV_OUTPUT" \ + | grep "Final coverage:" \ + | awk '{print $3}' \ + | sed 's/%//') + + echo "PR_COVERAGE=$PR_COVERAGE" >> $GITHUB_ENV - name: Checkout base branch - run: | - git checkout origin/${{ github.base_ref }} + run: git checkout origin/${{ github.base_ref }} - name: Run coverage on base branch run: | - ./scripts/coverage.sh - mv coverage.percent coverage.base + COV_OUTPUT=$(./scripts/coverage.sh) + + echo "$COV_OUTPUT" + + BASE_COVERAGE=$(echo "$COV_OUTPUT" \ + | grep "Final coverage:" \ + | awk '{print $3}' \ + | sed 's/%//') + + echo "BASE_COVERAGE=$BASE_COVERAGE" >> $GITHUB_ENV - name: Compare coverage (PR vs base) run: | - PR_COV=$(cat coverage.pr) - BASE_COV=$(cat coverage.base) - - echo "PR Coverage : $PR_COV%" - echo "Base Coverage : $BASE_COV%" + echo "PR Coverage : ${PR_COVERAGE}%" + echo "Base Coverage : ${BASE_COVERAGE}%" - if (( $(echo "$PR_COV < $BASE_COV" | bc -l) )); then - echo "❌ Coverage reduced from $BASE_COV% → $PR_COV%" + if (( $(echo "${PR_COVERAGE} < ${BASE_COVERAGE}" | bc -l) )); then + echo "❌ Coverage reduced from ${BASE_COVERAGE}% → ${PR_COVERAGE}%" exit 1 fi From 7e7793d20b18f7c98ee70b8bcf5927bddc524f8b Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:44:04 +0000 Subject: [PATCH 5/9] Update coverage.yaml --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 918b87ac..110a39bb 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -10,7 +10,7 @@ permissions: jobs: coverage-gate: - runs-on: [self-hosted, linux, eks] + runs-on: ubuntu-latest steps: - name: Checkout PR code From 99ff13014edb9d65ba6a03e428d808a0e21b348e Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:47:10 +0000 Subject: [PATCH 6/9] Update coverage workflow to install 'bc' and simplify checks Added installation step for 'bc' to enable float comparison in coverage checks. Removed base branch coverage comparison steps. --- .github/workflows/coverage.yaml | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 110a39bb..f7d5f03c 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -23,6 +23,9 @@ jobs: with: go-version-file: go.mod + - name: Install bc (for float comparison) + run: sudo apt-get update && sudo apt-get install -y bc + - name: Run coverage on PR branch run: | chmod +x ./scripts/coverage.sh @@ -38,29 +41,4 @@ jobs: echo "PR_COVERAGE=$PR_COVERAGE" >> $GITHUB_ENV - name: Checkout base branch - run: git checkout origin/${{ github.base_ref }} - - - name: Run coverage on base branch - run: | - COV_OUTPUT=$(./scripts/coverage.sh) - - echo "$COV_OUTPUT" - - BASE_COVERAGE=$(echo "$COV_OUTPUT" \ - | grep "Final coverage:" \ - | awk '{print $3}' \ - | sed 's/%//') - - echo "BASE_COVERAGE=$BASE_COVERAGE" >> $GITHUB_ENV - - - name: Compare coverage (PR vs base) run: | - echo "PR Coverage : ${PR_COVERAGE}%" - echo "Base Coverage : ${BASE_COVERAGE}%" - - if (( $(echo "${PR_COVERAGE} < ${BASE_COVERAGE}" | bc -l) )); then - echo "❌ Coverage reduced from ${BASE_COVERAGE}% → ${PR_COVERAGE}%" - exit 1 - fi - - echo "✅ Coverage not reduced" From b6c0b55c783cdfdb70452dfd1492f416f45464c3 Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:54:06 +0000 Subject: [PATCH 7/9] Add coverage comparison step in GitHub Actions --- .github/workflows/coverage.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index f7d5f03c..5f77c5f5 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -42,3 +42,30 @@ jobs: - name: Checkout base branch run: | + git fetch origin + git checkout origin/${{ github.base_ref }} + + - name: Run coverage on base branch + run: | + COV_OUTPUT=$(./scripts/coverage.sh) + + echo "$COV_OUTPUT" + + BASE_COVERAGE=$(echo "$COV_OUTPUT" \ + | grep "Final coverage:" \ + | awk '{print $3}' \ + | sed 's/%//') + + echo "BASE_COVERAGE=$BASE_COVERAGE" >> $GITHUB_ENV + + - name: Compare coverage (PR vs base) + run: | + echo "PR Coverage : ${PR_COVERAGE}%" + echo "Base Coverage : ${BASE_COVERAGE}%" + + if (( $(echo "${PR_COVERAGE} < ${BASE_COVERAGE}" | bc -l) )); then + echo "❌ Coverage reduced from ${BASE_COVERAGE}% → ${PR_COVERAGE}%" + exit 1 + fi + + echo "✅ Coverage not reduced" From a4fd76ec4260590e38cb00ce6e303d43a0a6da64 Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:59:50 +0000 Subject: [PATCH 8/9] Refactor coverage workflow steps and improve readability --- .github/workflows/coverage.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 5f77c5f5..61afd62a 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -23,7 +23,7 @@ jobs: with: go-version-file: go.mod - - name: Install bc (for float comparison) + - name: Install bc run: sudo apt-get update && sudo apt-get install -y bc - name: Run coverage on PR branch @@ -41,11 +41,14 @@ jobs: echo "PR_COVERAGE=$PR_COVERAGE" >> $GITHUB_ENV - name: Checkout base branch + if: github.event_name == 'pull_request' run: | + echo "Base branch: ${{ github.base_ref }}" git fetch origin git checkout origin/${{ github.base_ref }} - name: Run coverage on base branch + if: github.event_name == 'pull_request' run: | COV_OUTPUT=$(./scripts/coverage.sh) @@ -59,6 +62,7 @@ jobs: echo "BASE_COVERAGE=$BASE_COVERAGE" >> $GITHUB_ENV - name: Compare coverage (PR vs base) + if: github.event_name == 'pull_request' run: | echo "PR Coverage : ${PR_COVERAGE}%" echo "Base Coverage : ${BASE_COVERAGE}%" From 1d08a1ae6f64939823ce5da62d5f34875a4f58fa Mon Sep 17 00:00:00 2001 From: YuvrajBhupati <66075699+YuvrajBhupati@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:08:16 +0000 Subject: [PATCH 9/9] Fix echo statement for coverage script --- scripts/coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/coverage.sh b/scripts/coverage.sh index aea698cc..10140c20 100644 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -echo "Running tests and generating raw coverage..." +echo "Running tests and generating raw coverage......." go test ./... -coverprofile=coverage.raw.out echo "Filtering coverage (excluding generated & entry code)..."