Skip to content

Improve compatibility with other operating systems #1386

Improve compatibility with other operating systems

Improve compatibility with other operating systems #1386

Workflow file for this run

name: Testing
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- master
schedule:
- cron: '17 1 * * *' # Run every day on a seemly random time.
# 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:
get-matrix:
name: Get base test matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.base-matrix.outputs.matrix }}
steps:
- name: Set matrix
id: base-matrix
run: |
MATRIX=$(cat << EOF
{
"include": [
{
"php": "8.4",
"wp": "latest",
"mysql": "mysql-8.0"
},
{
"php": "8.4",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.4",
"wp": "latest",
"mysql": "mysql-8.0",
"os": "macos-15"
},
{
"php": "8.4",
"wp": "latest",
"dbtype": "sqlite",
"os": "macos-15"
},
{
"php": "8.4",
"wp": "latest",
"mysql": "mysql-8.0",
"os": "windows-2025"
},
{
"php": "8.4",
"wp": "latest",
"dbtype": "sqlite",
"os": "windows-2025"
}
]
}
EOF
)
echo matrix=$MATRIX >> $GITHUB_OUTPUT
prepare-unit:
name: Prepare matrix for unit tests
needs: get-matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v5
- name: Check existence of composer.json & phpunit.xml.dist files
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "composer.json, phpunit.xml.dist"
- name: Set matrix
id: set-matrix
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c \
--argjson with_coverage_flag "true" \
--arg minimum_php "7.2" \
--arg minimum_wp "4.9" \
'
.include |= (
map(
# First, select only the versions that meet all minimum requirements
select(
(.php >= $minimum_php) and
(.wp == "latest" or .wp >= $minimum_wp)
) |
# Next, update the coverage flag on the remaining items
if $with_coverage_flag == false and .coverage == true then
.coverage = false
else
.
end
) |
# Finally, get the unique entries
unique_by(.php)
)
' <<< "$BASE_MATRIX")" >> $GITHUB_OUTPUT
else
echo "matrix=" >> $GITHUB_OUTPUT
fi
env:
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}
unit: #-----------------------------------------------------------------------
needs: prepare-unit
if: ${{ needs.prepare-unit.outputs.matrix != '' }}
name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }} (${{ matrix.os || 'ubuntu-22.04' }})
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
continue-on-error: ${{ matrix.php == 'nightly' }}
steps:
- name: Check out source code
uses: actions/checkout@v5
- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer,cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Composer dependencies & cache dependencies
uses: "ramsey/composer-install@v3"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Grab PHPUnit version
id: phpunit_version
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
# PHPUnit 10+ may fail a test run when the "old" configuration format is used.
# Luckily, there is a build-in migration tool since PHPUnit 9.3.
- name: Migrate PHPUnit configuration for PHPUnit 10+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '1' ) }}
continue-on-error: true
run: composer phpunit -- --migrate-configuration
- name: Setup problem matcher to provide annotations for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run PHPUnit
run: |
if [[ ${{ matrix.coverage == true }} == true ]]; then
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
else
composer phpunit
fi
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/[email protected]
with:
directory: build/logs
flags: unit
token: ${{ secrets.CODECOV_TOKEN }}
prepare-functional: #---------------------------------------------------------
name: Prepare matrix for functional tests
needs: get-matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out source code
uses: actions/checkout@v5
- name: Check existence of composer.json & behat.yml files
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "composer.json, behat.yml"
- name: Set matrix
id: set-matrix
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c \
--argjson with_coverage_flag "true" \
--arg minimum_php "7.2" \
--arg minimum_wp "4.9" \
'
# First, select only the versions that meet all minimum requirements
.include |= (
map(
select(
.php >= $minimum_php
) |
# Next, update the coverage flag on the remaining items
if $with_coverage_flag == false and .coverage == true then
.coverage = false
else
.
end
)
) |
# Reassign WP4.9 to minimum_wp
.include |= (
map(
select(
.wp == "4.9"
).wp |= $minimum_wp
)
)
' <<< "$BASE_MATRIX" )" >> $GITHUB_OUTPUT
else
echo "matrix=" >> $GITHUB_OUTPUT
fi
env:
BASE_MATRIX: ${{ needs.get-matrix.outputs.matrix }}
FILE_EXISTS: ${{ steps.check_files.outputs.files_exists == 'true' }}
functional: #-----------------------------------------------------------------
needs: prepare-functional
if: ${{ needs.prepare-functional.outputs.matrix != '' }}
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && matrix.mysql || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }} (${{ matrix.os || 'ubuntu-22.04' }})
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }}
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
continue-on-error: ${{ matrix.dbtype == 'sqlite' || matrix.dbtype == 'mariadb' || matrix.php == 'nightly' }}
steps:
- name: Check out source code
uses: actions/checkout@v5
- name: Install Ghostscript
run: |
sudo apt-get update
sudo apt-get install ghostscript -y
- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
extensions: gd, imagick, mysql, zip
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Change ImageMagick policy to allow pdf->png conversion.
run: |
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
- name: Install Composer dependencies & cache dependencies
uses: "ramsey/composer-install@v3"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Setup MySQL Server
id: setup-mysql
if: ${{ matrix.dbtype != 'sqlite' }}
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: ${{ matrix.mysql }}
auto-start: true
root-password: root
user: wp_cli_test
password: password1
my-cnf: |
default_authentication_plugin=mysql_native_password
- name: Configure DB environment
if: ${{ matrix.dbtype != 'sqlite' }}
run: |
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
echo "MYSQL_TCP_PORT=3306" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBHOST=127.0.0.1:3306" >> $GITHUB_ENV
- name: Prepare test database
if: ${{ matrix.dbtype != 'sqlite' }}
run: composer prepare-tests
- name: Check Behat environment
env:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
- name: Run Behat
env:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
run: |
ARGS=()
if [[ $WP_CLI_TEST_COVERAGE == 'true' ]]; then
# The flag was only added in v3.17.0
if composer behat -- --help 2>/dev/null | grep xdebug; then
ARGS+=("--xdebug")
fi
fi
if [[ $RUNNER_DEBUG == '1' ]]; then
ARGS+=("--format=pretty")
fi
composer behat -- "${ARGS[@]}" || composer behat-rerun -- "${ARGS[@]}"
- name: Retrieve list of coverage files
id: coverage_files
if: ${{ matrix.coverage }}
run: |
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
echo "files=$FILES" >> $GITHUB_OUTPUT
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/[email protected]
with:
# Because somehow providing `directory: build/logs` doesn't work for these files
files: ${{ steps.coverage_files.outputs.files }}
flags: feature
token: ${{ secrets.CODECOV_TOKEN }}