Skip to content

Commit

Permalink
Build/Test Tools: Post message for testing on Playground only after b…
Browse files Browse the repository at this point in the history
…uild succeeds.

Uses the `workflow_run` trigger to only leave pull request comments after the build jobs finish.

Props zieladam, desrosj.
See #59416.

git-svn-id: https://develop.svn.wordpress.org/trunk@57210 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
swissspidy committed Dec 20, 2023
1 parent cafaabf commit e62bad5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
57 changes: 50 additions & 7 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: >
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );
22 changes: 22 additions & 0 deletions .github/workflows/test-build-processes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e62bad5

Please sign in to comment.