Code review #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ main, dev ] | |
| pull_request: | |
| branches: [ main, dev ] | |
| permissions: | |
| contents: read | |
| jobs: | |
| phpcs: | |
| name: PHPCS (WordPress Coding Standards) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| tools: composer | |
| coverage: none | |
| - name: Get Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: ${{ runner.os }}-composer- | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run PHPCS | |
| run: composer run-script phpcs | |
| phpstan: | |
| name: PHPStan (Static Analysis) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| tools: composer | |
| coverage: none | |
| - name: Get Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: ${{ runner.os }}-composer- | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run PHPStan | |
| run: composer run-script analyse | |
| phpunit: | |
| name: PHPUnit (PHP ${{ matrix.php }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] | |
| services: | |
| mysql: | |
| image: mysql:5.7 | |
| env: | |
| MYSQL_ROOT_PASSWORD: root | |
| MYSQL_DATABASE: wordpress_test | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=3 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: mysqli, zip | |
| coverage: ${{ matrix.php == '8.3' && 'xdebug' || 'none' }} | |
| tools: composer | |
| - name: Install Subversion | |
| run: sudo apt-get update && sudo apt-get install -y subversion | |
| - name: Get Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Install WordPress test suite | |
| run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest true | |
| - name: Run unit tests (Brain\Monkey - fast) | |
| if: matrix.php != '8.3' | |
| run: composer run-script test:unit | |
| - name: Run integration tests (WP Test Suite - real WP) | |
| if: matrix.php != '8.3' | |
| run: composer run-script test:integration | |
| - name: Run unit tests with coverage (PHP 8.3) | |
| if: matrix.php == '8.3' | |
| run: composer run-script test:coverage:unit | |
| - name: Run integration tests with coverage (PHP 8.3) | |
| if: matrix.php == '8.3' | |
| run: composer run-script test:coverage:integration | |
| - name: Upload unit coverage to Codecov | |
| if: matrix.php == '8.3' | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage/clover-unit.xml | |
| flags: unit | |
| name: unit-php-8.3 | |
| fail_ci_if_error: false | |
| - name: Upload integration coverage to Codecov | |
| if: matrix.php == '8.3' | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage/clover-integration.xml | |
| flags: integration | |
| name: integration-php-8.3 | |
| fail_ci_if_error: false | |
| e2e: | |
| name: E2E Tests (Playwright) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| tools: composer | |
| coverage: none | |
| - name: Install Composer dependencies (autoloader for plugin) | |
| run: composer install --no-dev --prefer-dist --no-progress | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install npm dependencies | |
| run: npm ci | |
| - name: Install Playwright Chromium | |
| run: npx playwright install chromium --with-deps | |
| - name: Start wp-env | |
| run: npm run env:start | |
| - name: Wait for WordPress to be ready | |
| run: | | |
| for i in $(seq 1 30); do | |
| if curl -sf http://localhost:8888/wp-login.php > /dev/null 2>&1; then | |
| echo "WordPress is ready (attempt $i)" | |
| exit 0 | |
| fi | |
| echo "Waiting for WordPress... (attempt $i)" | |
| sleep 2 | |
| done | |
| echo "WordPress failed to start within 60 seconds" | |
| exit 1 | |
| - name: Create E2E test users | |
| run: bash bin/e2e-setup.sh | |
| - name: Run E2E tests | |
| run: npm run test:e2e | |
| - name: Upload Playwright report | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-report | |
| path: playwright-report/ | |
| retention-days: 7 | |
| - name: Upload test results | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: test-results/ | |
| retention-days: 7 | |
| - name: Stop wp-env | |
| if: always() | |
| run: npm run env:stop |