Add the Title Generation UI #180
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pull Request Comments | |
| on: | |
| pull_request: | |
| types: [ 'opened', 'synchronize', 'reopened', 'edited' ] | |
| # Cancels all previous workflow runs for pull requests that have not completed. | |
| concurrency: | |
| # The concurrency group contains the workflow name and the branch name for pull requests | |
| # or the commit hash for any other events. | |
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | |
| cancel-in-progress: true | |
| # Disable permissions for all available scopes by default. | |
| # Any needed permissions should be configured at the job level. | |
| permissions: {} | |
| jobs: | |
| # Builds the plugin ZIP file. | |
| build-plugin-zip: | |
| name: Build plugin zip | |
| uses: ./.github/workflows/build-plugin-zip.yml | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| # Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance. | |
| playground-details: | |
| name: Comment on a pull request with Playground details | |
| runs-on: ubuntu-24.04 | |
| needs: build-plugin-zip | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 | |
| with: | |
| name: ${{ github.event.repository.name }} | |
| path: ${{ github.event.repository.name }} | |
| - name: Check if comment already exists | |
| id: check-pr-contents | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| // Get the pull request details. | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number | |
| }); | |
| // Define the string to search for. | |
| const searchString = 'Test using WordPress Playground'; | |
| let foundString = false; | |
| // Check PR body. | |
| if (pr.body.includes(searchString)) { | |
| foundString = true; | |
| } | |
| // Set outputs. | |
| core.setOutput('string_found', foundString); | |
| console.log(`Search string "${searchString}" found: ${foundString}`); | |
| - name: Update PR body with a comment about testing with Playground | |
| if: steps.check-pr-contents.outputs.string_found == 'false' | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| const prNumber = context.issue.number; | |
| const blueprint = { | |
| preferredVersions: { | |
| php: '7.4', | |
| wp: 'latest', | |
| }, | |
| steps: [ | |
| { | |
| step: 'mkdir', | |
| path: '/tmp/pr', | |
| }, | |
| { | |
| step: 'writeFile', | |
| path: '/tmp/pr/pr.zip', | |
| data: { | |
| resource: 'url', | |
| url: `/plugin-proxy.php?org=WordPress&repo=ai&workflow=Pull%20Request%20Comments&artifact=ai&pr=${prNumber}`, | |
| caption: `Downloading AI Experiments PR ${prNumber}`, | |
| }, | |
| }, | |
| { | |
| step: 'unzip', | |
| zipPath: '/tmp/pr/pr.zip', | |
| extractToPath: '/tmp/pr', | |
| }, | |
| { | |
| step: 'installPlugin', | |
| pluginData: { | |
| resource: 'vfs', | |
| path: '/tmp/pr/ai.zip', | |
| }, | |
| } | |
| ] | |
| }; | |
| const blueprintUrl = `https://playground.wordpress.net/#${encodeURI(JSON.stringify(blueprint))}`; | |
| // Get the current PR details. | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| // Create the comment to append. | |
| const playgroundComment = `## Test using WordPress Playground | |
| The changes in this pull request can be previewed and tested using this [WordPress Playground](https://wordpress.github.io/wordpress-playground/) instance: | |
| [Click here to test this pull request](${blueprintUrl}).`; | |
| // Append the comment to the existing PR body. | |
| const updatedBody = pr.body + '\n\n' + playgroundComment; | |
| // Update the PR body. | |
| await github.rest.pulls.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| body: updatedBody | |
| }); | |
| console.log('Successfully updated PR body with Playground comment'); |