Skip to content

Commit 25b029b

Browse files
committed
fix: configure worker deploy for GitHub Actions
- Enable preview_urls in wrangler configuration - Remove invalid --out json flag from wrangler deploy - Extract preview URL from wrangler deploy console output - Update redirect tests to check for non-redirect status codes instead of expecting 200 (since there's no backend to proxy to) The worker now properly deploys to a preview environment and tests verify that redirects work as expected. Signed-off-by: Mark Phelps <[email protected]>
1 parent dba5aba commit 25b029b

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

.github/workflows/worker.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ jobs:
2727
id: deploy
2828
working-directory: ./worker
2929
run: |
30-
PREVIEW_URL=$(wrangler deploy --config wrangler.jsonc --env preview --dry-run=remote --out json | jq -r '.previews[0].url')
30+
# Deploy the worker to preview environment
31+
OUTPUT=$(wrangler deploy --config wrangler.jsonc --env preview 2>&1 | tee /dev/tty)
32+
33+
# Extract the deployed URL from the output
34+
# Look for the worker URL pattern
35+
PREVIEW_URL=$(echo "$OUTPUT" | grep -o 'https://docs-preview[^[:space:]]*' | head -1)
36+
37+
# If not found, try a more general pattern
38+
if [ -z "$PREVIEW_URL" ]; then
39+
PREVIEW_URL=$(echo "$OUTPUT" | grep -o 'https://[^[:space:]]*workers.dev' | head -1)
40+
fi
41+
42+
echo "Extracted preview URL: $PREVIEW_URL"
3143
echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
3244
3345
- name: Run redirect tests
@@ -47,15 +59,30 @@ jobs:
4759
test "$LOCATION" = "$BASE_URL/v1/getting-started"
4860
4961
echo "Testing already versioned path (/v1) → no redirect"
50-
STATUS=$(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/v1/getting-started)
51-
test "$STATUS" -eq 200
62+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-redirs 0 $BASE_URL/v1/getting-started)
63+
# Should not get a redirect (301/302), might get 404 or 522 since there's no backend
64+
if [ "$STATUS" -eq 301 ] || [ "$STATUS" -eq 302 ]; then
65+
echo "ERROR: /v1/ path should not redirect but got status $STATUS"
66+
exit 1
67+
fi
68+
echo "✓ Got status $STATUS (not a redirect)"
5269
5370
echo "Testing already versioned path (/v2) → no redirect"
54-
STATUS=$(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/v2/getting-started)
55-
test "$STATUS" -eq 200
71+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-redirs 0 $BASE_URL/v2/getting-started)
72+
# Should not get a redirect (301/302), might get 404 or 522 since there's no backend
73+
if [ "$STATUS" -eq 301 ] || [ "$STATUS" -eq 302 ]; then
74+
echo "ERROR: /v2/ path should not redirect but got status $STATUS"
75+
exit 1
76+
fi
77+
echo "✓ Got status $STATUS (not a redirect)"
5678
5779
echo "Testing excluded path (.css) → no redirect"
58-
STATUS=$(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/styles.css)
59-
test "$STATUS" -eq 200
80+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-redirs 0 $BASE_URL/styles.css)
81+
# Should not get a redirect (301/302), might get 404 or 522 since there's no backend
82+
if [ "$STATUS" -eq 301 ] || [ "$STATUS" -eq 302 ]; then
83+
echo "ERROR: .css path should not redirect but got status $STATUS"
84+
exit 1
85+
fi
86+
echo "✓ Got status $STATUS (not a redirect)"
6087
6188
echo "✅ All redirect tests passed!"

worker/wrangler.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"observability": {
1111
"enabled": true
1212
},
13+
"preview_urls": true,
1314
"env": {
1415
"preview": {
1516
"name": "docs-preview"

0 commit comments

Comments
 (0)