Make WordPress Core


Ignore:
Timestamp:
12/20/2023 02:50:11 PM (15 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.