chore(ci): coverage #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Quality" | |
on: | |
pull_request: | |
branches: | |
- main | |
- master | |
pull_request_target: | |
types: | |
- opened | |
- edited | |
- synchronize | |
jobs: | |
coverage: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Read coverage data | |
id: coverage | |
run: | | |
echo "::set-output name=lines::$(jq '.total.lines.pct' coverage/coverage-summary.json)" | |
echo "::set-output name=statements::$(jq '.total.statements.pct' coverage/coverage-summary.json)" | |
echo "::set-output name=functions::$(jq '.total.functions.pct' coverage/coverage-summary.json)" | |
echo "::set-output name=branches::$(jq '.total.branches.pct' coverage/coverage-summary.json)" | |
- name: Post coverage comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const lines = process.env.lines; | |
const statements = process.env.statements; | |
const functions = process.env.functions; | |
const branches = process.env.branches; | |
const commentBody = ` | |
### Jest Coverage Report 📊 | |
|Metric | Coverage (%) | | |
|------------|----------------| | |
| Lines | ${lines}% | | |
| Statements | ${statements}% | | |
| Functions | ${functions}% | | |
| Branches | ${branches}% | | |
`; | |
const { context, github } = require('@actions/github'); | |
const { data: comments } = await github.issues.listComments({ | |
...context.repo, | |
issue_number: context.issue.number, | |
}); | |
const existingComment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('### Jest Coverage Report 📊')); | |
if (existingComment) { | |
await github.issues.updateComment({ | |
...context.repo, | |
comment_id: existingComment.id, | |
body: commentBody, | |
}); | |
} else { | |
await github.issues.createComment({ | |
...context.repo, | |
issue_number: context.issue.number, | |
body: commentBody, | |
}); | |
} |