Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Code Coverage (Github workflow) #183

Open
Sebbo94BY opened this issue Feb 19, 2023 · 9 comments
Open

Add Code Coverage (Github workflow) #183

Sebbo94BY opened this issue Feb 19, 2023 · 9 comments
Assignees

Comments

@Sebbo94BY
Copy link
Collaborator

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
Copy link
Collaborator

ronindesign commented Feb 19, 2023

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
Copy link
Collaborator

ronindesign commented Feb 19, 2023

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
Copy link
Collaborator Author

Sebbo94BY commented Feb 19, 2023

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
Copy link
Collaborator

ronindesign commented Feb 19, 2023

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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

@Sebbo94BY
Copy link
Collaborator Author

Sebbo94BY commented Feb 19, 2023

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

@Sebbo94BY
Copy link
Collaborator Author

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

@ronindesign
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants