-
Notifications
You must be signed in to change notification settings - Fork 369
Document the new GitHub Preview button action #2893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
281 changes: 281 additions & 0 deletions
281
packages/docs/site/docs/main/guides/github-action-pr-preview.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,281 @@ | ||
| --- | ||
| title: Adding PR Preview Buttons with GitHub Actions | ||
| slug: /guides/github-action-pr-preview | ||
| description: Automatically add Playground preview buttons to pull requests for your WordPress plugin or theme. | ||
| --- | ||
|
|
||
| The Playground PR Preview action adds a preview button to your pull requests. Clicking the button launches Playground with your plugin or theme installed from the PR branch: | ||
|
|
||
|  | ||
|
|
||
| For complete configuration options and advanced features, see the [action-wp-playground-pr-preview workflow README](https://github.com/WordPress/action-wp-playground-pr-preview/tree/v2). | ||
|
|
||
| ## How it works | ||
|
|
||
| The action runs on pull request events (opened, updated, edited). It can either update the PR description with a preview button or post the button as a comment. | ||
|
|
||
| ## Basic setup for plugins | ||
|
|
||
| For plugins without a build step, create `.github/workflows/pr-preview.yml`: | ||
|
|
||
| ```yaml | ||
| name: PR Preview | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, edited] | ||
|
|
||
| jobs: | ||
| preview: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Post Playground Preview Button | ||
| uses: WordPress/action-wp-playground-pr-preview@v2 | ||
| with: | ||
| mode: 'append-to-description' | ||
| plugin-path: . | ||
| ``` | ||
|
|
||
| The `plugin-path: .` setting points to your plugin directory. For subdirectories like `plugins/my-plugin`, use `plugin-path: plugins/my-plugin`. | ||
|
|
||
| See [adamziel/preview-in-playground-button-plugin-example](https://github.com/adamziel/preview-in-playground-button-plugin-example/pull/1) for a working example. | ||
|
|
||
| ## Basic setup for themes | ||
|
|
||
| For themes, use `theme-path` instead of `plugin-path`: | ||
|
|
||
| ```yaml | ||
| name: PR Preview | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, edited] | ||
|
|
||
| jobs: | ||
| preview: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Post Playground Preview Button | ||
| uses: WordPress/action-wp-playground-pr-preview@v2 | ||
| with: | ||
| theme-path: . | ||
| ``` | ||
|
|
||
| ## Button placement | ||
|
|
||
| By default, the action updates the PR description (`mode: append-to-description`). To post as a comment instead: | ||
|
|
||
| ```yaml | ||
| with: | ||
| plugin-path: . | ||
| mode: comment | ||
| ``` | ||
|
|
||
| The action wraps the button in HTML markers and updates it on subsequent runs. By default, it restores the button if you remove it. To prevent restoration: | ||
|
|
||
| ```yaml | ||
| with: | ||
| plugin-path: . | ||
| restore-button-if-removed: false | ||
| ``` | ||
|
|
||
| ## Working with built artifacts | ||
|
|
||
| For plugins or themes requiring compilation, the workflow involves building the code, exposing it via GitHub releases, and creating a blueprint that references the public URL. | ||
|
|
||
| Example workflow (see [complete documentation](https://github.com/WordPress/action-wp-playground-pr-preview/tree/v2#advanced-testing-built-ci-artifacts)): | ||
|
|
||
| ```yaml | ||
| name: PR Preview with Build | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, edited] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Build | ||
| run: | | ||
| npm install | ||
| npm run build | ||
| zip -r plugin.zip dist/ | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: built-plugin | ||
| path: plugin.zip | ||
|
|
||
| expose-build: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| outputs: | ||
| artifact-url: ${{ steps.expose.outputs.artifact-url }} | ||
| steps: | ||
| - name: Expose built artifact | ||
| id: expose | ||
| uses: WordPress/action-wp-playground-pr-preview/.github/actions/expose-artifact-on-public-url@v2 | ||
| with: | ||
| artifact-name: 'built-plugin' | ||
| pr-number: ${{ github.event.pull_request.number }} | ||
| commit-sha: ${{ github.sha }} | ||
| artifacts-to-keep: '2' | ||
|
|
||
| create-blueprint: | ||
| needs: expose-build | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| blueprint: ${{ steps.blueprint.outputs.result }} | ||
| steps: | ||
| - uses: actions/github-script@v7 | ||
| id: blueprint | ||
| with: | ||
| script: | | ||
| const blueprint = { | ||
| steps: [{ | ||
| step: "installPlugin", | ||
| pluginZipFile: { | ||
| resource: "url", | ||
| url: "${{ needs.expose-build.outputs.artifact-url }}" | ||
| } | ||
| }] | ||
| }; | ||
| return JSON.stringify(blueprint); | ||
| result-encoding: string | ||
|
|
||
| preview: | ||
| needs: create-blueprint | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| steps: | ||
| - uses: WordPress/action-wp-playground-pr-preview@v2 | ||
| with: | ||
| blueprint: ${{ needs.create-blueprint.outputs.blueprint }} | ||
| ``` | ||
|
|
||
| The `artifacts-to-keep` setting controls how many builds to retain per PR. For themes, change `installPlugin` to `installTheme`. | ||
|
|
||
| See [adamziel/preview-in-playground-button-built-artifact-example](https://github.com/adamziel/preview-in-playground-button-built-artifact-example/pull/2) for a complete working example. | ||
|
|
||
| ## Custom blueprints | ||
|
|
||
| Use blueprints to configure the Playground environment. You can install additional plugins, set WordPress options, import content, or run custom PHP. | ||
|
|
||
| Example installing your plugin with WooCommerce: | ||
|
|
||
| ```yaml | ||
| jobs: | ||
| create-blueprint: | ||
| name: Create Blueprint | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| blueprint: ${{ steps.blueprint.outputs.result }} | ||
| steps: | ||
| - name: Create Blueprint | ||
| id: blueprint | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const blueprint = { | ||
| steps: [ | ||
| { | ||
| step: "installPlugin", | ||
| pluginData: { | ||
| resource: "git:directory", | ||
| url: `https://github.com/${context.repo.owner}/${context.repo.repo}.git`, | ||
| ref: context.payload.pull_request.head.ref, | ||
| path: "/" | ||
| } | ||
| }, | ||
| { | ||
| step: "installPlugin", | ||
| pluginData: { | ||
| resource: "wordpress.org/plugins", | ||
| slug: "woocommerce" | ||
| } | ||
| } | ||
| ] | ||
| }; | ||
| return JSON.stringify(blueprint); | ||
| result-encoding: string | ||
|
|
||
| preview: | ||
| needs: create-blueprint | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| steps: | ||
| - uses: WordPress/action-wp-playground-pr-preview@v2 | ||
| with: | ||
| blueprint: ${{ needs.create-blueprint.outputs.blueprint }} | ||
| ``` | ||
|
|
||
| Or reference an external blueprint: | ||
|
|
||
| ```yaml | ||
| with: | ||
| blueprint-url: https://example.com/path/to/blueprint.json | ||
| ``` | ||
|
|
||
| See [Blueprints documentation](/blueprints) for all available steps and configuration options. | ||
|
|
||
| ## Template customization | ||
|
|
||
| Customize the preview content using template variables: | ||
|
|
||
| ```yaml | ||
| with: | ||
| plugin-path: . | ||
| description-template: | | ||
| ### Test this PR in WordPress Playground | ||
|
|
||
| {{PLAYGROUND_BUTTON}} | ||
|
|
||
| **Branch:** {{PR_HEAD_REF}} | ||
| ``` | ||
|
|
||
| Available variables: `{{PLAYGROUND_BUTTON}}`, `{{PLUGIN_SLUG}}`, `{{THEME_SLUG}}`, `{{PR_NUMBER}}`, `{{PR_TITLE}}`, `{{PR_HEAD_REF}}`, and more. | ||
|
|
||
| See the workflow README for the [complete list](https://github.com/WordPress/action-wp-playground-pr-preview/tree/v2#description-template). | ||
|
|
||
| ## Artifact exposure | ||
|
|
||
| The `expose-artifact-on-public-url` action uploads built files to a single release (tagged `ci-artifacts` by default). Each artifact gets a unique filename like `pr-123-abc1234.zip`. Old artifacts are automatically cleaned up based on `artifacts-to-keep`. | ||
|
|
||
| Configuration options: [Expose Artifact Inputs](https://github.com/WordPress/action-wp-playground-pr-preview/tree/v2#expose-artifact-inputs) | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **Button not appearing:** Workflow file must exist on the default branch. Check Actions tab for errors. | ||
|
|
||
| **Preview fails to load:** Verify path points to valid plugin/theme directory. Check build logs for artifacts. | ||
|
|
||
| **Not activated:** Check browser console for PHP errors. Dependencies may be missing. | ||
|
|
||
| **Permissions errors:** Set permissions at job level. | ||
|
|
||
| More: [workflow README](https://github.com/WordPress/action-wp-playground-pr-preview/tree/v2) | ||
|
|
||
| ## Examples | ||
|
|
||
| - [WordPress/blueprints](https://github.com/WordPress/blueprints/pull/155) - Blueprint previews | ||
| - [adamziel/preview-in-playground-button-plugin-example](https://github.com/adamziel/preview-in-playground-button-plugin-example/pull/3) - Plugin without build | ||
| - [adamziel/preview-in-playground-button-built-artifact-example](https://github.com/adamziel/preview-in-playground-button-built-artifact-example/pull/2) - Plugin with build | ||
|
|
||
| ## Next steps | ||
|
|
||
| - Add demo content ([guide](/guides/providing-content-for-your-demo)) | ||
| - Create custom blueprints ([docs](/blueprints)) | ||
| - Integrate with testing workflows | ||
| - Customize templates for reviewers | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 That is cool!