Skip to content

Post a Playground preview link on every PR #1

Post a Playground preview link on every PR

Post a Playground preview link on every PR #1

# Performs tasks required to make a pull request available for testing within WordPress Playground.
name: WordPress Playground
on:
pull_request:
pull_request_target:
branches:
- trunk
workflow_dispatch:
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
env:
PUPPETEER_SKIP_DOWNLOAD: ${{ true }}
jobs:
# Creates a built copy of WordPress and uploads it as an artifact that can be used
# to preview the changes inside of WordPress Playground.
build-wordpress:
name: Upload WordPress build as an artifact
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 20
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
- name: Set up Node.js
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version-file: '.nvmrc'
cache: npm
- name: Log debug information
run: |
npm --version
node --version
curl --version
git --version
svn --version
- name: Install npm Dependencies
run: npm ci
- name: Build WordPress
run: npm run build
- name: Zip WordPress build
run: cd build && zip -r wordpress.zip .
- name: Upload the build directory as GitHub artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: always()
with:
name: wordpress-build-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
path: build/wordpress.zip
if-no-files-found: error
# Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance.
comment-on-pr:
name: Comment on the pull request
runs-on: ubuntu-latest
permissions:
issues: write
needs: [ 'build-wordpress' ]
if: ${{ 'opened' == github.event.action }}
steps:
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:

Check failure on line 83 in .github/workflows/wordpress-playground.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/wordpress-playground.yml

Invalid workflow file

You have an error in your yaml syntax on line 83
script: |
const issueComment = `## 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 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.
- Everytime this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
it's possible that the most recent build failed, or has not completed. Check the [list of workflow runs to be sure](https://github.com/WordPress/wordpress-develop/actions/workflows/wordpress-playground.yml).
[Test this pull request WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${{ context.issue.number }}).
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: issueComment
})