diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index 3d47c26638450..6b0a81d09a49e 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -4,9 +4,10 @@ name: Pull Request Comments on: pull_request_target: types: [ 'opened' ] - branches: - - trunk - + workflow_run: + workflows: ["Test Build Processes"] + types: + - completed # Cancels all previous workflow runs for pull requests that have not completed. concurrency: @@ -82,17 +83,47 @@ jobs: permissions: issues: write pull-requests: write - if: ${{ github.repository == 'adamziel/wordpress-develop' && github.event_name == 'pull_request_target' }} + if: > + github.repository == 'WordPress/wordpress-develop' && + github.event_name == 'workflow_run' && + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' steps: + - name: 'Download artifact' + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); + + - run: unzip pr.zip + - uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 with: script: | + const issue_number = Number(fs.readFileSync('./NR')); + // Comments are only added after the first successful build. Check for the presence of a comment and bail early. const commentInfo = { owner: context.repo.owner, repo: context.repo.repo, issue_number: ${{ github.event.number }} }; + const comments = ( await github.rest.issues.listComments( commentInfo ) ).data; for ( const currentComment of comments ) { diff --git a/.github/workflows/test-build-processes.yml b/.github/workflows/test-build-processes.yml index ff351f27f796b..2cd32022fe29a 100644 --- a/.github/workflows/test-build-processes.yml +++ b/.github/workflows/test-build-processes.yml @@ -106,6 +106,26 @@ jobs: os: ${{ matrix.os }} directory: ${{ matrix.directory }} + # Uploads the PR number as an artifact for the Pull Request Commenting workflow to download and then + # leave a comment detailing how to test the PR within WordPress Playground. + playground-comment: + name: Leave WordPress Playground details + runs-on: ubuntu-latest + permissions: + actions: write + continue-on-error: true + needs: [ test-core-build-process, test-core-build-process-macos, test-gutenberg-build-process, test-gutenberg-build-process-macos ] + if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request' }} + + steps: + - name: Save PR number + run: | + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + - uses: actions/upload-artifact@v2 + with: + name: pr + path: pr/ slack-notifications: name: Slack Notifications