Make WordPress Core

Changeset 57210


Ignore:
Timestamp:
12/20/2023 02:50:11 PM (14 months ago)
Author:
swissspidy
Message:

Build/Test Tools: Post message for testing on Playground only after build succeeds.

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

Props zieladam, desrosj.
See #59416.

Location:
trunk/.github/workflows
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/pull-request-comments.yml

    r57197 r57210  
    55  pull_request_target:
    66    types: [ 'opened' ]
    7     branches:
    8       - trunk
     7  workflow_run:
     8    workflows: [ 'Test Build Processes' ]
     9    types:
     10      - completed
    911
    1012# Cancels all previous workflow runs for pull requests that have not completed.
     
    2830    if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }}
    2931    steps:
    30       - uses: wow-actions/welcome@72817eb31cda1de60f51893d80e2e82ce57f7e76 # v1.3.0
     32      - name: Post a welcome comment
     33        uses: wow-actions/welcome@72817eb31cda1de60f51893d80e2e82ce57f7e76 # v1.3.0
    3134        with:
    3235          FIRST_PR_REACTIONS: 'hooray'
     
    8285      issues: write
    8386      pull-requests: write
    84     if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }}
     87    if: >
     88      github.repository == 'WordPress/wordpress-develop' &&
     89      github.event.workflow_run.event == 'pull_request' &&
     90      github.event.workflow_run.conclusion == 'success'
    8591    steps:
    86       - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
     92      - name: Download artifact
     93        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
    8794        with:
    8895          script: |
     96            const artifacts = await github.rest.actions.listWorkflowRunArtifacts( {
     97               owner: context.repo.owner,
     98               repo: context.repo.repo,
     99               run_id: ${{ github.event.workflow_run.id }},
     100            } );
     101
     102            const matchArtifact = artifacts.data.artifacts.filter( ( artifact ) => {
     103              return artifact.name === 'pr-number'
     104            } )[0];
     105
     106            if ( ! matchArtifact ) {
     107              core.setFailed( 'No artifact found!' );
     108              return;
     109            }
     110
     111            const download = await github.rest.actions.downloadArtifact( {
     112               owner: context.repo.owner,
     113               repo: context.repo.repo,
     114               artifact_id: matchArtifact.id,
     115               archive_format: 'zip',
     116            } );
     117
     118            const fs = require( 'fs' );
     119            fs.writeFileSync( '${{github.workspace}}/pr-number.zip', Buffer.from( download.data ) )
     120
     121      - name: Unzip the artifact containing the PR number
     122        run: unzip pr-number.zip
     123
     124      - name: Leave a comment about testing with Playground
     125        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
     126        with:
     127          script: |
     128            const fs = require( 'fs' );
     129            const issue_number = Number( fs.readFileSync( './NR' ) );
     130
    89131            // Comments are only added after the first successful build. Check for the presence of a comment and bail early.
    90132            const commentInfo = {
    91133              owner: context.repo.owner,
    92134              repo: context.repo.repo,
    93               issue_number: ${{ github.event.number }}
     135              issue_number,
    94136            };
     137
    95138            const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
    96139
     
    117160            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.
    118161
    119             [Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${{ github.event.number }}).
     162            [Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${ issue_number }).
    120163            `;
    121164
  • trunk/.github/workflows/test-build-processes.yml

    r57197 r57210  
    107107      directory: ${{ matrix.directory }}
    108108
     109  # Uploads the PR number as an artifact for the Pull Request Commenting workflow to download and then
     110  # leave a comment detailing how to test the PR within WordPress Playground.
     111  playground-comment:
     112    name: Leave WordPress Playground details
     113    runs-on: ubuntu-latest
     114    permissions:
     115      actions: write
     116    continue-on-error: true
     117    needs: [ test-core-build-process, test-core-build-process-macos, test-gutenberg-build-process, test-gutenberg-build-process-macos ]
     118    if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request' }}
     119
     120    steps:
     121      - name: Save PR number
     122        run: |
     123          mkdir -p ./pr-number
     124          echo ${{ github.event.number }} > ./pr-number/NR
     125
     126      - name: Upload PR number as artifact
     127        uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
     128        with:
     129          name: pr-number
     130          path: pr-number/
    109131
    110132  slack-notifications:
Note: See TracChangeset for help on using the changeset viewer.