diff --git a/.github/workflows/pr-playground-preview.yml b/.github/workflows/pr-playground-preview.yml new file mode 100644 index 00000000..c9dc4fac --- /dev/null +++ b/.github/workflows/pr-playground-preview.yml @@ -0,0 +1,47 @@ +name: PR Playground Preview + +on: + workflow_run: + workflows: ["Test"] + types: + - completed + +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }} + cancel-in-progress: true + +permissions: {} + +jobs: + playground-preview: + name: Add Playground preview to PR + runs-on: ubuntu-24.04 + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + permissions: + contents: read + pull-requests: write + + steps: + - name: Get PR number + id: pr + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + with: + script: | + const prs = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: `${context.payload.workflow_run.head_repository.owner.login}:${context.payload.workflow_run.head_branch}`, + state: 'open', + }); + if (!prs.data.length) throw new Error('No open PR found for this branch'); + core.setOutput('number', prs.data[0].number); + + - name: Post Playground preview button + uses: WordPress/action-wp-playground-pr-preview@c8607529dac8d2bf9a1e8493865fc97cd1c3c87b # v2 + with: + mode: append-to-description + plugin-path: . + pr-number: ${{ steps.pr.outputs.number }} + github-token: ${{ secrets.GITHUB_TOKEN }}