Skip to content

chore(ci): coverage

chore(ci): coverage #9

Workflow file for this run

name: "Quality"
on:
pull_request:
branches:
- main
- master
pull_request_target:
types:
- opened
- edited
- synchronize
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Run tests
run: yarn test --coverage || true
- name: Read coverage data
id: coverage
run: |
echo "lines=$(jq '.total.lines.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
echo "statements=$(jq '.total.statements.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
echo "functions=$(jq '.total.functions.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
echo "branches=$(jq '.total.branches.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
- name: Post coverage comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const lines = `${{ steps.coverage.outputs.lines }}`.trim();
const statements = `${{ steps.coverage.outputs.statements }}`.trim();
const functions = `${{ steps.coverage.outputs.functions }}`.trim();
const branches = `${{ steps.coverage.outputs.branches }}`.trim();
const commentBody = `
### Jest Coverage Report 📊
|Metric | Coverage (%) |
|------------|----------------|
| Lines | ${lines}% |
| Statements | ${statements}% |
| Functions | ${functions}% |
| Branches | ${branches}% |
`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.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.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody,
});
}