coverage-badges-cli

Create coverage badges from coverage reports. Using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers).

Usage no npm install needed!

<script type="module">
  import coverageBadgesCli from 'https://cdn.skypack.dev/coverage-badges-cli';
</script>

README

coverage-badges-cli

Build & Deploy Coverage Status npm version Download NPM

Create coverage badges from coverage reports. Using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers).

Don't worry about the coverage.io service is down.

Install

$ npm i coverage-badges-cli

Example

{
  "scripts": {
    "coverage": "jest --coverage"
    "make-badges": "coverage-badges",
  },
  "jest": {
    "coverageReporters": [
      "lcov",
      "json-summary"
    ],
  }
}

This config creates a coverage badge in a default directory ./badges.

You can add ![Coverage](./coverage/badges.svg) to your README.md after the badge creation.

Github Actions

Input Parameters

  • source - The path of the target file "coverage-summary.json".
  • output - Output image path.
  • style - Badges style: flat, classic. (default classic)
- name: Create Coverage Badges
  uses: jaywcjlove/coverage-badges-cli@main
  with:
    style: flat
    source: coverage/coverage-summary.json
    output: coverage/badges.svg

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./build

Using the command line

name: Build & Deploy
on:
  push:
    branches:
      - master

jobs:
  build-deploy:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: 14

    - run: npm install
    - run: npm run build
    - run: npm run coverage
    - run: npm i coverage-badges-cli -g
    - run: coverage-badges --output coverage/badges.svg

    - name: Deploy
      uses: peaceiris/actions-gh-pages@v3
      if: github.ref == 'refs/heads/master'
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./coverage

Command Help

Usage: coverage-badges [options] [--help|h]

Options:

  --version, -v  Show version number
  --help, -h     Displays help information.
  --output, -o   Output directory.
  --source, -s   The path of the target file "coverage-summary.json".
  --style        Badges style: flat, flat-square.

Example:

  npm coverage-badges-cli --output coverage/badges.svg
  npm coverage-badges-cli --style plastic
  npm coverage-badges-cli --source coverage/coverage-summary.json

Development

$ npm i
$ npm run build
$ npm run watch

See also

License

MIT © Kenny Wong