Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
686e25a
Document Worker Previews
yomna-shousha Jun 22, 2026
1e194e2
Diagram v1
yomna-shousha Jun 22, 2026
e6efbba
Refine Worker Previews diagram
yomna-shousha Jun 22, 2026
d1669bb
Refine Worker Previews overview
yomna-shousha Jun 22, 2026
48797fe
Refine Worker Previews settings docs
yomna-shousha Jun 23, 2026
2e2bd39
Add Durable Objects carousel diagram
yomna-shousha Jun 28, 2026
55ff148
Worker Previews docs: restructure resources, add recipes, update cros…
yomna-shousha Jun 29, 2026
f67e602
style: format
cloudflare-docs-bot[bot] Jun 29, 2026
b3d496d
Fix broken Access link, rewrite compare page to use Preview URLs, add…
yomna-shousha Jun 29, 2026
486abc0
Fix broken links flagged by CI
yomna-shousha Jun 29, 2026
458c2d8
Align preview secret docs with workers-sdk PR #15043, remove base-con…
yomna-shousha Aug 10, 2026
00da184
Remove base-config push, clarify Wrangler file as single source of tr…
yomna-shousha Aug 12, 2026
6803139
Fix Worker Previews links after rebase
yomna-shousha Aug 22, 2026
30c654f
WIP: restructure Previews docs for clarity, add placeholder screenshots
yomna-shousha Aug 22, 2026
79dc873
fix: export WorkerPreviewsAgentPrompt component
yomna-shousha Aug 22, 2026
f5fffa2
[Workers] Clarify Preview configuration docs
yomna-shousha Aug 23, 2026
cc264e6
Revise get-started page: clarify isolation, add dashboard screenshots…
yomna-shousha Aug 23, 2026
ac5ebaf
Simplify configuration page: branching analogy, consolidate base conf…
yomna-shousha Aug 24, 2026
fd49266
Add Previews observability page: logs, traces, metrics, Tail Workers,…
yomna-shousha Aug 24, 2026
d684708
Move preview workflow comparison into Previews docs
yomna-shousha Aug 25, 2026
8babc74
Update previews docs
yomna-shousha Aug 31, 2026
907deb4
[Workers] Remove Previews domain screenshots
yomna-shousha Aug 31, 2026
a06cddf
[Workers] Restore selected Previews screenshots
yomna-shousha Aug 31, 2026
a080e74
[Workers] Restore Previews compare workflows page
yomna-shousha Sep 1, 2026
32ce25f
style: format
cloudflare-docs-bot[bot] Sep 17, 2026
3edb21e
Agreed: moved page-specific Previews components to direct imports.
ask-bonk[bot] Sep 18, 2026
3721dc4
[Workers] Update Previews documentation
yomna-shousha Sep 21, 2026
8d47d7f
style: format
cloudflare-docs-bot[bot] Sep 21, 2026
46ceb0d
[Workers] Remove unused Previews redirects and diagram
yomna-shousha Sep 21, 2026
13de8c1
docs: update Workers Previews documentation
yomna-shousha Sep 21, 2026
3f1c4d9
docs: clarify Preview configuration examples
yomna-shousha Sep 21, 2026
9759624
[Workers] Clarify Preview configuration and migrations
yomna-shousha Sep 22, 2026
e068690
[Workers] Clarify Preview D1 migration target
yomna-shousha Sep 22, 2026
cffceed
[Workers] Explain shared Preview D1 workflow
yomna-shousha Sep 22, 2026
e23ae75
[Workers] Clarify Preview secrets and Workflows
yomna-shousha Sep 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update previews docs
  • Loading branch information
