Skip to content

Commit

Permalink
Adding code coverage comment in the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachinbisht27 committed Sep 13, 2023
1 parent a65cd4a commit f8d0016
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

- name: Code coverage comment
- name: Post Code Coverage Comment
run: |
echo "Code Coverage Report" > coverage_comment.txt
echo "![Coverage](https://img.shields.io/badge/coverage-$(grep -oP 'covered="(\K[^"]+)' coverage.xml)%25-brightgreen)" >> coverage_comment.txt
echo "Coverage details are available [here](./coverage.xml)." >> coverage_comment.txt
echo "::set-env name=GH_TOKEN::${{ secrets.GITHUB_TOKEN }}"
gh pr comment "$(cat coverage_comment.txt)"
# Set up the comment payload in a JSON file
echo '{"body": "'$(cat coverage_comment.txt | sed ':a;N;$!ba;s/\n/\\n/g')'"}' > comment_payload.json
# Post the comment using the GitHub API
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d @comment_payload.json \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments"

0 comments on commit f8d0016

Please sign in to comment.