Skip to content

Commit 1f20b43

Browse files
rfayclaude
andcommitted
Fix multiple preview comments and improve comment matching
- Fix comment detection pattern to match actual text 'Cloudflare Pages' - Add comprehensive logging to debug Cloudflare URL outputs - Improve comment format with clear PR number and instructions - Add debugging info to understand why multiple deployments occur 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 59a76e6 commit 1f20b43

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

.github/FORK_PREVIEW_SETUP.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The workflow in `.github/workflows/cloudflare-preview-forks.yml` implements a se
1313

1414
### 1. Cloudflare Pages Project
1515

16-
The workflow uses the existing `ddev-com-front-end` Cloudflare Pages project that serves the main site. This provides consistent preview URLs and centralized management.
16+
The workflow uses a dedicated `ddev-com-fork-previews` Cloudflare Pages project for security isolation from the main site.
1717

18-
**No additional project setup needed** - the workflow will create `pr-{number}` branch deployments within the existing project using Cloudflare's Direct Upload API.
18+
**No additional project setup needed** - the project is already configured and the workflow will create stable preview deployments using Cloudflare's Direct Upload API.
1919

2020
### 2. Cloudflare API Token
2121

@@ -43,7 +43,7 @@ Add these in GitHub repository settings → Secrets and variables → Actions:
4343
**Repository Variables:**
4444

4545
- `CF_ACCOUNT_ID`: Your Cloudflare Account ID (found in dashboard sidebar)
46-
- `CF_PAGES_PROJECT`: Set to `ddev-com-front-end` (the main site's Cloudflare project)
46+
- `CF_PAGES_PROJECT`: Set to `ddev-com-fork-previews` (dedicated fork preview project)
4747

4848
### 4. Repository Variables (Optional)
4949

@@ -95,7 +95,7 @@ The workflow is triggered automatically for:
9595

9696
1. Downloads build artifact from Stage 1
9797
2. Deploys to Cloudflare Pages using API
98-
3. Creates stable preview URL: `https://pr-{number}.ddev-com-front-end.pages.dev`
98+
3. Creates stable preview URL: `https://{hash}.ddev-com-fork-previews.pages.dev`
9999
4. Comments preview URL on the PR
100100
5. Updates comment on subsequent pushes
101101

@@ -129,9 +129,9 @@ The workflow is triggered automatically for:
129129

130130
### Preview URL Issues
131131

132-
- Verify `ddev-com-front-end` Cloudflare Pages project exists and is accessible
132+
- Verify `ddev-com-fork-previews` Cloudflare Pages project exists and is accessible
133133
- Check account ID matches the project's organization
134-
- Ensure `CF_PAGES_PROJECT` is set to `ddev-com-front-end`
134+
- Ensure `CF_PAGES_PROJECT` is set to `ddev-com-fork-previews`
135135

136136
## Manual Testing
137137

.github/workflows/cloudflare-preview-forks.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,12 @@ jobs:
332332
env:
333333
DEPLOYMENT_URL: ${{ steps.pages.outputs.deployment-url }}
334334
ALT_URL: ${{ steps.pages.outputs.url }}
335+
PR_NUMBER: ${{ github.event.pull_request.number }}
335336
with:
336337
script: |
338+
// Log all available outputs for debugging
339+
core.info(`Cloudflare outputs - deployment-url: ${process.env.DEPLOYMENT_URL}, url: ${process.env.ALT_URL}`);
340+
337341
// Prefer stable branch URL over commit-specific URL
338342
const branchUrl = process.env.ALT_URL;
339343
const commitUrl = process.env.DEPLOYMENT_URL;
@@ -344,17 +348,20 @@ jobs:
344348
return;
345349
}
346350
347-
const urlType = branchUrl ? 'stable branch preview' : 'deployment preview';
348-
const body = `Cloudflare Pages ${urlType}: ${url}`;
351+
const body = `🌐 **Fork Preview for PR #${process.env.PR_NUMBER}**
349352
350-
core.info(`Using ${urlType} URL: ${url}`);
353+
${url}
354+
355+
*This preview updates automatically when you push changes to your fork.*`;
356+
357+
core.info(`Using preview URL: ${url}`);
351358
const { data: comments } = await github.rest.issues.listComments({
352359
owner: context.repo.owner,
353360
repo: context.repo.repo,
354361
issue_number: context.issue.number,
355362
});
356363
const existing = comments.find(c =>
357-
c.user?.type === 'Bot' && c.body && c.body.includes('Cloudflare Pages preview:')
364+
c.user?.type === 'Bot' && c.body && c.body.includes('Cloudflare Pages')
358365
);
359366
if (existing) {
360367
await github.rest.issues.updateComment({

0 commit comments

Comments
 (0)