yomna-shousha committed Sep 17, 2026
commit 8babc74838efc160ce96a0842a0be2ea28f099e5
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/workers/previews/replace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions src/components/PreviewsResourcesDiagram.astro
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
<div class="pres-setting">
<code>UPLOADS</code>
<span class="pres-arrow-text">&#8594;</span>
<code class="pres-target">preview-uploads</code>
<code class="pres-target">r2-staging</code>
</div>
</div>
<div class="pres-divider"></div>
<div class="pres-card-section">
<span class="pres-section-label">Resource</span>
<div class="pres-resource pres-resource-shared">
<span class="pres-resource-type">R2 bucket</span>
<code class="pres-resource-name">preview-uploads</code>
<code class="pres-resource-name">r2-staging</code>
</div>
</div>
</div>
Expand All @@ -83,12 +83,12 @@
<select class="pres-branch-select" aria-label="Select Preview">
<option
value="redesign"
data-caption="Started from the base configuration. Same bucket as fix-api, so they read and write the same data."
data-caption="Started from Base configuration. Same bucket as fix-api, so they read and write the same data."
>redesign</option
>
<option
value="fix-api"
data-caption="Started from the base configuration. Same bucket as redesign, so they read and write the same data."
data-caption="Started from Base configuration. Same bucket as redesign, so they read and write the same data."
>fix-api</option
>
<option
Expand All @@ -110,15 +110,15 @@
<div class="pres-setting">
<code>UPLOADS</code>
<span class="pres-arrow-text">&#8594;</span>
<code class="pres-target">preview-uploads</code>
<code class="pres-target">r2-staging</code>
</div>
</div>
<div class="pres-divider"></div>
<div class="pres-card-section">
<span class="pres-section-label">Resource</span>
<div class="pres-resource pres-resource-shared">
<span class="pres-resource-type">R2 bucket</span>
<code class="pres-resource-name">preview-uploads</code>
<code class="pres-resource-name">r2-staging</code>
</div>
</div>
</div>
Expand All @@ -133,15 +133,15 @@
<div class="pres-setting">
<code>UPLOADS</code>
<span class="pres-arrow-text">&#8594;</span>
<code class="pres-target">preview-uploads</code>
<code class="pres-target">r2-staging</code>
</div>
</div>
<div class="pres-divider"></div>
<div class="pres-card-section">
<span class="pres-section-label">Resource</span>
<div class="pres-resource pres-resource-shared">
<span class="pres-resource-type">R2 bucket</span>
<code class="pres-resource-name">preview-uploads</code>
<code class="pres-resource-name">r2-staging</code>
</div>
</div>
</div>
Expand All @@ -156,7 +156,7 @@
<div class="pres-setting">
<code>UPLOADS</code>
<span class="pres-arrow-text">&#8594;</span>
<code class="pres-target">login-test-uploads</code>
<code class="pres-target">r2-login-test</code>
<span class="pres-pill">changed</span>
</div>
</div>
Expand All @@ -165,15 +165,15 @@
<span class="pres-section-label">Resource</span>
<div class="pres-resource pres-resource-own">
<span class="pres-resource-type">R2 bucket</span>
<code class="pres-resource-name">login-test-uploads</code>
<code class="pres-resource-name">r2-login-test</code>
</div>
</div>
</div>
</div>

<p class="pres-caption" data-pres-caption>
Started from the base configuration. Same bucket as fix-api, so they
read and write the same data.
Started from Base configuration. Same bucket as fix-api, so they read
and write the same data.
</p>
</div>
</div>
Expand All @@ -182,8 +182,8 @@
<div class="pres-shared-callout">
<span class="pres-shared-line"></span>
<span class="pres-shared-text"
>redesign and fix-api share <code>preview-uploads</code>. Same binding,
same data. feature/login has its own bucket.</span
>redesign and fix-api share <code>r2-staging</code>. Same binding, same
data. feature/login has its own bucket.</span
>
<span class="pres-shared-line"></span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/WorkerPreviewsAgentPrompt.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
const prompt = `Inspect this Worker project and configure Cloudflare Workers Previews safely.
const prompt = `Inspect this Worker project and configure Cloudflare Workers Previews.

1. Read the Wrangler configuration file and identify vars, secrets, bindings, Durable Objects, Workflows, service bindings, queues, routes, cron triggers, observability, limits, placement, and any env sections.
2. Add or update a \`previews\` block for every binding or runtime setting that the Preview needs. Do not assume production bindings are available in Previews.
Expand All @@ -25,7 +25,7 @@ const prompt = `Inspect this Worker project and configure Cloudflare Workers Pre
<p
class="text-foreground m-0 font-mono text-lg leading-relaxed sm:text-xl"
>
Configure Worker Previews for this project safely...
Configure Worker Previews for this project...
</p>
<p class="text-muted-foreground mt-3 mb-0 text-sm leading-relaxed">
Copy this prompt into your coding agent to configure Previews from an
Expand Down
201 changes: 201 additions & 0 deletions src/content/docs/workers/previews/automation-examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
pcx_content_type: how-to
title: Automation examples
description: Create Previews from Workers Builds, GitHub Actions, or another automation tool.
sidebar:
order: 7
products:
- workers
---

Start with raw `npx wrangler preview`. It is easy to copy, easy to debug, and does not require a wrapper action.

Before adding automation, check [Resources and isolation](/workers/previews/resources/) so you know which resources are isolated and which resources are shared.

## GitHub Actions

Use this workflow when you want GitHub Actions to create a Preview for each pull request.

### Add repository secrets

From your repository, use the GitHub CLI to add the secrets used by the workflow:

```sh
gh auth login
gh secret set CLOUDFLARE_API_TOKEN
gh secret set CLOUDFLARE_ACCOUNT_ID
```

Create an API token with permissions to edit Workers Scripts and the resources your Preview uses. You do not need to create a `GITHUB_TOKEN` secret. GitHub Actions provides `${{ secrets.GITHUB_TOKEN }}` automatically.

### Create a Preview

Start here:

```yaml title=".github/workflows/preview.yml"
name: Preview

on: [pull_request]

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx wrangler preview --json
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
```

Add install or build steps before `npx wrangler preview --json` if your Worker needs them.

Repository secrets are not available to forked pull requests by default. If your repository accepts forked pull requests, add a guard such as `github.event.pull_request.head.repo.full_name == github.repository` before using Cloudflare credentials.

