Skip to content

PHP CI

PHP CI #1682

Workflow file for this run

# For details of what checks are run for PRs please refer below
# docs: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: PHP CI
on:
push:
branches: ["main", "master", "next"]
tags: ["v*"]
pull_request:
workflow_dispatch:
schedule:
# schedule dayly tests, since dependencies are not intended to be locked
# this means: at 23:42
- cron: '42 23 * * *'
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
env:
PHP_VERSION_LATEST: "8.3"
PHP_PROJECT_EXT: dom,json,libxml # via `composer info -pt`
REPORTS_DIR: CI_reports
TESTS_REPORTS_ARTIFACT: tests-reports
TYPES_REPORTS_ARTIFACT: types-reports
jobs:
composer-validate:
name: Composer Validate
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION_LATEST }}
extensions: ${{ env.PHP_PROJECT_EXT }}
tools: 'composer:v2'
coverage: none
- name: Validate composer.json and composer.lock
run: composer validate --no-interaction
phpunit:
name: PHPUnit (${{ matrix.os}}, php${{ matrix.php }}, ${{ matrix.dependencies }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ "ubuntu-latest" ]
php:
- "8.3" # highest supported
- "8.2"
- "8.1" # lowest supported
dependencies: [ "lowest", "highest" ]
include:
- # Windows highest
os: windows-latest
php: "8.3"
dependencies: "highest"
- # MacOS highest
os: macos-latest
php: "8.3"
dependencies: "highest"
timeout-minutes: 30
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: dir setup
run: mkdir ${{ env.REPORTS_DIR }}
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.PHP_PROJECT_EXT }}
tools: 'composer:v2'
coverage: pcov
- name: Get composer cache directory
id: composer-cache
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ steps.composer-cache.outputs.dir }}
# see https://github.com/actions/cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.job }}-${{ runner.os }}-php${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('composer.*', 'tools/phpunit/composer.*') }}
restore-keys: |
composer-${{ github.job }}-${{ runner.os }}-php${{ matrix.php }}-${{ matrix.dependencies }}-
composer-${{ github.job }}-${{ runner.os }}-php${{ matrix.php }}-
composer-${{ github.job }}-${{ runner.os }}-
- name: Install PHPUnit
run: composer install --prefer-dist --no-interaction --no-progress
working-directory: tools/phpunit
- name: Install (${{ matrix.dependencies }})
shell: bash
run: |
# removing security-foo here is fine, as no code is run, only parsed
composer remove --dev 'roave/security-advisories' \
--no-update --no-install
composer config platform.php ${{ matrix.php }}
composer update \
--no-interaction --no-progress \
--prefer-dist \
${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }}
- name: Run PHPUnit tests
run: >
php
-d zend.assertions=1
-d assert.exception=1
-d display_errors=On
-d error_reporting=-1
-d log_errors_max_len=0
-d memory_limit=-1
tools/phpunit/vendor/phpunit/phpunit/phpunit
--no-progress
--log-junit='${{ env.REPORTS_DIR }}/tests/${{ matrix.os }}_php${{ matrix.php }}_${{ matrix.dependencies }}.junit.xml'
--coverage-clover='${{ env.REPORTS_DIR }}/coverage/${{ matrix.os }}_php${{ matrix.php }}_${{ matrix.dependencies }}.clover.xml'
- name: Artifact reports
if: ${{ ! cancelled() }}
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: '${{ env.TESTS_REPORTS_ARTIFACT }}_${{ matrix.os }}_php${{ matrix.php }}_${{ matrix.dependencies }}'
path: ${{ env.REPORTS_DIR }}
if-no-files-found: error
report-coverage:
name: Publish test coverage
needs: [ "phpunit" ]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: fetch test artifacts
# see https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
with:
pattern: '${{ env.TESTS_REPORTS_ARTIFACT }}_*'
merge-multiple: true
path: ${{ env.REPORTS_DIR }}
- name: Run codacy-coverage-reporter
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
## see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-secrets
if: ${{ env.CODACY_PROJECT_TOKEN != '' }}
# see https://github.com/codacy/codacy-coverage-reporter-action
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
coverage-reports: ${{ env.REPORTS_DIR }}/coverage/*.clover.xml
code-checker:
name: Code Analysis p${{ matrix.php }} c${{ matrix.composer }} ${{ matrix.dependencies }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
php:
- "8.3" # highest supported
- "8.1" # lowest supported
composer:
- "v2" # latest 2.x
- "2.6"
- "2.5"
- "2.4"
- "2.3" # lowest supported
dependencies: [ "highest" ]
include:
- # lowest supported
php: "8.1"
composer: "2.3"
dependencies: "lowest"
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION_LATEST }}
extensions: ${{ env.PHP_PROJECT_EXT }}
tools: composer:${{ matrix.composer }}
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ steps.composer-cache.outputs.dir }}
# see https://github.com/actions/cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.job }}-${{ runner.os }}-php${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('composer.*', 'tools/psalm/composer.*') }}
restore-keys: |
composer-${{ github.job }}-${{ runner.os }}-php${{ matrix.php }}-${{ matrix.dependencies }}-
composer-${{ github.job }}-${{ runner.os }}-php${{ matrix.php }}-
composer-${{ github.job }}-${{ runner.os }}-
- name: Install psalm
run: composer install --no-interaction --no-progress --prefer-dist
working-directory: tools/psalm
- name: Install (composer:~${{ matrix.composer }}.0 ${{ matrix.dependencies }})
run: |
# removing security-foo here is fine, as no code is run, only parsed
composer remove --dev 'roave/security-advisories' \
--no-update --no-install
composer config platform.php ${{ matrix.php }}
composer update \
--no-interaction --no-progress \
--prefer-dist \
${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }} \
--with='composer/composer:~${{ matrix.composer }}.0'
- name: Run Psalm tests
run: >
php tools/psalm/vendor/vimeo/psalm/psalm
--no-diff
--no-cache
--long-progress
--output-format=github
--report='${{ env.REPORTS_DIR }}/psalm/p${{ matrix.php }}_c${{ matrix.composer }}_${{ matrix.dependencies }}.junit.xml'
--stats
- name: Artifact reports
if: ${{ ! cancelled() }}
# see https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: '${{ env.TYPES_REPORTS_ARTIFACT }}_php${{ matrix.php }}_composer${{ matrix.composer }}_${{ matrix.dependencies }}'
path: ${{ env.REPORTS_DIR }}
if-no-files-found: error
composer-unused:
name: ComposerUnused
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION_LATEST }}
extensions: ${{ env.PHP_PROJECT_EXT }}
tools: 'composer:v2'
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ steps.composer-cache.outputs.dir }}
# see https://github.com/actions/cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.job }}-${{ runner.os }}-${{ hashFiles('composer.*', 'tools/composer-unused/composer.*') }}
restore-keys: |
composer-${{ github.job }}-${{ runner.os }}-
- name: Install composer-unused
run: composer install --prefer-dist --no-interaction --no-progress
working-directory: tools/composer-unused
- name: Install dependencies
run: composer install --no-dev --prefer-dist --no-interaction --no-progress
- name: Run composer-unused tests
run: >
php tools/composer-unused/vendor/icanhazstring/composer-unused/bin/composer-unused
--no-progress
--no-interaction
--excludeDir=tools
composer-require-checker:
name: ComposerRequireChecker
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION_LATEST }}
extensions: ${{ env.PHP_PROJECT_EXT }}
tools: 'composer:v2'
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ steps.composer-cache.outputs.dir }}
# see https://github.com/actions/cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.job }}-${{ runner.os }}-${{ hashFiles('composer.*', 'tools/composer-require-checker/composer.*') }}
restore-keys: |
composer-${{ github.job }}-${{ runner.os }}-
- name: Install composer-require-checker
run: composer install --prefer-dist --no-interaction --no-progress
working-directory: tools/composer-require-checker
- name: Install dependencies
run: composer install --no-dev --prefer-dist --no-interaction --no-progress
- name: Run composer-require-checker tests
run: >
php tools/composer-require-checker/vendor/maglnet/composer-require-checker/bin/composer-require-checker
--no-interaction
coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION_LATEST }}
extensions: ${{ env.PHP_PROJECT_EXT }}
tools: 'composer:v2'
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ steps.composer-cache.outputs.dir }}
# see https://github.com/actions/cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.job }}-${{ runner.os }}-${{ hashFiles('composer.*', 'tools/php-cs-fixer/composer.*') }}
restore-keys: |
composer-${{ github.job }}-${{ runner.os }}-
- name: Install PHP-CS-Fixer
run: composer install --prefer-dist --no-interaction --no-progress
working-directory: tools/php-cs-fixer
- name: Run PHP-CS-Fixer tests
run: >
php tools/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer
fix
--dry-run
--diff
--using-cache=no
--show-progress=dots
--no-interaction
composer-normalize:
name: Composer normalize
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Setup PHP
# see https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION_LATEST }}
tools: 'composer:v2'
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
if: ${{ steps.composer-cache.outputs.dir }}
# see https://github.com/actions/cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.job }}-${{ runner.os }}-${{ hashFiles('composer.*', 'tools/composer-normalize/composer.*') }}
restore-keys: |
composer-${{ github.job }}-${{ runner.os }}-
- name: Install composer-normalize
run: composer install --prefer-dist --no-interaction --no-progress
working-directory: tools/composer-normalize
- name: Run composer-normalize tests
run: >
composer -d tools/composer-normalize
normalize
--dry-run
--diff
--no-check-lock
--no-update-lock
--no-interaction
$PWD/composer.json