php-actions / phpunit

Run PHPUnit tests in Github Actions.
108 stars 24 forks source link

Php unit --coverage-text option #16

Closed CorentinGuerrero closed 3 years ago

CorentinGuerrero commented 4 years ago

Hi, it's possible to launch test with --coverage-text option ?

g105b commented 3 years ago

Hi @CorentinGuerrero,

Yep, it's possible since the release of v8 and v9. Take a look at the actions.yml:

https://github.com/php-actions/phpunit/blob/master/action.yml#L63-L65

You can pass any arguments you want into the args input.

Example file:

      - name: PHPUnit Tests
        uses: php-actions/phpunit@v9
        with:
          args: --coverage-text

For coverage to work, you'll need to be running PHPUnit with XDebug installed. This isn't currently supported by this action, so may I ask if this is something you are planning to provide yourself (using a custom PHP runtime in some way), or do you want me to include XDebug by default in the PHPUnit action? I think the latter, but I'm just confirming with you to understand your use case better.

Gared commented 3 years ago

Hey, I would like to have XDebug included by default in this action to get the clover report generated 👍

g105b commented 3 years ago

@Gared you're in luck. I'm currently working on including a PHP configuration option to phpunit, composer, phpstan and behat php-actions repositories. This will allow you to choose between PHP versions and installed extensions. I'm still figuring this out, so any feedback is welcome, but I hope to see it completed this week.

Gared commented 3 years ago

Hey @g105b good to hear! If you have anything to test or need feedback I'd be happy to test and help 👍

g105b commented 3 years ago

I just want to keep you in the loop. I have built a docker image that has all the versions of PHP installed, with a simple script to switch which version is currently active. I will expose this as an input on the Github action, but the problem I'm having is that Github Package Repository doesn't allow you to host packages publically, even though it is open source... I'm a bit confused as how to use the package properly, but once I've solved this, our issue should be resolved :)

g105b commented 3 years ago

I've reached out to Github support to see if they can help:

Hi Octocats!

I'm reaching out for some support because I have ran out of ideas for how to solve this. I've read that Github Package Repository is and will never be public (without requiring authentication), but this puts me into an impossible situation, but I hope you can show me how it is easily fixed.

I have a Github Action here with a Dockerfile here: https://github.com/php-actions/phpunit/blob/17-php-versions/Dockerfile .

As you can see, the file is currently being tweaked to attempt to use the base image from my Github Package Repository. I have tried authenticating using HTTP basic auth, using a personal access token, but Github conveniently detected the token in my commit and revoked the token.

Is there a way to store the token as a secret to be used within the Dockerfile? If not, please can you kindly explain to me the general workflow for what I'm trying to achieve.

For context, here's the consequence of using Github Package Repository: https://github.com/php-actions/example-phpunit/runs/1282426066?check_suite_focus=true

Thanks in advance, Greg.

g105b commented 3 years ago

I've had a response from Github, which I will attempt to follow now:

What you could do it publish your image to the new GitHub Container Registry at ghcr.io. This new registry does support real public images.

For example, you could push your image to ghcr.io/php-actions/php-build:latest using a PAT with the write:packages scope (you can't use ${{ github.token }}).

You can them make it public like this: https://docs.github.com/en/free-pro-team@latest/packages/getting-started-with-github-container-registry/about-github-container-registry#visibility-and-access-permissions-for-container-images

I hope that helps!

Regards, Jamie.

g105b commented 3 years ago

Woo! Finally, I have a working solution. Sorry it's taken so long, but I've had to have been doing this alongside paid work.

I've got a system that allows PHP, PHPUnit and Composer to have their versions and arguments managed purely from the action's yaml configuration. I'll merge things and make a release on all the actions later today after updating the readmes.

Gared commented 3 years ago

@g105b That sounds great! Let me know if I can test something 👍

g105b commented 3 years ago

@Gared your testing will be really useful. All php-actions repositories are now based off our own base image: https://github.com/php-actions/php-build, which means we have full control over the environment now. Previously we were basing off the official Composer/PhpUnit docker hub images, which meant we were at the mercy of how those images worked.

I haven't tested with xdebug myself, so I will be very grateful for your input on the testing here. Please see an example test run using the new functionality here: https://github.com/php-actions/example-phpunit/actions/runs/354003732/workflow, take note of the action versions used.

Xdebug should be available for you in the base image. If any further configuration is necessary, I'll do my best to configure the base image so that it works for you and other. If you want to experiment locally within the Docker image, please use this command: docker run -it ghcr.io/php-actions/php-build:latest /bin/bash. That will drop you into a bash shell within the Docker image. You can use switch-php-version X.Y to change which installed PHP is used.

Looking forward to hearing your feedback.

Gared commented 3 years ago

@g105b Done my first testing right now and it's working, great! 👍 Unfortunately the build time was raised by two minutes. Anyway thanks for your work!

g105b commented 3 years ago

@Gared great to hear it's working for you, but the speed of the new GitHub package repository is really concerning. It took about half an hour to push the image, even though it was only about 300mb. Maybe it'll improve over time, but let's assume not. I wonder how its speed can be improved?