Skip to content

Add Code Coverage (Github workflow) #183

Description

@Sebbo94BY

What about implementing a code coverage badge to the README, so that everyone can see how much code is covered by the tests?

Codecov for example provides a Github action, so we could simply generate the coverage report using a Github workflow and upload it to Coverage: https://github.com/marketplace/actions/codecov

But therefore, somebody with enough permissions to this repository is required:

Example workflow file:

# .github/workflows/codecov.yml
name: "Codecov"

on:
  push:
    branches:
      - master
      - main
      - dev
  pull_request:
  schedule:
    - cron: '0 15 * * 2'

jobs:
  phpunit-coverage:
    strategy:
      fail-fast: false
      matrix:
        php_versions: [
          '8.0',
          '8.1',
          '8.2',
        ]
    name: PHP ${{ matrix.php_versions }}
    runs-on: ubuntu-latest
    steps:
    - name: checkout repository
      uses: actions/checkout@v3

    - name: install php ${{ matrix.php_versions }} with extensions
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php_versions }}
        extensions: json ctype openssl ssh2
        coverage: none
        tools: none

    - name: install dependencies
      uses: php-actions/composer@v6
      with:
        dev: yes
        php_version: ${{ matrix.php_versions }}
        php_extensions: json ctype openssl ssh2

    - name: generate phpunit coverage report
      run: ./vendor/bin/phpunit --coverage-clover=coverage.xml

    - name: upload coverage report to codecov
      uses: codecov/codecov-action@v3
      with:
          files: ./coverage.xml

And in the README something like this:

[![Code Coverage](https://codecov.io/gh/planetteamspeak/ts3phpframework/branch/master/graph/badge.svg)](https://codecov.io/gh/planetteamspeak/ts3phpframework)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions