diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index ebe380f983847..df276270f1396 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -4,8 +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: @@ -27,7 +29,8 @@ jobs: timeout-minutes: 5 if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }} steps: - - uses: wow-actions/welcome@72817eb31cda1de60f51893d80e2e82ce57f7e76 # v1.3.0 + - name: Post a welcome comment + uses: wow-actions/welcome@72817eb31cda1de60f51893d80e2e82ce57f7e76 # v1.3.0 with: FIRST_PR_REACTIONS: 'hooray' FIRST_PR_COMMENT: > @@ -81,17 +84,57 @@ jobs: permissions: issues: write pull-requests: write - if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }} + if: > + github.repository == 'WordPress/wordpress-develop' && + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' steps: - - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + - name: Download artifact + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts( { + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }}, + } ); + + const matchArtifact = artifacts.data.artifacts.filter( ( artifact ) => { + return artifact.name === 'pr-number' + } )[0]; + + if ( ! matchArtifact ) { + core.setFailed( 'No artifact found!' ); + return; + } + + const download = await github.rest.actions.downloadArtifact( { + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + } ); + + const fs = require( 'fs' ); + fs.writeFileSync( '${{github.workspace}}/pr-number.zip', Buffer.from( download.data ) ) + + - name: Unzip the artifact containing the PR number + run: unzip pr-number.zip + + - name: Leave a comment about testing with Playground + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 with: script: | + const fs = require( 'fs' ); + 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 }} + issue_number, }; + const comments = ( await github.rest.issues.listComments( commentInfo ) ).data; for ( const currentComment of comments ) { @@ -116,7 +159,7 @@ jobs: 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. - [Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${{ github.event.number }}). + [Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${ issue_number }). `; github.rest.issues.createComment( commentInfo ); diff --git a/.github/workflows/test-build-processes.yml b/.github/workflows/test-build-processes.yml index 20a6cb0b353a9..660cfdee81543 100644 --- a/.github/workflows/test-build-processes.yml +++ b/.github/workflows/test-build-processes.yml @@ -106,6 +106,28 @@ 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-number + echo ${{ github.event.number }} > ./pr-number/NR + + - name: Upload PR number as artifact + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + with: + name: pr-number + path: pr-number/ slack-notifications: name: Slack Notifications