name: PR Playground Preview (Built Artifact) on: pull_request: types: [opened, synchronize, reopened, edited] jobs: build: name: Build Plugin Artifact runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Install dependencies run: npm install - name: Build plugin run: | npm run build cd dist zip -r ../plugin.zip . cd .. - name: Upload build artifact for next job uses: actions/upload-artifact@v4 with: name: built-plugin-${{ github.event.pull_request.number }}-${{ github.sha }} path: plugin.zip retention-days: 1 expose-build-artifact-on-public-url: name: Expose Built Artifact on a Public GitHub Release URL needs: build runs-on: ubuntu-latest permissions: contents: write outputs: artifact-url: ${{ steps.expose.outputs.artifact-url }} artifact-name: ${{ steps.expose.outputs.artifact-name }} 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-${{ github.event.pull_request.number }}-${{ github.sha }} pr-number: ${{ github.event.pull_request.number }} commit-sha: ${{ github.sha }} # Number of artifacts to keep for this PR (0 = unlimited) # Change this value to keep more/fewer artifacts per PR artifacts-to-keep: '2' release-tag: 'ci-artifacts' create-blueprint: name: Create Playground Blueprint needs: expose-build-artifact-on-public-url runs-on: ubuntu-latest outputs: blueprint: ${{ steps.blueprint.outputs.result }} steps: - name: Create blueprint with artifact URL id: blueprint uses: actions/github-script@v7 with: script: | const blueprint = { "$schema": "https://playground.wordpress.net/blueprint-schema.json", "preferredVersions": { "php": "8.2", "wp": "latest" }, "steps": [ { "step": "installPlugin", "pluginData": { "resource": "url", "url": "${{ needs.expose-build-artifact-on-public-url.outputs.artifact-url }}" }, "options": { "activate": true } } ] }; return JSON.stringify(blueprint); result-encoding: string playground-preview: name: Post Playground Preview Button needs: create-blueprint runs-on: ubuntu-latest permissions: contents: read pull-requests: write issues: write steps: - name: Post Playground Preview Button uses: WordPress/action-wp-playground-pr-preview@v2 with: mode: append-to-description blueprint: ${{ needs.create-blueprint.outputs.blueprint }} github-token: ${{ secrets.GITHUB_TOKEN }}