planetteamspeak / ts3phpframework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
https://www.planetteamspeak.com
GNU General Public License v3.0
212 stars 59 forks source link

Add Code Coverage (Github workflow) #183

Open Sebbo94BY opened 1 year ago

Sebbo94BY commented 1 year ago

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)
ronindesign commented 1 year ago

We have/had coverage by Coveralls (via Travis CI.) But I'm open to alternatives if there is a popular/more modern choice, Codecov looks pretty great. Do we want to go with that? I'll see about getting things configured.

ronindesign commented 1 year ago

So I won't be able to add the repo secret here, but I'm able to add it on ronindesign/ts3phpframework, then we can use that repo and a mirror branch to point the coverage badge at:

[![Code Coverage](https://codecov.io/gh/ronindesign/ts3phpframework/branch/upstream-master/graph/badge.svg)](https://codecov.io/gh/roninsystems/ts3phpframework)
Sebbo94BY commented 1 year ago

Ah, good point. We can also use Travis CI and/or Coveralls. I don't know, what's better or if there are even any differences besides the name and UI.

The problem is, that you always need to sync your fork with this repo, so that it reflects the actual percentage here, correct?

That's the reason, why I rather would like to implement it directly in the source repo. But I'll leave this up to you.

There seems to exist a Github action to easily upload the PHPUnit coverage result to Coverallls: https://github.com/marketplace/actions/coveralls-github-action (so we could use my above example with coveralls instead of codecov)

ronindesign commented 1 year ago

Yes, that's correct, it would definitely be a work-around, but maybe we can automate the fork sync using https://github.com/apps/pull ?

Otherwise, I don't see a way of making this happen directly in this repo as Sven hasn't enabled this functionality in the past. So my recommendation would be to not wait for that to happen and to just find an alternative solution instead.

Sebbo94BY commented 1 year ago

Yeah, we can try this - but at the end, you still have to manually click on merge. So instead of using this app, you could also simply click on "sync" - which avoids the pull request. :D

ronindesign commented 1 year ago

The app auto-approves the PR, should be 100% automated.

Sebbo94BY commented 1 year ago

Ah, ok. Yeah, then it would be perfect. :)

Sebbo94BY commented 1 year ago

@ronindesign do you set up everything and add the badge to the README?

ronindesign commented 1 year ago

Unfortunately, I've not had time to prioritize this. I will try and make time to add this, but I can't guarantee a timeframe. Appreciate your patience on this.