Skip to content

Commit

Permalink
add cov report
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayraykk committed Jan 12, 2024
1 parent b29449e commit fbaede6
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,36 @@ jobs:
coverage run tests/run.py
- name: Generate coverage report
run: |
coverage report -m
coverage report -m > coverage.txt
- name: Update or Post coverage report as PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const report = fs.readFileSync('coverage.txt', {encoding:'utf8', flag:'r'});
const commentIdentifier = '<!-- coverage-comment -->';
const commentBody = `${commentIdentifier}\n📊 **Coverage Report**:\n\`\`\`\n${report}\n\`\`\``;
const issue_number = context.issue.number;
const comments = await github.issues.listComments({
...context.repo,
issue_number
});
const coverageComment = comments.data.find(comment => comment.body.includes(commentIdentifier));
if (coverageComment) {
await github.issues.updateComment({
...context.repo,
comment_id: coverageComment.id,
body: commentBody
});
} else {
await github.issues.createComment({
...context.repo,
issue_number,
body: commentBody
});
}

0 comments on commit fbaede6

Please sign in to comment.