blueprints/.github/workflows/preview-comment.yml

70 lines
3.3 KiB
YAML

# Responsible for making comments on pull requests, such as commenting for first time contributors.
name: Pull Request Comments
on:
pull_request_target:
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
jobs:
# Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance.
playground-details:
name: Comment on a pull request with Playground details
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout pull request head
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Resolve the Blueprint file
uses: actions/github-script@v7
id: blueprint
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const issue_number = context.payload.pull_request.number;
const prInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
};
// First, find a blueprint.json file in the pull request
const blueprintFile = ( await github.rest.pulls.listFiles( prInfo ) ).data.filter( file => file.filename.endsWith( '/blueprint.json' ) )[0];
if ( !blueprintFile ) {
return '';
}
return decodeURIComponent(blueprintFile.raw_url);
- name: Leave a comment about testing with Playground
uses: WordPress/action-wp-playground-pr-preview@v2
if: steps.blueprint.outputs.result != ''
with:
mode: comment
github-token: ${{ secrets.GITHUB_TOKEN }}
blueprint-url: ${{ steps.blueprint.outputs.result }}
comment-template: |
## Test using WordPress Playground
The changes in this pull request can previewed and tested using a [WordPress Playground](https://developer.wordpress.org/playground/) instance.
[WordPress Playground](https://developer.wordpress.org/playground/) is an experimental project that creates a full WordPress instance entirely within the browser.
### Some things to be aware of
- All changes will be lost when closing a tab with a Playground instance.
- All changes will be lost when refreshing the page.
- A fresh instance is created each time the link below is clicked.
For more details about these limitations and more, check out the [Limitations page](https://wordpress.github.io/wordpress-playground/limitations/) in the WordPress Playground documentation.
{{PLAYGROUND_BUTTON}}