Setting Github Actions with Pest
Expected Result
This Github Action is used in https://apinotready.com
Whole Github Action
If you don't want to go further, and just want the action itself. Feel free :)
1name: ApiNotReady.com 2 3on: [push, pull_request] 4 5jobs: 6 unit-tests: 7 runs-on: ubuntu-latest 8 steps: 9 - name: Checkout10 uses: actions/checkout@v211 12 - name: Setup PHP with Xdebug13 uses: shivammathur/setup-php@v214 with:15 php-version: '7.4'16 coverage: xdebug17 18 - name: Copy .env19 run: php -r "file_exists('.env') || copy('.env.example', '.env');"20 21 - name: Cache dependencies22 uses: actions/cache@v223 with:24 path: ~/.composer/cache/files25 key: dependencies-composer-${{ hashFiles('composer.json') }}26 27 - name: Install Dependencies28 run: composer install -q --no-ansi --no-interaction --no-progress --prefer-dist --optimize-autoloader29 30 - name: Generate key31 run: php artisan key:generate32 33 - name: Clear Config34 run: php artisan config:clear35 36 - name: Directory Permissions37 run: chmod -R 777 storage bootstrap/cache38 39 - name: Execute tests40 run: vendor/bin/pest --coverage --min=90
Default from Github
The default action to Laravel from Github only comes with the uses: actions/checkout@v2
, but, as we are going to use the coverage from Pest php, we will need to set xdebug, as well.
This is the reason we need to add:
1- name: Setup PHP with Xdebug2 uses: shivammathur/setup-php@v23 with:4 php-version: '7.4'5 coverage: xdebug
Error with PHPUnit
When using the default action from Github action, you will receive the following error:
1option --coverage is ambiguous
The issue here is the --no-script
when running composer install. You must remove this argument when running it.
Setting minimun coverage
As you can find in Pest documentation, you must add the following arguments when you run the tests:
1- name: Execute tests2 run: vendor/bin/pest --coverage --min=90