Skip to content

Commit

Permalink
Workflow for src tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoslavGeorgiev committed Oct 23, 2023
1 parent 62dbd78 commit adb8aea
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/src-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Code coverage (`src` directory)

on:
pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
woocommerce-coverage:
name: Src Coverage
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 10
matrix:
woocommerce: [ 'latest' ]
wordpress: [ 'latest' ]
php: [ '7.4' ]
env:
WP_VERSION: ${{ matrix.wordpress }}
WC_VERSION: ${{ matrix.woocommerce }}
steps:
# clone the repository
- uses: actions/checkout@v3
# enable dependencies caching
- uses: actions/cache@v3
with:
path: ~/.cache/composer/
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
# setup PHP, but without debug extensions for reasonable performance
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
coverage: xdebug2
# run CI checks
- run: bash bin/run-ci-tests-check-src-coverage.bash
7 changes: 4 additions & 3 deletions bin/phpunit.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ fi

CURRENT_PHP_MAJOR_VERSION=$(php -r 'echo PHP_MAJOR_VERSION;')
CURRENT_PHP_MINOR_VERSION=$(php -r 'echo PHP_MINOR_VERSION;')
CONFIG_FILE=${1-phpunit.xml.dist}

# The PHPUnit version inside composer.json is not compatible with PHP versions bellow 7.3
# Update this constant if you wish to bump supported PHP major version
SUPPORTED_PHP_MAJOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON=7
SUPPORTED_PHP_MINOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON=3

if [ $CURRENT_PHP_MAJOR_VERSION -gt $SUPPORTED_PHP_MAJOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON ]; then
./vendor/bin/phpunit -c phpunit.xml.dist "$@";
./vendor/bin/phpunit -c $CONFIG_FILE "$@";
else
if [ $CURRENT_PHP_MINOR_VERSION -ge $SUPPORTED_PHP_MINOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON ]; then
./vendor/bin/phpunit -c phpunit.xml.dist "$@";
./vendor/bin/phpunit -c $CONFIG_FILE "$@";
else
chmod +x ./bin/phpunit6
./bin/phpunit6 -c phpunit.xml.dist "$@";
./bin/phpunit6 -c $CONFIG_FILE "$@";
fi
fi

16 changes: 16 additions & 0 deletions bin/run-ci-tests-check-src-coverage.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# set strict mode for bash
set -euo pipefail
IFS=$'\n\t'

# set environment variables
WCPAY_DIR="$GITHUB_WORKSPACE"

composer self-update && composer install --no-progress
sudo systemctl start mysql.service
bash bin/install-wp-tests.sh woocommerce_test root root localhost $WP_VERSION $WC_VERSION false
echo 'Running the tests...'
bash bin/phpunit.sh phpunit-src.xml.dist --coverage-clover /tmp/clover.xml
vendor/bin/coverage-check /tmp/clover.xml 100

0 comments on commit adb8aea

Please sign in to comment.