|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [master, development, latest] |
| 6 | + push: |
| 7 | + branches: [development, latest] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ci-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + # ============================================================ |
| 15 | + # JavaScript: Lint + Type Check + Test + Build |
| 16 | + # ============================================================ |
| 17 | + js: |
| 18 | + name: JS (Lint, Test, Build) |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: 20 |
| 26 | + cache: npm |
| 27 | + |
| 28 | + - run: npm ci |
| 29 | + |
| 30 | + - name: ESLint |
| 31 | + run: npm run lint |
| 32 | + |
| 33 | + - name: Vitest |
| 34 | + run: npm test -- --reporter=verbose |
| 35 | + |
| 36 | + - name: Build |
| 37 | + run: npm run build |
| 38 | + |
| 39 | + # ============================================================ |
| 40 | + # PHP: Lint + Unit Tests |
| 41 | + # ============================================================ |
| 42 | + php: |
| 43 | + name: PHP ${{ matrix.php }} (Unit Tests) |
| 44 | + runs-on: ubuntu-latest |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + php: ['8.0', '8.1', '8.2'] |
| 49 | + services: |
| 50 | + mysql: |
| 51 | + image: mysql:8.0 |
| 52 | + env: |
| 53 | + MYSQL_ROOT_PASSWORD: root |
| 54 | + MYSQL_DATABASE: embedpress_tests |
| 55 | + ports: |
| 56 | + - 3306:3306 |
| 57 | + options: >- |
| 58 | + --health-cmd="mysqladmin ping -h localhost" |
| 59 | + --health-interval=10s |
| 60 | + --health-timeout=5s |
| 61 | + --health-retries=3 |
| 62 | +
|
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - uses: shivammathur/setup-php@v2 |
| 67 | + with: |
| 68 | + php-version: ${{ matrix.php }} |
| 69 | + extensions: mysqli, mbstring, intl |
| 70 | + coverage: xdebug |
| 71 | + tools: phpunit:9, composer |
| 72 | + |
| 73 | + - name: Install Composer dependencies |
| 74 | + run: composer install --no-interaction --prefer-dist |
| 75 | + |
| 76 | + - name: Run PHPUnit (unit suite) |
| 77 | + run: phpunit --testsuite unit --colors=always --coverage-clover build/logs/clover.xml |
| 78 | + env: |
| 79 | + EP_UNIT_TESTS: 1 |
| 80 | + |
| 81 | + # ============================================================ |
| 82 | + # PHP Code Quality |
| 83 | + # ============================================================ |
| 84 | + phpcs: |
| 85 | + name: PHP CodeSniffer |
| 86 | + runs-on: ubuntu-latest |
| 87 | + steps: |
| 88 | + - uses: actions/checkout@v4 |
| 89 | + |
| 90 | + - uses: shivammathur/setup-php@v2 |
| 91 | + with: |
| 92 | + php-version: '8.2' |
| 93 | + tools: cs2pr, phpcs, composer |
| 94 | + |
| 95 | + - name: Install WPCS |
| 96 | + run: | |
| 97 | + composer global require wp-coding-standards/wpcs phpcompatibility/phpcompatibility-wp dealerdirect/phpcodesniffer-composer-installer --no-interaction |
| 98 | +
|
| 99 | + - name: Run PHPCS |
| 100 | + run: phpcs --standard=phpcs.xml --report=checkstyle | cs2pr |
| 101 | + continue-on-error: true |
| 102 | + |
| 103 | + # ============================================================ |
| 104 | + # E2E: Playwright Tests (WordPress + Chromium) |
| 105 | + # ============================================================ |
| 106 | + e2e: |
| 107 | + name: E2E Tests |
| 108 | + runs-on: ubuntu-latest |
| 109 | + services: |
| 110 | + mysql: |
| 111 | + image: mysql:8.0 |
| 112 | + env: |
| 113 | + MYSQL_ROOT_PASSWORD: root |
| 114 | + MYSQL_DATABASE: embedpress |
| 115 | + MYSQL_USER: wordpress |
| 116 | + MYSQL_PASSWORD: wordpress |
| 117 | + ports: |
| 118 | + - 3306:3306 |
| 119 | + options: >- |
| 120 | + --health-cmd="mysqladmin ping -h localhost" |
| 121 | + --health-interval=10s |
| 122 | + --health-timeout=5s |
| 123 | + --health-retries=3 |
| 124 | +
|
| 125 | + steps: |
| 126 | + - uses: actions/checkout@v4 |
| 127 | + |
| 128 | + - uses: actions/setup-node@v4 |
| 129 | + with: |
| 130 | + node-version: 20 |
| 131 | + cache: npm |
| 132 | + |
| 133 | + - uses: shivammathur/setup-php@v2 |
| 134 | + with: |
| 135 | + php-version: '8.2' |
| 136 | + extensions: mysqli, mbstring, gd, intl |
| 137 | + tools: wp-cli |
| 138 | + |
| 139 | + - name: Install Node dependencies |
| 140 | + run: npm ci |
| 141 | + |
| 142 | + - name: Build assets |
| 143 | + run: npm run build |
| 144 | + |
| 145 | + - name: Install Playwright browsers |
| 146 | + run: npx playwright install chromium |
| 147 | + |
| 148 | + - name: Setup WordPress |
| 149 | + run: | |
| 150 | + # Download WordPress |
| 151 | + wp core download --path=/tmp/wordpress --allow-root |
| 152 | +
|
| 153 | + # Configure |
| 154 | + wp config create --path=/tmp/wordpress \ |
| 155 | + --dbname=embedpress --dbuser=wordpress --dbpass=wordpress \ |
| 156 | + --dbhost=127.0.0.1 --allow-root |
| 157 | +
|
| 158 | + wp config set WP_DEBUG true --raw --path=/tmp/wordpress --allow-root |
| 159 | +
|
| 160 | + # Install |
| 161 | + wp core install --path=/tmp/wordpress \ |
| 162 | + --url=http://localhost:8080 \ |
| 163 | + --title="EmbedPress E2E" \ |
| 164 | + --admin_user=admin --admin_password=admin \ |
| 165 | + --admin_email=test@test.com --skip-email --allow-root |
| 166 | +
|
| 167 | + # Link plugin |
| 168 | + ln -s ${{ github.workspace }} /tmp/wordpress/wp-content/plugins/embedpress |
| 169 | +
|
| 170 | + # Activate |
| 171 | + wp plugin activate embedpress --path=/tmp/wordpress --allow-root |
| 172 | +
|
| 173 | + # Set permalinks |
| 174 | + wp rewrite structure '/%postname%/' --hard --path=/tmp/wordpress --allow-root |
| 175 | +
|
| 176 | + # Start PHP built-in server |
| 177 | + php -S localhost:8080 -t /tmp/wordpress & |
| 178 | +
|
| 179 | + # Wait for server |
| 180 | + sleep 3 |
| 181 | + curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || true |
| 182 | +
|
| 183 | + - name: Run Playwright E2E tests |
| 184 | + run: npx playwright test |
| 185 | + env: |
| 186 | + WP_BASE_URL: http://localhost:8080 |
| 187 | + |
| 188 | + - uses: actions/upload-artifact@v4 |
| 189 | + if: failure() |
| 190 | + with: |
| 191 | + name: playwright-report |
| 192 | + path: playwright-report/ |
| 193 | + retention-days: 7 |
0 commit comments