chore(ci): coverage #11
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: | |
permissions: | |
contents: read | |
issues: write | |
pull-requests: write | |
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 | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/yarn | |
node_modules | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-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, | |
}); | |
} |