@@ -130,34 +130,80 @@ jobs:
130130 name : website-build
131131 path : ${{ env.WEBSITE_DIR }}
132132
133+ - name : Resolve preview deploy eligibility
134+ id : preview_eligibility
135+ shell : bash
136+ env :
137+ CF_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
138+ CF_ACCOUNT_ID : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
139+ run : |
140+ if [[ -n "${CF_API_TOKEN}" && -n "${CF_ACCOUNT_ID}" ]]; then
141+ echo "can_deploy=true" >> "$GITHUB_OUTPUT"
142+ else
143+ echo "can_deploy=false" >> "$GITHUB_OUTPUT"
144+ fi
145+
133146 - name : Deploy Preview to Cloudflare
134147 id : deploy
148+ if : ${{ steps.preview_eligibility.outputs.can_deploy == 'true' }}
135149 working-directory : ${{ env.WEBSITE_DIR }}
136150 run : pnpm dlx @opennextjs/cloudflare deploy --env preview
137151 env :
138152 CLOUDFLARE_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
139153 CLOUDFLARE_ACCOUNT_ID : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
140154
141155 - name : Upsert PR comment with preview URL (no spam)
156+ if : ${{ always() && (steps.deploy.outcome == 'success' || steps.deploy.outcome == 'skipped') && github.event.pull_request.head.repo.fork == false }}
142157 uses : actions/github-script@v8
143158 env :
144159 MARKER : ${{ env.PREVIEW_COMMENT_MARKER }}
145160 DEPLOYMENT_URL : ${{ steps.deploy.outputs.deployment-url }}
161+ DEPLOY_OUTCOME : ${{ steps.deploy.outcome }}
162+ HEAD_IS_FORK : ${{ github.event.pull_request.head.repo.fork }}
163+ HAS_CF_SECRETS : ${{ steps.preview_eligibility.outputs.can_deploy }}
146164 with :
147165 script : |
148166 const marker = process.env.MARKER;
149- const url = process.env.DEPLOYMENT_URL || "Check the Cloudflare dashboard for the preview URL.";
167+ const url = process.env.DEPLOYMENT_URL || "";
168+ const deployOutcome = (process.env.DEPLOY_OUTCOME || "").toLowerCase();
169+ const isFork = (process.env.HEAD_IS_FORK || "").toLowerCase() === "true";
170+ const hasCfSecrets = (process.env.HAS_CF_SECRETS || "").toLowerCase() === "true";
171+
172+ const baseMeta = `- Branch: \`${context.payload.pull_request.head.ref}\`
173+ - Commit: \`${context.sha}\``;
174+
175+ let body;
176+ if (deployOutcome === "success") {
177+ body = `${marker}
178+ ## 🚀 Preview Deployment Ready!
179+
180+ Preview URL: ${url || "Check the Cloudflare dashboard for the preview URL."}
150181
151- const body = `${marker}
152- ## 🚀 Preview Deployment Ready!
182+ ${baseMeta}
153183
154- Preview URL: ${url}
184+ (This comment will be updated on new pushes.)
185+ `;
186+ } else if (!hasCfSecrets && isFork) {
187+ body = `${marker}
188+ ## ℹ️ Preview Deployment Skipped
155189
156- - Branch: \`${context.payload.pull_request.head.ref}\`
157- - Commit: \`${context.sha}\`
190+ This PR comes from a fork, and repository Cloudflare secrets are not exposed to \`pull_request\` workflows.
158191
159- (This comment will be updated on new pushes.)
160- `;
192+ ${baseMeta}
193+
194+ (This comment will be updated on new pushes.)
195+ `;
196+ } else {
197+ body = `${marker}
198+ ## ℹ️ Preview Deployment Skipped
199+
200+ Preview deployment was skipped because required Cloudflare secrets are missing.
201+
202+ ${baseMeta}
203+
204+ (This comment will be updated on new pushes.)
205+ `;
206+ }
161207
162208 const { owner, repo } = context.repo;
163209 const issue_number = context.issue.number;
0 commit comments