Skip to content

Coverage Badge

Actions
Badges for test results and code coverage
v1.0.1
Latest
Star (49)

coverage-badge-action  cov

Similar Projects

Difference

  • ✅ No gist-id required
  • ✅ No github-token required
  • ✅ No entire upload to gh-pages
  • ✅ Just patch and push to gh-pages
  • ✅ Supports Node.js & pytest

Update: supports pytest

```yml
# .github/workflows/test.yml
# ...
- name: Set up Python 3.10
  uses: actions/setup-python@v3
  with:
    python-version: "3.10"

- name: Install
  run: |
    python -m pip install --upgrade pip
    pip install pytest pytest-cov
    pip install -r requirements.txt
- name: Test and Coverage
  run: python -m pytest --cov --cov-report json
# ...
```

Usage

  1. Make sure you have gh-pages branch and have GitHub Pages on:

    # if you don't have gh-pages yet, create an empty one
    git stash save my_wip_state  # if not clean (1)
    git switch --orphan gh-pages
    git commit --allow-empty -m "Initial commit"
    git push -u origin gh-pages
    
    git checkout my_original_branch
    git stash apply stash^{/my_wip_state}  # if not clean (2)

    See Step.6 in 🚀 Blog Setup via Github Fork

    6. (Important) Select both gh-pages and / (root) in Project Settings -> Pages

  2. Give workflow permission:

    On your repository Settings -> Action -> General -> Workflow permissions choose Read and Write permissions

  3. Whatever the coverage tool is, don't forget to have reporter=json-summary enabled:

    // package.json
    -  "test:cov": "c8 xv",
    +  "test:cov": "c8 -r text -r json-summary xv",
    // or
    -  "coverage": "nyc mocha",
    +  "coverage": "nyc -r text -r json-summary mocha",
  4. Add the action to your current workflow

    # .github/workflows/test.yml
    name: Test
    on: [push, pull_request, workflow_dispatch]
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          # Your original steps
          - uses: actions/checkout@v3
          - uses: actions/setup-node@v3
          - name: Install
            run: npm install
          - name: Test and Coverage
            run: npm run test:cov  # or npm run coverage
    
          # Add this
          - name: Update Coverage Badge
            # GitHub actions: default branch variable
            # https://stackoverflow.com/questions/64781462/github-actions-default-branch-variable
            if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
            uses: we-cli/coverage-badge-action@main
  5. Add the badge to your README.md

    <!-- README.md -->
    + [![cov](https://<you>.github.io/<repo>/badges/coverage.svg)](https://github.com/<you>/<repo>/actions)

    Replace the <you> and <repo> above, like:

    <!-- README.md -->
    + [![cov](https://we-cli.github.io/jayin/badges/coverage.svg)](https://github.com/we-cli/jayin/actions)

    and you get:

    cov

Coverage Badge is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Badges for test results and code coverage
v1.0.1
Latest

Coverage Badge is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.