### Use Workers Builds instead

If your Worker is already connected to Cloudflare, [Workers Builds](/workers/ci-cd/builds/) can create the Preview and comment the Preview URL on your pull request.

1. [Connect your Worker to a GitHub or GitLab repository](/workers/ci-cd/builds/#get-started).
2. Enable [Preview Builds](/workers/ci-cd/builds/build-branches/#configure-preview-builds).
3. Confirm the [Preview command](/workers/ci-cd/builds/configuration/#preview-command) is `npx wrangler preview`.

### Comment the Preview URL on a pull request

To post the Preview URL back to the pull request, name the Preview after the pull request number and save the URL as a workflow output.

Add `pull-requests: write` permission:

```yaml title=".github/workflows/preview.yml"
permissions:
contents: read
pull-requests: write
```

Then replace the `npx wrangler preview --json` step with these steps:

```yaml title=".github/workflows/preview.yml"
- id: preview
name: Create or update Preview
run: |
set -o pipefail
output="$(npx wrangler preview --name "pr-${{ github.event.pull_request.number }}" --json)"
printf '%s\n' "$output"
preview_url="$(printf '%s' "$output" | jq -er '.preview_urls[0] // .preview.urls[0]')"
echo "preview_url=$preview_url" >> "$GITHUB_OUTPUT"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

- name: Comment Preview URL on PR
run: gh pr comment "${{ github.event.pull_request.number }}" --body "Preview: ${{ steps.preview.outputs.preview_url }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

This creates a new comment each time the workflow runs. If you want a single sticky comment, use `gh pr comment --edit-last --create-if-none` or a pull request comment action.

This workflow uses `jq`, which is available on GitHub-hosted Ubuntu runners.

### Probe the Preview

After you have a Preview URL, add checks that hit the deployed Preview. This catches runtime-only problems that a build can miss.

```yaml title=".github/workflows/preview.yml"
- name: Probe Preview
run: curl --fail --show-error --silent "$PREVIEW_URL/api/health"
env:
PREVIEW_URL: ${{ steps.preview.outputs.preview_url }}
```

Change `/api/health` to a route that proves your Worker is healthy.

If a probe fails, use [Workers Observability](/workers/observability/) to inspect metrics, logs, errors, and traces. For Preview-specific details, refer to [Test and debug](/workers/previews/test-and-debug/).

### Capture a screenshot

For visual checks, capture the rendered Preview as a workflow artifact:

```yaml title=".github/workflows/preview.yml"
- name: Capture Preview screenshot
run: |
npx --yes playwright install --with-deps chromium
npx --yes playwright screenshot "$PREVIEW_URL" preview.png
env:
PREVIEW_URL: ${{ steps.preview.outputs.preview_url }}

- uses: actions/upload-artifact@v4
with:
name: preview-screenshot
path: preview.png
```

For hosted browser checks, use [Browser Run](/browser-run/). To capture screenshots through Browser Run, refer to the [screenshot endpoint](/browser-run/quick-actions/screenshot-endpoint/).

### Delete closed pull request Previews

If you create one Preview per pull request, delete it when the pull request closes:

```yaml title=".github/workflows/preview.yml"
on:
pull_request:
types: [opened, synchronize, reopened, closed]

jobs:
cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Delete Preview
run: npx wrangler preview delete --name "pr-${{ github.event.pull_request.number }}" --skip-confirmation
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
```

### Use wrangler-action instead

If you prefer a GitHub Action wrapper, use [`cloudflare/wrangler-action`](https://github.com/cloudflare/wrangler-action). The action runs Wrangler, exposes Preview URLs as workflow outputs, creates a GitHub Deployment when you pass `gitHubToken`, and writes a job summary.

Add `deployments: write` permission if you pass `gitHubToken`:

```yaml title=".github/workflows/preview.yml"
permissions:
contents: read
deployments: write
```

```yaml title=".github/workflows/preview.yml"
- uses: actions/checkout@v4
- id: preview
uses: cloudflare/wrangler-action@v3
with:
command: preview --name pr-${{ github.event.pull_request.number }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
```

Use `${{ steps.preview.outputs.preview-url }}` in the PR comment, probe, or screenshot steps above. The plain Wrangler examples use `preview_url` because they write their own workflow output.

## Monorepo with multiple Workers

Preview names are scoped to a Worker. In a monorepo, each Worker can have a Preview with the same pull request name:

```sh
cd workers/api && npx wrangler preview --name "pr-123"
cd ../web && npx wrangler preview --name "pr-123"
```

Service bindings between these Previews currently resolve to the bound Worker's production deployment rather than to another Worker's matching Preview. For end-to-end multi-Worker testing, use staging Workers or another environment strategy while Preview coverage continues to expand.

## Other automation tools

In any automation tool, run `npx wrangler preview` instead of `npx wrangler deploy` for pull request or branch previews:

```sh
npx wrangler preview --name "$BRANCH_NAME" --json
```

Use the JSON output to post the Preview URL wherever your team reviews changes.
Loading