Skip to content

Commit

Permalink
Add coverage workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Raphaël Pinson <[email protected]>
  • Loading branch information
raphink committed Sep 26, 2024
1 parent d272b93 commit b502a0a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 62 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test and Coverage

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test-and-coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23' # Specify your Go version here

- name: Run tests and generate coverage for PR
run: go test ./... -coverprofile=pr-coverage.out -covermode=atomic

- name: Generate coverage report for main branch
run: |
git fetch origin main
git checkout main
go test ./... -coverprofile=main-coverage.out -covermode=atomic
- name: Compare coverage and report
run: |
# Generate coverage reports
go tool cover -func=pr-coverage.out > pr-coverage.txt
go tool cover -func=main-coverage.out > main-coverage.txt
# Extract total coverage values
pr_coverage=$(grep total: pr-coverage.txt | awk '{print $3}')
main_coverage=$(grep total: main-coverage.txt | awk '{print $3}')
echo "PR Coverage: $pr_coverage"
echo "Main Branch Coverage: $main_coverage"
# Compare coverage
pr_percentage=${pr_coverage%\%}
main_percentage=${main_coverage%\%}
if (( $(echo "$pr_percentage > $main_percentage" | bc -l) )); then
echo "Coverage has increased from $main_coverage to $pr_coverage 🎉" > coverage-report.txt
elif (( $(echo "$pr_percentage < $main_percentage" | bc -l) )); then
echo "Coverage has decreased from $main_coverage to $pr_coverage ⚠️" > coverage-report.txt
else
echo "Coverage is unchanged at $pr_coverage" > coverage-report.txt
fi
- name: Post coverage comparison in PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Coverage Report
path: coverage-report.txt
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/isovalent/credly-go

go 1.23.0
go 1.23

require github.com/stretchr/testify v1.9.0

Expand Down

0 comments on commit b502a0a

Please sign in to comment.