|
| 1 | +name: E2E Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +jobs: |
| 8 | + e2e: |
| 9 | + name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }} |
| 10 | + runs-on: ubuntu-24.04 |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + php: [ "8.2", "8.3", "8.4" ] |
| 15 | + wordpress: [ "6.7", "6.8" ] |
| 16 | + exclude: |
| 17 | + # Exclude older PHP versions with newer WordPress |
| 18 | + - php: "7.4" |
| 19 | + wordpress: "6.5.3" |
| 20 | + |
| 21 | + services: |
| 22 | + mysql: |
| 23 | + image: mysql:8.0 |
| 24 | + env: |
| 25 | + MYSQL_DATABASE: wordpress |
| 26 | + MYSQL_ROOT_PASSWORD: root |
| 27 | + ports: [ 3306:3306 ] |
| 28 | + options: >- |
| 29 | + --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot" |
| 30 | + --health-interval=10s |
| 31 | + --health-timeout=5s |
| 32 | + --health-retries=5 |
| 33 | +
|
| 34 | + env: |
| 35 | + WP_VERSION: ${{ matrix.wordpress }} |
| 36 | + WP_SITE_URL: http://localhost:8100 |
| 37 | + WP_DB_NAME: wordpress |
| 38 | + WP_DB_USER: root |
| 39 | + WP_DB_PASS: root |
| 40 | + WP_DB_HOST: 127.0.0.1 |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Check MySQL tables |
| 44 | + run: | |
| 45 | + echo "Listing databases:" |
| 46 | + mysql -h 127.0.0.1 -uroot -proot -e "SHOW DATABASES;" |
| 47 | +
|
| 48 | + echo "Checking if 'wordpress' database has any tables:" |
| 49 | + mysql -h 127.0.0.1 -uroot -proot -D wordpress -e "SHOW TABLES;" || echo "No tables found (yet)." |
| 50 | +
|
| 51 | + - name: Checkout plugin |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + persist-credentials: false |
| 55 | + |
| 56 | + - name: Set up PHP |
| 57 | + uses: shivammathur/setup-php@v2 |
| 58 | + with: |
| 59 | + # Note: Specified version is only for running tests, |
| 60 | + # as the WordPress PHP version is set inside the FrankenPHP Dockerfile. |
| 61 | + php-version: 8.4 |
| 62 | + extensions: mysqli, zip, gd |
| 63 | + coverage: none |
| 64 | + tools: wp-cli |
| 65 | + |
| 66 | + - name: Cache WordPress archive |
| 67 | + id: cache-wordpress |
| 68 | + uses: actions/cache@v3 |
| 69 | + with: |
| 70 | + path: /tmp/wp |
| 71 | + key: wp-${{ matrix.wordpress }} |
| 72 | + |
| 73 | + - name: Download WordPress |
| 74 | + if: steps.cache-wordpress.outputs.cache-hit != 'true' |
| 75 | + run: | |
| 76 | + mkdir -p /tmp/wp |
| 77 | + curl -O https://wordpress.org/wordpress-${WP_VERSION}.tar.gz |
| 78 | + tar -xzf wordpress-${WP_VERSION}.tar.gz --strip-components=1 -C /tmp/wp |
| 79 | + rm wordpress-${WP_VERSION}.tar.gz |
| 80 | +
|
| 81 | + - name: Set up Docker Buildx |
| 82 | + uses: docker/setup-buildx-action@v3 |
| 83 | + |
| 84 | + - name: Build FrankenPHP image (with cache) |
| 85 | + id: build |
| 86 | + uses: docker/build-push-action@v6 |
| 87 | + env: |
| 88 | + DOCKER_BUILD_SUMMARY: false |
| 89 | + with: |
| 90 | + context: . |
| 91 | + file: .github/docker/Dockerfile |
| 92 | + tags: frankenphp-${{ matrix.php }} |
| 93 | + load: true |
| 94 | + build-args: | |
| 95 | + PHP_VERSION=${{ matrix.php }} |
| 96 | + cache-from: type=gha |
| 97 | + cache-to: type=gha,mode=max |
| 98 | + |
| 99 | + - name: Start FrankenPHP server |
| 100 | + run: | |
| 101 | + docker run -d \ |
| 102 | + --name frankenphp \ |
| 103 | + --network host \ |
| 104 | + -p 8100:8100 \ |
| 105 | + -v /tmp/wp:/var/www/html \ |
| 106 | + -v $GITHUB_WORKSPACE:/var/www/html/wp-content/plugins/simpleanalytics \ |
| 107 | + -v $GITHUB_WORKSPACE/Caddyfile:/etc/frankenphp/Caddyfile \ |
| 108 | + frankenphp-${{ matrix.php }} |
| 109 | +
|
| 110 | + - name: Wait for FrankenPHP to be ready |
| 111 | + run: | |
| 112 | + for i in $(seq 1 30); do |
| 113 | + curl -s -o /dev/null http://localhost:8100 && echo "Server is up" && exit 0 |
| 114 | + echo "Waiting... ($i/30)" |
| 115 | + sleep 2 |
| 116 | + done |
| 117 | + echo "Server did not start in time" && exit 1 |
| 118 | +
|
| 119 | + - name: Verify MySQL is accepting connections |
| 120 | + run: | |
| 121 | + for i in $(seq 1 10); do |
| 122 | + mysql -h 127.0.0.1 -uroot -proot -e "SELECT 1" && echo "MySQL ready" && exit 0 |
| 123 | + echo "Waiting for MySQL... ($i/10)" |
| 124 | + sleep 2 |
| 125 | + done |
| 126 | + echo "MySQL not ready" && exit 1 |
| 127 | +
|
| 128 | + - name: Install WordPress |
| 129 | + run: | |
| 130 | + rm -f /tmp/wp/wp-config.php |
| 131 | + wp config create \ |
| 132 | + --dbname="$WP_DB_NAME" \ |
| 133 | + --dbuser="$WP_DB_USER" \ |
| 134 | + --dbpass="$WP_DB_PASS" \ |
| 135 | + --dbhost="$WP_DB_HOST" \ |
| 136 | + --path=/tmp/wp \ |
| 137 | + --skip-check |
| 138 | + wp config set DISABLE_WP_CRON true --raw --path=/tmp/wp |
| 139 | + wp core install \ |
| 140 | + --url="${WP_SITE_URL}" \ |
| 141 | + --title="Test Site" \ |
| 142 | + --admin_user=admin \ |
| 143 | + --admin_password=admin \ |
| 144 | + --admin_email=test@example.com \ |
| 145 | + --path=/tmp/wp \ |
| 146 | + --skip-email \ |
| 147 | + --allow-root |
| 148 | + wp user create author author@local.test --role=author --user_pass=author --path=/tmp/wp --allow-root |
| 149 | + wp user create editor editor@local.test --role=editor --user_pass=editor --path=/tmp/wp --allow-root |
| 150 | + wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --path=/tmp/wp --allow-root |
| 151 | +
|
| 152 | + - name: Show current config values |
| 153 | + run: wp config list --path=/tmp/wp --allow-root |
| 154 | + |
| 155 | + - name: Warm up WordPress |
| 156 | + run: | |
| 157 | + curl -s -o /dev/null -w "wp-login.php: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/wp-login.php |
| 158 | + curl -s -o /dev/null -w "homepage: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/ |
| 159 | +
|
| 160 | + - name: Install pnpm |
| 161 | + uses: pnpm/action-setup@v4 |
| 162 | + with: |
| 163 | + version: 10 |
| 164 | + |
| 165 | + - name: Setup Node |
| 166 | + uses: actions/setup-node@v4 |
| 167 | + with: |
| 168 | + node-version: lts/* |
| 169 | + cache: "pnpm" |
| 170 | + |
| 171 | + - name: Install pnpm dependencies |
| 172 | + run: pnpm install |
| 173 | + |
| 174 | + - name: Install Playwright Browsers |
| 175 | + run: npx playwright install --with-deps |
| 176 | + |
| 177 | + - name: Cache composer dependencies |
| 178 | + uses: actions/cache@v3 |
| 179 | + with: |
| 180 | + path: vendor |
| 181 | + key: composer-${{ hashFiles('composer.lock') }} |
| 182 | + |
| 183 | + - name: Run composer install |
| 184 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist |
| 185 | + |
| 186 | + - name: Run Pest tests |
| 187 | + run: ./vendor/bin/pest -v --ci --bail --colors=always |
| 188 | + |
| 189 | + - name: Upload test results |
| 190 | + if: always() |
| 191 | + uses: actions/upload-artifact@v4 |
| 192 | + with: |
| 193 | + name: test-results-php${{ matrix.php }}-wp${{ matrix.wordpress }} |
| 194 | + path: tests/Browser/Screenshots |
| 195 | + retention-days: 30 |
| 196 | + |
| 197 | + - name: Show FrankenPHP logs |
| 198 | + if: always() |
| 199 | + run: | |
| 200 | + echo "=== FrankenPHP logs ===" |
| 201 | + docker logs frankenphp || echo "No logs found" |
0 commit comments