PHP Github actions guidelines

What the Action does

This action sets up the PHP environment on the Ubuntu machine. It validates and caches Composer packages. In the end, it runs a code coverage tool by Codecov. The package is then available on the Packagist repository.

Notes

  • It's recommended to use a Linux machine for building - jobs.<name>.runs-on property.
  • PHP versions are specified in strategy.matrix.destination property.
  • The action uses 3rd party shivammathur/setup-php@v2 action for setting PHP environment.
  • Package on Packagist will be automatically crawled periodically. You just have to make sure you keep the composer.json file up to date - for more info take a look at the Packagist documentation.
  • Version of the package on Packagist is automatically fetched from the tag.

GitHub Action example

  • PHP project using Composer and Codecov
name: Build & Test & Report

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:        
        php-versions: ['7.0', '7.1', '7.2', '7.3']
        phpunit-versions: ['latest']
    steps:
    - uses: actions/checkout@v2
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: $
        extensions: mbstring, intl
        ini-values: post_max_size=256M, max_execution_time=180
        coverage: xdebug        
        tools: php-cs-fixer, phpunit:$
    - name: Validate composer.json and composer.lock
      run: composer validate --strict
    - name: Cache Composer packages
      id: composer-cache
      uses: actions/cache@v2
      with:
        path: vendor
        key: $-php-$
        restore-keys: |
          $-php-
    - name: Install dependencies
      run: composer install --prefer-dist --no-progress --no-suggest
    - name: Coverage
      run: vendor/bin/phpunit --coverage-clover coverage.xml
    - name: Codecov
      uses: codecov/codecov-action@v1