You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-2Lines changed: 75 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,12 @@ Start with **[Quick start](#quick-start)** and choose the path that matches your
26
26
## Table of contents
27
27
28
28
-[Quick start](#quick-start)
29
+
-[Which setup should I use?](#which-setup-should-i-use)
29
30
-[No build step](#no-build-step)
30
31
-[With a build step](#with-a-build-step)
31
32
-[See it live](#see-it-live)
32
33
-[Recipes](#recipes)
34
+
-[Using an LLM to add this to your repository](#using-an-llm-to-add-this-to-your-repository)
33
35
-[How it works](#how-it-works)
34
36
-[Reference](#reference)
35
37
-[Limitations & gotchas](#limitations--gotchas)
@@ -42,6 +44,18 @@ Start with **[Quick start](#quick-start)** and choose the path that matches your
42
44
43
45
## Quick start
44
46
47
+
### Which setup should I use?
48
+
49
+
| Your repository | Use this setup |
50
+
|---|---|
51
+
| A plugin or theme works directly from the repository checkout |[No build step](#no-build-step)|
52
+
| A plugin or theme needs Composer, npm, Vite, or another build command first |[With a build step](#with-a-build-step)|
53
+
| You accept public fork PRs and need previews to work for those contributors |[With a build step](#with-a-build-step)|
54
+
| A preview should install multiple built plugins or themes | Start with [With a build step](#with-a-build-step), then use the [monorepo recipe](#monorepo-with-multiple-plugins-all-activated-together)|
55
+
| The repository is private | The default setup is not enough; Playground needs public, unauthenticated URLs. See [Limitations & gotchas](#limitations--gotchas). |
56
+
57
+
If you are not sure, start with **No build step** only when the files committed to the pull request are exactly the files WordPress should run. If CI must generate anything first, use **With a build step**.
58
+
45
59
### No build step
46
60
47
61
Use this setup when your plugin or theme can run directly from the repository, with no Composer install, npm build, or asset pipeline. Create one workflow file:
@@ -66,10 +80,18 @@ jobs:
66
80
github-token: ${{ secrets.GITHUB_TOKEN }}
67
81
```
68
82
83
+
You do not need to create `secrets.GITHUB_TOKEN`; GitHub provides it automatically. The `permissions` block gives that token the access this action needs.
84
+
69
85
Open a pull request. The action adds a Preview button to the pull request description. When someone clicks it, Playground fetches the plugin or theme from GitHub and boots WordPress with it activated.
70
86
71
87
This direct setup does not run a build command or publish a ZIP artifact; Playground loads the files from GitHub at the pull request ref.
72
88
89
+
Expected result:
90
+
91
+
- The PR workflow finishes successfully.
92
+
- The PR description contains a managed Preview button block.
93
+
- Clicking the button opens Playground with your plugin or theme installed and activated.
94
+
73
95
> **Fork PR note:** this direct one-workflow setup is simplest for same-repository PRs. Public fork PRs usually receive a read-only `GITHUB_TOKEN`, so the action may be unable to edit the PR description. If fork contributors need working previews, use the two-workflow build/publish setup below even when the build command is just a small zip step.
74
96
75
97
### With a build step
@@ -94,6 +116,8 @@ jobs:
94
116
npm run build:plugin-zip
95
117
```
96
118
119
+
In `artifacts: my-plugin=build/my-plugin.zip`, `my-plugin` is the artifact name and `build/my-plugin.zip` is the ZIP file your `build-command` must create. The ZIP should extract to a plugin slug folder, for example `my-plugin/my-plugin.php`, not just files at the ZIP root. See [Plugin zips must extract to a slug-named folder](#limitations--gotchas) if your preview opens but the plugin is missing.
120
+
97
121
```yaml
98
122
# .github/workflows/pr-preview-publish.yml
99
123
name: PR Preview - Publish
@@ -116,8 +140,18 @@ jobs:
116
140
kind: plugin # or: kind: theme
117
141
```
118
142
143
+
`kind: plugin` tells the publish workflow to generate the simplest Blueprint for one plugin ZIP: install it and activate it. Use `kind: theme` for one theme ZIP. For multiple ZIPs or extra setup steps, use a custom `blueprint:` recipe below.
144
+
145
+
You do not need to create `secrets.GITHUB_TOKEN`; GitHub provides it automatically to each workflow run.
146
+
119
147
Open a pull request. The build workflow runs `npm ci && npm run build:plugin-zip`. After that succeeds, the publish workflow uploads the resulting ZIP to a public release URL and posts the Preview button. When someone clicks it, Playground installs and activates the built plugin.
120
148
149
+
Expected result:
150
+
151
+
- The build workflow uploads a `wp-playground-preview-pr<N>-<SHA>` artifact.
152
+
- The publish workflow creates or updates a `ci-artifacts` prerelease and uploads the built ZIP there.
153
+
- The PR description contains a Preview button that opens Playground with the built plugin or theme installed.
154
+
121
155
> **Why two workflow files?** The build workflow runs untrusted pull request code with read-only permissions. The publish workflow runs later, from the trusted default-branch workflow, with the write permissions needed to upload release assets and update the pull request. See [How it works](#how-it-works).
122
156
123
157
---
@@ -139,7 +173,7 @@ Each link is a real, public repo running these workflows. Each PR has a working
139
173
140
174
Pick the recipe that matches your repository, then adjust the paths, commands, and artifact names for your project.
141
175
142
-
Unless a recipe shows a full workflow file, the YAML snippet is a step that goes under `jobs.preview.steps` in the [no-build workflow](#no-build-step).
176
+
Unless a recipe shows a full workflow file, the YAML snippet is a replacement step under `jobs.preview.steps` in the [no-build workflow](#no-build-step).
143
177
144
178
### Plugin in a subdirectory
145
179
@@ -154,6 +188,8 @@ In `.github/workflows/pr-preview.yml`, replace the Quick start step under `jobs.
154
188
155
189
### Theme
156
190
191
+
In `.github/workflows/pr-preview.yml`, replace the Quick start step under `jobs.preview.steps` with:
@@ -163,6 +199,8 @@ In `.github/workflows/pr-preview.yml`, replace the Quick start step under `jobs.
163
199
164
200
### Plugin **and** theme together
165
201
202
+
Use this when a PR should preview a plugin and a theme from the same repository. In `.github/workflows/pr-preview.yml`, replace the Quick start step under `jobs.preview.steps` with:
@@ -211,9 +249,17 @@ Or host the blueprint elsewhere and pass the URL:
211
249
212
250
Learn more about Blueprints: <https://wordpress.github.io/wordpress-playground/blueprints/>.
213
251
252
+
Choose the Blueprint input based on where the JSON comes from:
253
+
254
+
- Use `blueprint` when the workflow can include the full JSON string.
255
+
- Use `blueprint-url` when the JSON is already hosted at a public URL.
256
+
- Use `blueprint-from-artifact` when the build workflow generates `blueprint.json` dynamically.
257
+
214
258
### Single plugin with a build step
215
259
216
-
See the [Quick start with a build step](#with-a-build-step) above. The reusable workflow handles checkout, optional Node/PHP setup, build, zip, upload, public URL, blueprint, and button posting.
260
+
See the [Quick start with a build step](#with-a-build-step) above. The reusable workflow handles checkout, optional Node/PHP setup, build, ZIP upload, public URL, Blueprint generation, and button posting.
261
+
262
+
The most common mistake is producing a ZIP with the wrong shape. WordPress plugin ZIPs should extract to a slug-named folder, such as `my-plugin/my-plugin.php`. If your build command runs `zip -r my-plugin.zip .` from inside the plugin directory, stage the files into a folder first, then zip that folder.
217
263
218
264
### Monorepo with multiple plugins, all activated together
219
265
@@ -471,6 +517,33 @@ Available template variables are listed under [Reference → Template variables]
471
517
472
518
---
473
519
520
+
## Using an LLM to add this to your repository
521
+
522
+
If you ask an LLM or coding agent to set this up, give it enough context to choose the right path instead of blindly pasting the first YAML snippet.
523
+
524
+
Suggested prompt:
525
+
526
+
```text
527
+
Add WordPress/action-wp-playground-pr-preview@v3 to this repository.
528
+
First inspect whether the WordPress plugin or theme can run directly from the repository checkout, or whether CI must build files first.
529
+
If no build step is needed, add one pull_request workflow using plugin-path or theme-path.
530
+
If a build step is needed, add the two-workflow preview-build.yml / preview-publish.yml setup.
531
+
Use the smallest working configuration. Preserve existing CI. Do not use pull_request_target.
532
+
After editing, verify that any artifacts path listed in artifacts: is actually created by build-command.
533
+
```
534
+
535
+
Checklist for reviewing the LLM's output:
536
+
537
+
- `secrets.GITHUB_TOKEN` is referenced but not created manually.
538
+
- Direct action usage appears under `jobs.<job_id>.steps[].uses`.
539
+
- Reusable workflow usage appears under `jobs.<job_id>.uses`.
540
+
- Build and publish workflows use the same version, for example `@v3`.
541
+
- Every `artifacts` entry has the form `name=path/to/file.zip`, and the build command creates that exact ZIP path.
542
+
- Plugin ZIPs extract to a slug-named folder, not directly to files at the ZIP root.
543
+
- The workflow does not use `pull_request_target`.
0 commit comments