Seth Phat
Seth Phat Blog

Follow

Seth Phat Blog

Follow
GitHub Action script for PHP CI

GitHub Action script for PHP CI

Seth Phat's photo
Seth Phat
ยทDec 17, 2022ยท

1 min read

Hey guys,

A quick trick & sharing with y'all for my script to run PHPUnit with GitHub Action.

FYI some of my latest repositories are using this script:

GitHub Action script x PHPUnit

Will be affected for:

  • A new commit to the main branch

  • New PRs that point to the main branch

Flow:

  • Install PHP 8.1 + pcov (best PHP coverage driver at the moment)

  • Install dependencies

  • (Optional) Setup env

  • Run the test with the coverage option

  • (Optional) Upload to CodeCov for the coverage result

name: Build & Test
on:
    pull_request:
        branches:
            - 'main'
        types: [ opened, synchronize, reopened, ready_for_review ]
    push:
        branches:
            - 'main'

jobs:
    build_php81:
        runs-on: ubuntu-latest
        steps:
            -   uses: actions/checkout@v3
                if: success()

            -   name: Setup PHP with coverage driver
                uses: shivammathur/setup-php@v2
                with:
                    php-version: '8.1'
                    coverage: pcov

            -   name: Setup
                if: success()
                run: |
                    php -v
                    composer install --no-interaction

            -   name: PHPUnit tests with coverage
                if: success()
                run: |
                    composer test-coverage

            -   name: upload coverage to codecov.io
                uses: codecov/codecov-action@v1
                with:
                    token: ${{ secrets.CODECOV_TOKEN }}
                    file: ./coverage.xml

Feel free to copy it and change it to your desired flow ๐Ÿ˜‰

Cheers!

ย 
Share this