Skip to content

t813: fix TypeError in switch_template() when product uses default template mode #1446

t813: fix TypeError in switch_template() when product uses default template mode

t813: fix TypeError in switch_template() when product uses default template mode #1446

Workflow file for this run

name: Unit & Integration Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
php-lint:
name: PHP Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
with:
php-version: '8.2'
tools: none
- name: Check PHP syntax
run: |
echo "Checking PHP syntax across the codebase..."
errors=0
while IFS= read -r file; do
if ! php -l "$file" 2>&1 | grep -q "No syntax errors"; then
php -l "$file"
errors=$((errors + 1))
fi
done < <(find inc/ -name '*.php' -type f)
if [ "$errors" -gt 0 ]; then
echo ""
echo "Found $errors file(s) with syntax errors."
exit 1
fi
echo "All PHP files passed syntax check."
php-tests:
name: PHP ${{ matrix.php-version }}
needs: php-lint
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.php-version == '8.5' }}
strategy:
fail-fast: false
matrix:
php-version: ["8.2", "8.3", "8.4", "8.5"]
services:
mysql:
image: mariadb:11.4
env:
MYSQL_ROOT_PASSWORD: root
ports: [3306]
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=10s
--health-timeout=5s
--health-retries=5
container:
image: cimg/php:${{ matrix.php-version }}
options: --user root
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Composer global bin path
run: |
mkdir -p "$HOME/.config/composer/vendor/bin"
echo "PATH=$HOME/.config/composer/vendor/bin:$PATH" >> $GITHUB_ENV
- name: Install System Dependencies
run: |
# Remove broken packagecloud git-lfs source that returns 403 in cimg/php:8.5
rm -f /etc/apt/sources.list.d/github_git-lfs.list 2>/dev/null || true
apt-get update && apt-get install -y subversion mariadb-client
- name: Install PHP Extensions
run: |
install-php-extensions mysqli gd bcmath || echo "Extensions may already be installed."
- name: Install Xdebug for Coverage
if: matrix.php-version == '8.3'
run: |
install-php-extensions xdebug || echo "Xdebug may already be installed."
- name: Self-update Composer
run: |
composer self-update || echo "Composer update skipped due to permission issue."
- name: Install PHP Dependencies
run: |
composer install --no-interaction --prefer-dist
- name: Wait for MySQL to be ready
run: |
for i in {1..30}; do
if mysqladmin ping -h mysql --silent; then
echo "MySQL is up"
break
fi
echo "Waiting for MySQL..."
sleep 2
done
- name: Prepare WordPress Tests
run: |
rm -rf /tmp/wordpress-tests-lib /tmp/wordpress/
bash bin/install-wp-tests.sh wordpress_test root root mysql latest
ln -s "$GITHUB_WORKSPACE" /tmp/wordpress/wp-content/plugins/ultimate-multisite
- name: Run PHPUnit Tests
if: matrix.php-version != '8.3'
run: vendor/bin/phpunit
- name: Run PHPUnit Tests with Coverage
if: matrix.php-version == '8.3'
run: |
php -d zend_extension=xdebug.so -d xdebug.mode=coverage \
vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text \
| tee coverage-summary.txt
- name: Upload coverage to Codecov
if: matrix.php-version == '8.3'
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5
with:
file: ./coverage.xml
flags: unittests
name: php-${{ matrix.php-version }}
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
wp-performance:
name: WP Performance Metrics
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: read
pull-requests: write
env:
PERF_ACTION_DIR: .wp-performance-action/env
WP_PERF_ARTIFACTS: ${{ github.workspace }}/.wp-performance-action/env/artifacts
steps:
# ── Checkout both branches ──────────────────────────────────────
- name: Checkout PR branch
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
path: current
- name: Checkout base branch (main)
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: ${{ github.base_ref }}
path: baseline
# ── Environment setup ───────────────────────────────────────────
- name: Setup PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
with:
php-version: "8.2"
- name: Install PHP dependencies (both branches)
run: |
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --working-dir=current
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --working-dir=baseline
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: lts/*
- name: Checkout wp-performance-action
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
repository: swissspidy/wp-performance-action
ref: 233d525186e4d41bc7574837a3baeb3b5698656f
path: .wp-performance-action
- name: Install performance action dependencies
run: npm ci
working-directory: .wp-performance-action/env
- name: Install Playwright browsers
run: npx playwright install --with-deps
working-directory: .wp-performance-action/env
- name: Prepare merged blueprint
run: |
BLUEPRINT=$(realpath "$GITHUB_WORKSPACE/current/.github/performance-blueprint.json")
jq -s 'map(to_entries)|flatten|group_by(.key)|map({(.[0].key):map(.value)|add})|add' \
./blueprints/setup.json "$BLUEPRINT" > ./blueprints/tmp-merged.json
echo "Merged blueprint:"
cat ./blueprints/tmp-merged.json | jq '.'
working-directory: .wp-performance-action/env
# ── Baseline run (main branch) ─────────────────────────────────
- name: Start server with baseline plugin
run: |
BASELINE_PATH=$(realpath "$GITHUB_WORKSPACE/baseline")
./node_modules/@wp-playground/cli/wp-playground.js server \
--mount="./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins" \
--mount="$BASELINE_PATH:/wordpress/wp-content/plugins/ultimate-multisite" \
--blueprint="./blueprints/tmp-merged.json" \
--wp=6.8 \
--php=8.2 &
echo $! > /tmp/playground.pid
working-directory: .wp-performance-action/env
- name: Wait for baseline server
run: |
echo "Waiting for baseline server on port 9400..."
for i in $(seq 1 60); do
if curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server is ready after ${i}s"
exit 0
fi
echo " attempt $i/60..."
sleep 5
done
echo "ERROR: Server did not become ready within 300 seconds"
exit 1
- name: Run baseline performance tests
run: |
mkdir -p "$WP_PERF_ARTIFACTS"
for attempt in 1 2 3; do
echo "--- Baseline attempt $attempt/3 ---"
if ! curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server not responding — skipping"
continue
fi
if npm run test:performance; then
echo "Baseline tests passed on attempt $attempt"
# Save baseline results
cp "$WP_PERF_ARTIFACTS/performance-results.json" \
"$RUNNER_TEMP/baseline-results.json"
echo "baseline_ok=true" >> "$GITHUB_ENV"
exit 0
fi
echo "Baseline tests failed on attempt $attempt"
[ "$attempt" -lt 3 ] && sleep 10
done
echo "All baseline attempts failed — will run PR tests without comparison"
echo "baseline_ok=false" >> "$GITHUB_ENV"
working-directory: .wp-performance-action/env
env:
WP_BASE_URL: http://127.0.0.1:9400
WP_ARTIFACTS_PATH: ${{ github.workspace }}/.wp-performance-action/env/artifacts
BLOB_REPORT_PATH: ${{ github.workspace }}/.wp-performance-action/env/blob-report
SHARD: ""
URLS_TO_TEST: /
DEBUG: "true"
TEST_ITERATIONS: "20"
TEST_REPETITIONS: "2"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
- name: Stop baseline server
run: |
npm run stop-server 2>/dev/null || true
# Clean artifacts for the PR run
rm -rf "$WP_PERF_ARTIFACTS"
working-directory: .wp-performance-action/env
# ── PR branch run ───────────────────────────────────────────────
- name: Start server with PR branch plugin
run: |
CURRENT_PATH=$(realpath "$GITHUB_WORKSPACE/current")
./node_modules/@wp-playground/cli/wp-playground.js server \
--mount="./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins" \
--mount="$CURRENT_PATH:/wordpress/wp-content/plugins/ultimate-multisite" \
--blueprint="./blueprints/tmp-merged.json" \
--wp=6.8 \
--php=8.2 &
working-directory: .wp-performance-action/env
- name: Wait for PR server
run: |
echo "Waiting for PR server on port 9400..."
for i in $(seq 1 60); do
if curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server is ready after ${i}s"
exit 0
fi
echo " attempt $i/60..."
sleep 5
done
echo "ERROR: Server did not become ready within 300 seconds"
exit 1
- name: Run PR branch performance tests
run: |
mkdir -p "$WP_PERF_ARTIFACTS"
for attempt in 1 2 3; do
echo "--- PR branch attempt $attempt/3 ---"
if ! curl -sf --max-time 5 http://127.0.0.1:9400/ > /dev/null 2>&1; then
echo "Server not responding — skipping"
continue
fi
if npm run test:performance; then
echo "PR tests passed on attempt $attempt"
exit 0
fi
echo "PR tests failed on attempt $attempt"
[ "$attempt" -lt 3 ] && sleep 10
done
echo "All 3 attempts failed"
exit 1
working-directory: .wp-performance-action/env
env:
WP_BASE_URL: http://127.0.0.1:9400
WP_ARTIFACTS_PATH: ${{ github.workspace }}/.wp-performance-action/env/artifacts
BLOB_REPORT_PATH: ${{ github.workspace }}/.wp-performance-action/env/blob-report
SHARD: ""
URLS_TO_TEST: /
DEBUG: "true"
TEST_ITERATIONS: "20"
TEST_REPETITIONS: "2"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
- name: Stop server
if: always()
run: npm run stop-server 2>/dev/null || true
working-directory: .wp-performance-action/env
# ── Generate comparison report ──────────────────────────────────
- name: Generate performance comparison report
id: prepare-results
if: always()
run: |
RESULTS_JSON="$WP_PERF_ARTIFACTS/performance-results.json"
if [ ! -f "$RESULTS_JSON" ]; then
echo "No PR results found — skipping report"
exit 0
fi
# Build the results.js arguments: after-file [before-file]
ARGS="$RESULTS_JSON"
if [ "$baseline_ok" = "true" ] && [ -f "$RUNNER_TEMP/baseline-results.json" ]; then
ARGS="$RESULTS_JSON $RUNNER_TEMP/baseline-results.json"
echo "Generating comparison report (PR vs main)..."
else
echo "Generating report (PR branch only, no baseline available)..."
fi
REPOSITORY_URL="${{ github.server_url }}/${{ github.repository }}" \
npm run test:performance:results $ARGS
working-directory: .wp-performance-action/env
- name: Add workflow summary
if: always()
run: |
if [ -f "$WP_PERF_ARTIFACTS/performance-results.md" ]; then
cat "$WP_PERF_ARTIFACTS/performance-results.md" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload performance results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: performance-results-${{ github.run_number }}
path: |
.wp-performance-action/env/artifacts/
${{ runner.temp }}/baseline-results.json
retention-days: 30
- name: Check if a comment was already made
id: find-comment
if: github.event.pull_request.head.repo.full_name == github.repository
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: Performance test results for
- name: Comment on PR with performance results
if: github.event.pull_request.head.repo.full_name == github.repository && hashFiles('.wp-performance-action/env/artifacts/performance-results.md') != ''
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body-path: .wp-performance-action/env/artifacts/performance-results.md
token: ${{ secrets.GITHUB_TOKEN }}