@@ -106,7 +106,7 @@ jobs:
106106 - name : Upload Cloudflare Worker Preview Version
107107 id : upload_preview
108108 run : |
109- OUTPUT=$(pnpm --filter @codingcatdev/site exec wrangler versions upload --tag "pr-${{ github.event.pull_request.number }} " --message "PR #${{ github.event.pull_request.number }} : ${{ github.event.pull_request.title } }")
109+ OUTPUT=$(pnpm --filter @codingcatdev/site exec wrangler versions upload --tag "pr-${PR_NUMBER} " --message "PR #${PR_NUMBER} : ${PR_TITLE }")
110110 echo "$OUTPUT"
111111
112112 PREVIEW_URL=$(echo "$OUTPUT" | grep -i "Version Preview URL:" | awk '{print $NF}' | head -n 1)
@@ -115,26 +115,43 @@ jobs:
115115 echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
116116 echo "version_id=$VERSION_ID" >> $GITHUB_OUTPUT
117117
118+ echo "::notice title=Cloudflare Worker Preview URL::${PREVIEW_URL}"
119+
118120 echo "### ⚡ Cloudflare Worker Preview Ready" >> $GITHUB_STEP_SUMMARY
119121 echo "" >> $GITHUB_STEP_SUMMARY
120122 echo "- **Preview URL**: [${PREVIEW_URL}](${PREVIEW_URL})" >> $GITHUB_STEP_SUMMARY
121123 echo "- **Version ID**: \`${VERSION_ID}\`" >> $GITHUB_STEP_SUMMARY
122124 echo "- **Target Worker**: \`codingcatdev-dev\`" >> $GITHUB_STEP_SUMMARY
123125
124126 if [ -n "$PREVIEW_URL" ]; then
125- echo "### ⚡ Cloudflare Worker Preview Ready!" > pr_comment.md
126- echo "" >> pr_comment.md
127- echo "| Environment | URL |" >> pr_comment.md
128- echo "|---|---|" >> pr_comment.md
129- echo "| **PR Preview** | [${PREVIEW_URL}](${PREVIEW_URL}) |" >> pr_comment.md
130- echo "| **Dev Custom Domain** | [https://dev.codingcat.dev](https://dev.codingcat.dev) |" >> pr_comment.md
131- echo "" >> pr_comment.md
132- echo "- **Worker Version ID**: \`${VERSION_ID}\`" >> pr_comment.md
133- echo "- **Protection**: Restricted to \`@codingcat.dev\` accounts via Cloudflare Zero Trust Access" >> pr_comment.md
134- gh pr comment ${{ github.event.pull_request.number }} --body-file pr_comment.md
127+ cat << 'EOF' > pr_comment.md
128+ # ## ⚡ Cloudflare Worker Preview Ready!
129+
130+ | Environment | URL |
131+ |---|---|
132+ | **PR Preview** | [${PREVIEW_URL}](${PREVIEW_URL}) |
133+ | **Dev Custom Domain** | [https://dev.codingcat.dev](https://dev.codingcat.dev) |
134+
135+ - **Worker Version ID**: `${VERSION_ID}`
136+ - **Protection**: Restricted to `@codingcat.dev` accounts via Cloudflare Zero Trust Access
137+ EOF
138+ # Replace placeholder variables with actual values in pr_comment.md
139+ sed -i "s|\${PREVIEW_URL}|${PREVIEW_URL}|g" pr_comment.md
140+ sed -i "s|\${VERSION_ID}|${VERSION_ID}|g" pr_comment.md
141+
142+ # Check if bot has already posted a preview comment on this PR
143+ COMMENT_ID=$(gh api "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" --jq '.[] | select((.user.login=="github-actions[bot]" or .user.login=="app/github-actions") and (.body | contains("Cloudflare Worker Preview Ready"))) | .id' | tail -n 1)
144+
145+ if [ -n "$COMMENT_ID" ]; then
146+ gh api -X PATCH "repos/${{ github.repository }}/issues/comments/${COMMENT_ID}" -f body="$(cat pr_comment.md)"
147+ else
148+ gh pr comment "$PR_NUMBER" --body-file pr_comment.md
149+ fi
135150 fi
136151 env :
137152 CLOUDFLARE_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
138153 CLOUDFLARE_ACCOUNT_ID : ${{ secrets.CLOUDFLARE_ACCOUNT_ID || 'c46bd0f3b9ed47b8692cca098030edbf' }}
139154 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
155+ PR_NUMBER : ${{ github.event.pull_request.number }}
156+ PR_TITLE : ${{ github.event.pull_request.title }}
140157
0 commit comments