diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 92c72cbbc..30b2273fd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -116,16 +116,124 @@ jobs: - name: Install PHP Dependencies run: composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: lts/* + + - name: Checkout wp-performance-action + uses: actions/checkout@v4 + with: + repository: swissspidy/wp-performance-action + ref: b7e3ffcf0fc4a48b62492e021e0ebeb51430ff11 + 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: Start WordPress Playground server + run: | + PLUGIN_REALPATH=$(realpath "$GITHUB_WORKSPACE") + PLUGIN_BASENAME=$(basename "$PLUGIN_REALPATH") + BLUEPRINT=$(realpath "$GITHUB_WORKSPACE/.github/performance-blueprint.json") + + MERGED_BLUEPRINT=./blueprints/tmp-merged.json + jq -s 'map(to_entries)|flatten|group_by(.key)|map({(.[0].key):map(.value)|add})|add' \ + ./blueprints/setup.json "$BLUEPRINT" > "$MERGED_BLUEPRINT" + + echo "Merged blueprint:" + cat "$MERGED_BLUEPRINT" | jq '.' + + ./node_modules/@wp-playground/cli/wp-playground.js server \ + --mount="./wp-content/mu-plugins:/wordpress/wp-content/mu-plugins" \ + --mount="$PLUGIN_REALPATH:/wordpress/wp-content/plugins/$PLUGIN_BASENAME" \ + --blueprint="$MERGED_BLUEPRINT" \ + --wp=6.8 \ + --php=8.2 & + working-directory: .wp-performance-action/env + + - name: Wait for WordPress Playground server on port 9400 + run: | + echo "Waiting for WordPress Playground to be ready 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 WP Performance Tests - uses: swissspidy/wp-performance-action@v2 + run: npm run test:performance + 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" + + - name: Stop server + if: always() + run: npm run stop-server + working-directory: .wp-performance-action/env + + - name: Generate performance results report + id: prepare-results + if: always() + run: | + WP_ARTIFACTS_PATH="$GITHUB_WORKSPACE/.wp-performance-action/env/artifacts" + RESULTS_JSON="$WP_ARTIFACTS_PATH/performance-results.json" + if [ -f "$RESULTS_JSON" ]; then + UUID=$(uuidgen) + cp "$RESULTS_JSON" "$RUNNER_TEMP/performance-results-$UUID.json" + echo "results=$RUNNER_TEMP/performance-results-$UUID.json" >> "$GITHUB_OUTPUT" + REPOSITORY_URL="${{ github.server_url }}/${{ github.repository }}" \ + npm run test:performance:results "$RUNNER_TEMP/performance-results-$UUID.json" + fi + working-directory: .wp-performance-action/env + + - name: Add workflow summary + if: always() + run: | + WP_ARTIFACTS_PATH="$GITHUB_WORKSPACE/.wp-performance-action/env/artifacts" + if [ -f "$WP_ARTIFACTS_PATH/performance-results.md" ]; then + cat "$WP_ARTIFACTS_PATH/performance-results.md" >> "$GITHUB_STEP_SUMMARY" + fi + + - name: Upload performance results + if: always() + uses: actions/upload-artifact@v4 + with: + name: performance-results-${{ github.run_number }} + path: .wp-performance-action/env/artifacts/ + retention-days: 30 + + - name: Check if a comment was already made + id: find-comment + if: github.event_name == 'pull_request' + 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_name == 'pull_request' && hashFiles('.wp-performance-action/env/artifacts/performance-results.md') != '' + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 with: - plugins: | - ./ - blueprint: .github/performance-blueprint.json - wp-version: "6.8" - urls: | - / - create-comment: ${{ github.event_name == 'pull_request' }} - print-results: true - upload-artifacts: true - debug: true + 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 }}