Skip to content

Commit

Permalink
Publishing code coverage report using codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuchalla committed Jul 7, 2023
1 parent 03d5a31 commit 10a30ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,24 @@ jobs:
- name: Run Unit Tests
run: |
ginkgo -r --randomize-all --randomize-suites --fail-on-pending --cover --trace --v --coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage-report.html
- name: Upload Coverage Report to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.out
flag: unittests
- name: Generate Coverage Comment
id: generate-comment
run: |
COVERAGE_PERCENT=$(go tool cover -func=coverage.out | grep total | awk '{print $NF}')
COMMENT_MESSAGE="Code coverage: $COVERAGE_PERCENT%"
echo "::set-output name=comment::$COMMENT_MESSAGE"
- name: Comment on Pull Request
run: |
COMMENT_BODY="${{ steps.generate-comment.outputs.comment }}"
curl \
-X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"body\":\"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# go-commons

[![codecov](https://codecov.io/github/cloud-bulldozer/go-commons/branch/main/graph/badge.svg?token=CFPW1UV7FO)](https://codecov.io/github/cloud-bulldozer/go-commons)

0 comments on commit 10a30ea

Please sign in to comment.