github action purposing on making coverage badge for jest,
super convinently.
combine 2 action jest-bades-action and
github-pages-deploy-action
if you put ci steps in 2 line, then badge automatically uploaded to your repo.
and put the url to your page. (ex. README.md)
then whenever update your code (pushed) then coverage will be updated imediately.
it looks like only work for 100% badge, but actually cacluated..
(cause this example -simple-csv-parser- cover 100%)...
other example.
[![Coverage Status](https://github.com/nolleh/simple-csv-parser/raw/gh-pages/badges/coverage-jest%20coverage.svg?raw=true)](https://nolleh.github.io/simple-csv-parser/badges/coverage-jest%20coverage.svg?raw=true)
don't be bothered to permission for your repository (token or private repo or whatever)
because this badge file no need to uploaded to elsewhere but your repo.
add to your github action...
- run test to make json-summary in your package.json or jest.config.json, add json-summary
{
"jest": {
"coverageReporters": ["json-summary", "text"]
}
}
- add jest-badge-deploy-action
name: ci
on: [push]
jobs:
test-and-push-badge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
- name: Install
run: |
npm install -g pnpm
pnpm i
- name: Test and Cov
run: pnpm test:cov
### this step!
- name: Cov Badge And Publish
uses: nolleh/jest-badge-deploy-action@latest
in your markdown (README.md)
import your gh-pages branches svg.
โ ๏ธ NOTE: you should change the repo path (simple-csv-parser...) to yours.
[![Coverage Status](https://github.com/nolleh/simple-csv-parser/raw/gh-pages/badges/coverage-jest%20coverage.svg?raw=true)](https://nolleh.github.io/simple-csv-parser/badges/coverage-jest%20coverage.svg?raw=true)
- gh-pages branch is special branch in github to upload static files. (deployed)
- by using jest:json-summary, generate badge.
- the generated badges pushed to the special branch (gh-pages)
- these all process worked in your ci workflow, and it has permission to your repository.
- Booyah!
ci can be fails with
remote: Permission to nolleh/simple-csv-parser.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/nolleh/simple-csv-parser/': The requested URL returned error: 403
make sure ci can access your repo. (to commit/push)
-
go to repository settings > Actions > general
-
scrolls down to
workflow permission
, and check 'Read and write permissions'
- this will be applied to your .github/workflow's permission.