Skip to content

Commit 7083dee

Browse files
committed
Ensure PR comment is added only after successful deployment
1 parent 2b1b80a commit 7083dee

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

.github/workflows/pr-preview.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
done
6767
6868
- name: Deploy to GitHub Pages
69+
id: deploy
6970
uses: peaceiris/actions-gh-pages@v3
7071
with:
7172
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -81,7 +82,34 @@ jobs:
8182
echo "url=${PREVIEW_URL}" >> $GITHUB_OUTPUT
8283
echo "Preview URL: ${PREVIEW_URL}"
8384
85+
- name: Verify deployment and wait for availability
86+
run: |
87+
PREVIEW_URL="${{ steps.preview-url.outputs.url }}"
88+
MAX_ATTEMPTS=12
89+
ATTEMPT=0
90+
91+
echo "Verifying GitHub Pages deployment..."
92+
echo "Preview URL: ${PREVIEW_URL}"
93+
94+
# Wait up to 2 minutes for the preview to become available
95+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
96+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "${PREVIEW_URL}" || echo "000")
97+
if [ "$HTTP_CODE" = "200" ]; then
98+
echo "✓ Preview is now available and accessible!"
99+
exit 0
100+
fi
101+
ATTEMPT=$((ATTEMPT + 1))
102+
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
103+
echo "Attempt ${ATTEMPT}/${MAX_ATTEMPTS}: Preview not yet available (HTTP ${HTTP_CODE}), waiting 10 seconds..."
104+
sleep 10
105+
fi
106+
done
107+
108+
echo "⚠ Preview deployment completed, but URL not yet accessible (may still be propagating)."
109+
echo "The preview should be available shortly. Comment will be added with the preview URL."
110+
84111
- name: Find existing comment
112+
if: success()
85113
uses: peter-evans/find-comment@v3
86114
id: find-comment
87115
with:
@@ -90,6 +118,7 @@ jobs:
90118
body-includes: 'Preview Build'
91119

92120
- name: Create or update PR comment
121+
if: success()
93122
uses: peter-evans/create-or-update-comment@v4
94123
with:
95124
comment-id: ${{ steps.find-comment.outputs.comment-id }}

0 commit comments

Comments
 (0)