Skip to content

Commit 4fdfbd2

Browse files
committed
Add NGROK_HOST_FILE mode: expose tunnel host without rewriting site URL
Callers that set NGROK_HOST_FILE get a narrower alternative to the existing wp config set WP_HOME/WP_SITEURL behavior: only the bare ngrok host is written to that file, and WordPress's own home/siteurl/ WP_BASE_URL are left untouched. Existing callers that don't set this input are unaffected — the original wp config set path still runs when NGROK_HOST_FILE is empty. Also adds diagnostic steps (webhook-host visibility via wp eval, and a post-run dump of [ngrok-diag] log lines) to make the tunnel/webhook state visible directly in the job output rather than only in an uploaded artifact.
1 parent d350dfe commit 4fdfbd2

1 file changed

Lines changed: 67 additions & 2 deletions

File tree

.github/workflows/test-playwright.yml

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ on:
8787
default: true
8888
required: false
8989
type: boolean
90+
NGROK_HOST_FILE:
91+
description: >
92+
Repo-relative path to write the bare ngrok tunnel host to (no scheme).
93+
The caller's own WordPress plugin is expected to read this file and
94+
expose it as a real NGROK_HOST env var to PHP (e.g. via a mu-plugin
95+
calling putenv()), since wp-env has no built-in way to pass an
96+
arbitrary host env var into the tests-wordpress container. When set,
97+
WordPress's own home/siteurl are left untouched — only this file is
98+
written, so the site keeps using its local URL and just the
99+
caller's webhook endpoint gets pointed at the tunnel.
100+
default: ''
101+
required: false
102+
type: string
90103
TESTRAIL_PLAN_ID:
91104
description: TestRail plan ID for reporting.
92105
default: ''
@@ -291,12 +304,58 @@ jobs:
291304
- name: Update WordPress URLs to ngrok
292305
env:
293306
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
294-
if: ${{ inputs.NGROK_ENABLED && env.NGROK_AUTH_TOKEN != '' }}
307+
NGROK_HOST_FILE: ${{ inputs.NGROK_HOST_FILE }}
308+
if: ${{ inputs.NGROK_ENABLED && env.NGROK_AUTH_TOKEN != '' && env.NGROK_HOST_FILE == '' }}
295309
run: |
296310
npx wp-env run tests-cli wp config set WP_SITEURL "$NGROK_URL"
297311
npx wp-env run tests-cli wp config set WP_HOME "$NGROK_URL"
298312
sed -i "s|WP_BASE_URL=.*|WP_BASE_URL=$NGROK_URL|" .env.ci
299313
314+
- name: Expose ngrok host to the webhook endpoint only
315+
env:
316+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
317+
NGROK_HOST_FILE: ${{ inputs.NGROK_HOST_FILE }}
318+
if: ${{ inputs.NGROK_ENABLED && env.NGROK_AUTH_TOKEN != '' && env.NGROK_HOST_FILE != '' }}
319+
run: |
320+
# WordPress's own home/siteurl are intentionally left untouched here —
321+
# only the bare tunnel host is written, for the caller's own
322+
# NGROK_HOST-reading mu-plugin to expose to PHP's getenv(). The site
323+
# itself keeps using its local URL; only the webhook listening URL
324+
# is meant to go through the tunnel.
325+
NGROK_HOST="${NGROK_URL#https://}"
326+
NGROK_HOST="${NGROK_HOST#http://}"
327+
echo -n "$NGROK_HOST" > "$NGROK_HOST_FILE"
328+
echo "Wrote NGROK_HOST=$NGROK_HOST to $NGROK_HOST_FILE"
329+
330+
- name: "[Diagnostic] Confirm the webhook host is visible to PHP"
331+
if: ${{ inputs.NGROK_ENABLED && env.NGROK_AUTH_TOKEN != '' }}
332+
env:
333+
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
334+
NGROK_HOST_FILE: ${{ inputs.NGROK_HOST_FILE }}
335+
run: |
336+
echo "Expected NGROK_URL: $NGROK_URL"
337+
if [ -n "$NGROK_HOST_FILE" ]; then
338+
echo "--- NGROK_HOST_FILE mode (home/siteurl stay local) ---"
339+
echo "File contents ($NGROK_HOST_FILE):"
340+
cat "$NGROK_HOST_FILE" || echo "(file not found)"
341+
echo ""
342+
echo "wp option get home (should still be local, unchanged):"
343+
npx wp-env run tests-cli -- wp option get home
344+
echo "PHP getenv('NGROK_HOST') as seen by the tests-wordpress container:"
345+
npx wp-env run tests-cli -- wp eval 'echo getenv("NGROK_HOST") ?: "(empty)";'
346+
echo ""
347+
else
348+
echo "--- wp config set mode (home/siteurl rewritten to the tunnel) ---"
349+
echo "wp option get home (DB, what rest_url() actually resolves through):"
350+
npx wp-env run tests-cli -- wp option get home
351+
echo "wp option get siteurl (DB):"
352+
npx wp-env run tests-cli -- wp option get siteurl
353+
echo "wp config get WP_HOME (wp-config.php constant, just written above):"
354+
npx wp-env run tests-cli -- wp config get WP_HOME
355+
echo "wp config get WP_SITEURL (wp-config.php constant, just written above):"
356+
npx wp-env run tests-cli -- wp config get WP_SITEURL
357+
fi
358+
300359
- name: Execute custom code before executing the test script
301360
env:
302361
GH_TOKEN: ${{ github.token }}
@@ -311,9 +370,15 @@ jobs:
311370
run: |
312371
# Ensure .env.ci is deleted on exit
313372
trap 'rm -f .env.ci' EXIT
314-
373+
315374
npm run ${{ inputs.PLAYWRIGHT_SCRIPT }}
316375
376+
- name: "[Diagnostic] Dump ngrok webhook diagnostic log lines"
377+
if: always()
378+
run: |
379+
echo "=== [ngrok-diag] lines from the tests-wordpress container's PHP/Apache log ==="
380+
npx wp-env logs tests --no-watch 2>&1 | grep -i 'ngrok-diag' || echo "No [ngrok-diag] lines found — either NGROK_ENABLED was off, connectMerchant never ran, or nothing reached the incoming webhook route."
381+
317382
- name: Upload artifact
318383
if: always()
319384
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)