Skip to content

Commit 3c111ba

Browse files
committed
ci(preview): gracefully skip when Cloudflare secrets are missing
Guards wrangler versions upload behind a HAS_CF_SECRETS env check so forks without CLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID configured don't get a red X on every PR. Build still runs (validates code), and a sticky PR comment explains how to enable previews. Deploy workflow is intentionally not guarded — prod should fail loudly.
1 parent 1dfd436 commit 3c111ba

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

.github/workflows/preview.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ concurrency:
2020
jobs:
2121
preview:
2222
runs-on: ubuntu-latest
23+
env:
24+
HAS_CF_SECRETS: ${{ secrets.CLOUDFLARE_API_TOKEN != '' && secrets.CLOUDFLARE_ACCOUNT_ID != '' }}
2325
steps:
2426
- name: Resolve ref
2527
id: resolve
@@ -59,6 +61,7 @@ jobs:
5961

6062
- name: Upload preview version
6163
id: deploy
64+
if: env.HAS_CF_SECRETS == 'true'
6265
run: |
6366
set +e
6467
OUTPUT=$(npx wrangler versions upload --preview-alias ${{ steps.alias.outputs.alias }} 2>&1)
@@ -78,7 +81,7 @@ jobs:
7881
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
7982

8083
- name: Comment preview URL on PR
81-
if: github.event_name == 'pull_request'
84+
if: github.event_name == 'pull_request' && env.HAS_CF_SECRETS == 'true'
8285
uses: marocchino/sticky-pull-request-comment@v2
8386
with:
8487
header: preview-url
@@ -89,3 +92,19 @@ jobs:
8992
|---|---|
9093
| **Version** | ${{ steps.deploy.outputs.preview_url }} |
9194
| **Alias** | ${{ steps.deploy.outputs.alias_url }} |
95+
96+
- name: Comment missing-secrets notice on PR
97+
if: github.event_name == 'pull_request' && env.HAS_CF_SECRETS != 'true'
98+
uses: marocchino/sticky-pull-request-comment@v2
99+
with:
100+
header: preview-url
101+
message: |
102+
### Preview skipped
103+
104+
Cloudflare secrets are not configured for this repo. Previews are disabled until an admin sets them.
105+
106+
**To enable:** Settings → Secrets and variables → Actions, add:
107+
- `CLOUDFLARE_API_TOKEN` — token with `Workers Scripts:Edit` permission
108+
- `CLOUDFLARE_ACCOUNT_ID` — target Cloudflare account ID
109+
110+
The build itself passed, so this PR's code is still validated.

0 commit comments

Comments
 (0)