Skip to content

CI/QA: Switch to GitHub Actions and start using Coveralls #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions .circleci/config.yml

This file was deleted.

13 changes: 6 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
# https://blog.madewithlove.be/post/gitattributes/
#
/.gitattributes export-ignore
/.gitignore export-ignore
/composer.circleci.json export-ignore
/phpcs.xml.dist export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/.circleci/ export-ignore
/Tests/ export-ignore
/phpunit.xml.dist export-ignore
/.github export-ignore
/Tests/ export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/csqa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CS and QA

on:
# Run on all pushes and on all pull requests.
# Prevent the build from running when there are only irrelevant changes.
push:
paths-ignore:
- '**.md'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
checkcs:
name: 'PHP: 7.4 | Basic CS and QA checks'
runs-on: ubuntu-latest

env:
XMLLINT_INDENT: ' '

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: cs2pr

# Using PHPCS `master` as an early detection system for bugs upstream.
- name: 'Composer: adjust dependencies'
run: composer require --no-update squizlabs/php_codesniffer:"dev-master"

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"

- name: Install xmllint
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y libxml2-utils

# Show XML violations inline in the file diff.
# @link https://github.com/marketplace/actions/xmllint-problem-matcher
- uses: korelstar/xmllint-problem-matcher@v1

# Validate the XML file.
# @link http://xmlsoft.org/xmllint.html
- name: Validate ruleset against schema
run: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd VariableAnalysis/ruleset.xml

# Check the code-style consistency of the XML file.
- name: Check XML code style
run: diff -B ./VariableAnalysis/ruleset.xml <(xmllint --format "./VariableAnalysis/ruleset.xml")

# Check the code-style consistency of the PHP files.
- name: Check PHP code style
continue-on-error: true
run: composer lint -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
run: cs2pr ./phpcs-report.xml

phpstan:
name: "PHP: 7.4 | PHPStan"
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none

# Install dependencies and handle caching in one go.
# Dependencies need to be installed to make sure the PHPUnit classes are recognized.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"

- name: Run PHPStan
run: composer phpstan
209 changes: 209 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
name: Test

on:
# Run on all pushes and pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
#### TEST STAGE ####
test:
runs-on: ubuntu-latest

strategy:
matrix:
# The GHA matrix works different from Travis.
# You can define jobs here and then augment them with extra variables in `include`,
# as well as add extra jobs in `include`.
# @link https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
#
# IMPORTANT: test runs shouldn't fail because of PHPCS being incompatible with a PHP version.
# - PHPCS will run without errors on PHP 5.4 - 7.4 on all supported PHPCS versions.
# - PHP 8.0 needs PHPCS 3.5.7+ to run without errors.
# - PHP 8.1 needs PHPCS 3.6.1+ to run without errors.
#
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3']
phpcs_version: ['3.5.6', 'dev-master']

include:
# Make the matrix complete without duplicating builds run in code coverage.
- php: '8.1'
phpcs_version: '3.6.1'

- php: '8.0'
phpcs_version: 'dev-master'
- php: '8.0'
phpcs_version: '3.5.7'

- php: '7.4'
phpcs_version: 'dev-master'

# Experimental builds.
- php: '8.2' # Nightly.
phpcs_version: 'dev-master'

name: "Test: PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}"

continue-on-error: ${{ matrix.php == '8.2' }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup ini config
id: set_ini
run: |
# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then
echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On, zend.assertions=1'
else
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, zend.assertions=1'
fi

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none

- name: 'Composer: adjust dependencies'
run: |
# Remove dev dependencies which are not compatible with all supported PHP versions.
composer remove --dev --no-update sirbrillig/phpcs-import-detection phpstan/phpstan
# Set the PHPCS version for this test run.
composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}"

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies - normal
if: ${{ matrix.php != '8.2' }}
uses: "ramsey/composer-install@v2"

# For the PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow it yet.
- name: Install Composer dependencies - with ignore platform
if: ${{ matrix.php == '8.2' }}
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-req=php

- name: Run the unit tests
run: composer test

#### CODE COVERAGE STAGE ####
# N.B.: Coverage is only checked on the lowest and highest stable PHP versions
# and low/high for PHPCS.
coverage:
# No use running the coverage builds if there are failing test builds.
needs: test
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php: '8.1'
phpcs_version: 'dev-master'
- php: '7.4'
phpcs_version: '3.5.6'

- php: '5.4'
phpcs_version: 'dev-master'
- php: '5.4'
phpcs_version: '3.5.6'

name: "Coverage: PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup ini config
id: set_ini
run: |
# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then
echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On, zend.assertions=1'
else
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, zend.assertions=1'
fi

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: xdebug

- name: 'Composer: adjust dependencies'
run: |
# Remove dev dependencies which are not compatible with all supported PHP versions.
composer remove --dev --no-update sirbrillig/phpcs-import-detection phpstan/phpstan
composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}"

- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"

- name: Grab PHPUnit version
id: phpunit_version
run: echo ::set-output name=VERSION::$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')

- name: "DEBUG: Show grabbed version"
run: echo ${{ steps.phpunit_version.outputs.VERSION }}

# PHPUnit 9.3 started using PHP-Parser for code coverage which can cause interference.
# As of PHPUnit 9.3.4, a cache warming option is available.
# Using that option prevents issues with PHP-Parser backfilling PHP tokens when PHPCS does not (yet),
# which would otherwise cause tests to fail on tokens being available when they shouldn't be.
- name: "Warm the PHPUnit cache (PHPUnit 9.3+)"
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache --warm-coverage-cache

- name: "Run the unit tests with code coverage (PHPUnit < 9.3)"
if: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }}
run: composer coverage

- name: "Run the unit tests with code coverage (PHPUnit 9.3+)"
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: composer coverage -- --coverage-cache ./build/phpunit-cache

# PHP Coveralls v2 has a PHP 5.5 minimum and is not yet fully compatible with PHP 8.0+, so switch the PHP version.
- name: Switch to PHP 7.4
if: ${{ success() && matrix.php != '7.4' }}
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

- name: Install Coveralls
if: ${{ success() }}
run: composer require php-coveralls/php-coveralls:"^2.5.2" --no-interaction

- name: Upload coverage results to Coveralls
if: ${{ success() }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: vendor/bin/php-coveralls -v -x build/logs/clover.xml

coveralls-finish:
needs: coverage
runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/composer.lock
/vendor/
/build/
phpunit.xml
.phpunit.result.cache
.phpcs.xml
Expand Down
Loading