Skip to content

WIP: Reader UI

WIP: Reader UI #13317

Workflow file for this run

name: Unit Testing
on:
push:
branches:
- trunk
paths:
- '**/*.php'
- 'composer.json'
- 'composer.lock'
- 'phpunit.xml.dist'
- 'phpcs.xml'
- '.github/workflows/phpunit.yml'
- '!build/**/*.asset.php'
pull_request:
paths:
- '**/*.php'
- 'composer.json'
- 'composer.lock'
- 'phpunit.xml.dist'
- 'phpcs.xml'
- '.github/workflows/phpunit.yml'
- '!build/**/*.asset.php'
jobs:
phpunit:
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:10.4
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
include:
- wp-version: latest
- wp-version: '6.5'
php-versions: '7.2'
- wp-version: trunk
php-versions: '8.4'
steps:
- name: Install svn
run: |
sudo apt-get update
sudo apt-get install subversion
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
tools: composer, phpunit-polyfills
extensions: mysql
- name: Install Composer dependencies for PHP
uses: ramsey/composer-install@v3
- name: Setup Test Environment
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wp-version }}
- name: Unit Testing
run: ./vendor/bin/phpunit
env:
PHP_VERSION: ${{ matrix.php-versions }}
WP_ENVIRONMENT_TYPE: production
coverage:
runs-on: ubuntu-latest
services:
mysql:
image: mariadb:10.4
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
steps:
- name: Install svn
run: |
sudo apt-get update
sudo apt-get install subversion
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: xdebug
tools: composer, phpunit-polyfills, cs2pr
extensions: mysql
- name: Install Composer dependencies for PHP
uses: ramsey/composer-install@v3
- name: Setup Test Environment
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest
- name: Unit Testing with Coverage
run: ./vendor/bin/phpunit --coverage-text --coverage-clover coverage.xml --log-junit junit.xml 2>&1 | tee coverage-output.log
env:
WP_ENVIRONMENT_TYPE: production
- name: Generate Checkstyle Report for Coverage Warnings
if: always()
run: |
echo "Generating checkstyle report for coverage warnings..."
# Create checkstyle XML header
cat > coverage-warnings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="4.3">
EOF
# Check for PHPUnit warnings and process them
if grep -q "WARNINGS!" coverage-output.log; then
echo "Processing coverage warnings for checkstyle report..."
# Show warnings section for debugging
echo "--- Warnings Found ---"
sed -n '/There w.*warning/,/WARNINGS!/p' coverage-output.log | head -10
echo "--- End Warnings ---"
# Extract warnings to temporary file to avoid subshell issues
sed -n '/There w.*warning/,/WARNINGS!/p' coverage-output.log > temp-warnings.txt
# Track processed file:line combinations to avoid duplicates
declare -A processed_annotations
# Process each line
while IFS= read -r line; do
echo "Processing line: $line"
# Look for @covers warnings
if [[ "$line" =~ \"@covers[^\"]*\"\ is\ invalid ]]; then
echo "Found @covers warning line: $line"
# Extract the @covers target - everything between quotes
if [[ "$line" =~ \"@covers\ ([^\"]+)\" ]]; then
COVERS_TARGET="${BASH_REMATCH[1]}"
echo "Processing @covers warning for: $COVERS_TARGET"
# Find test file and line number
echo "Searching for @covers annotation with target: $COVERS_TARGET"
# Extract just the method name from the full class::method
METHOD_NAME=$(echo "$COVERS_TARGET" | sed 's/.*:://')
echo "Extracted method name: $METHOD_NAME"
if TEST_FILE=$(find tests/phpunit/tests/ -name "*.php" -type f -exec grep -l "@covers.*$METHOD_NAME" {} \; | head -1); then
echo "Found test file: $TEST_FILE"
if LINE_NUM=$(grep -n "@covers.*$METHOD_NAME" "$TEST_FILE" | head -1 | cut -d: -f1); then
echo "Found line number: $LINE_NUM"
# Create unique key for this file:line combination
FILE_LINE_KEY="$TEST_FILE:$LINE_NUM"
# Only process if we haven't seen this file:line before
if [[ -z "${processed_annotations[$FILE_LINE_KEY]}" ]]; then
echo "Adding annotation for $FILE_LINE_KEY"
processed_annotations[$FILE_LINE_KEY]=1
# Escape XML characters and add checkstyle entry
MESSAGE=$(echo "Invalid @covers annotation: $COVERS_TARGET" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')
cat >> coverage-warnings.xml << EOF
<file name="$TEST_FILE">
<error line="$LINE_NUM" column="1" severity="warning" message="$MESSAGE" source="phpunit.coverage"/>
</file>
EOF
else
echo "Skipping duplicate annotation for $FILE_LINE_KEY"
fi
fi
fi
fi
# Look for deprecation warnings
elif [[ "$line" =~ (deprecated|will\ no\ longer\ be\ possible) ]]; then
echo "::warning::PHPUnit deprecation warning: ${line}"
fi
done < temp-warnings.txt
rm -f temp-warnings.txt
WARNINGS_FOUND=true
else
echo "No coverage warnings found"
WARNINGS_FOUND=false
fi
# Close the checkstyle XML
echo '</checkstyle>' >> coverage-warnings.xml
# Debug: show the generated checkstyle content
echo "Generated checkstyle report:"
cat coverage-warnings.xml
# Exit with error if warnings were found
if [ "$WARNINGS_FOUND" = true ]; then
echo "::error::Coverage analysis produced warnings"
exit 1
fi
- name: Annotate Coverage Warnings in PR
if: always() && github.event_name == 'pull_request'
run: |
# Check if we have any errors in the checkstyle report
if grep -q '<error' coverage-warnings.xml; then
echo "Found coverage warnings to annotate"
echo "Converting checkstyle report to PR annotations..."
cs2pr --graceful-warnings coverage-warnings.xml
else
echo "No coverage warnings found in checkstyle report"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}