Skip to content

Commit

Permalink
Build/Test Tools: Fix the workflow that posts a preview link on every…
Browse files Browse the repository at this point in the history
… Pull Request

Fixes a 403 error in the pull-request-comments.yml job by switching from a custom workflow dispatch call to the pull_request_target trigger.

Follow up to [57124], [57174].
Props ockham.
See #59416.



git-svn-id: https://develop.svn.wordpress.org/trunk@57178 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
adamziel committed Dec 10, 2023
1 parent 13e055c commit 1850589
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/pull-request-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ name: Pull Request Comments
on:
pull_request_target:
types: [ 'opened' ]
workflow_dispatch:
inputs:
pr_number:
description: 'The pull request number to process.'
required: true
type: string
branches:
- trunk

# 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_target' && github.head_ref || github.event_name == 'workflow_dispatch' && inputs.pr_number || github.sha }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.event_name == 'workflow_dispatch' && github.event.number || github.sha }}

# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
Expand All @@ -31,7 +26,6 @@ jobs:
pull-requests: write
timeout-minutes: 5
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }}

steps:
- uses: wow-actions/welcome@72817eb31cda1de60f51893d80e2e82ce57f7e76 # v1.3.0
with:
Expand Down Expand Up @@ -87,7 +81,7 @@ jobs:
permissions:
issues: write
pull-requests: write
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'workflow_dispatch' }}
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name == 'pull_request_target' }}
steps:
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
Expand All @@ -96,7 +90,7 @@ jobs:
const commentInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.inputs.pr_number
issue_number: ${{ github.event.number }}
};
const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
Expand All @@ -122,7 +116,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=${ context.payload.inputs.pr_number }).
[Test this pull request with WordPress Playground](https://playground.wordpress.net/wordpress.html?pr=${{ github.event.number }}).
`;
github.rest.issues.createComment( commentInfo );
30 changes: 2 additions & 28 deletions .github/workflows/test-build-processes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,14 @@ jobs:
os: ${{ matrix.os }}
directory: ${{ matrix.directory }}

# Calls the Pull Request Commenting workflow to 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: Dispatch workflow run
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
retries: 2
retry-exempt-status-codes: 418
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'pull-request-comments.yml',
ref: 'trunk',
inputs: {
pr_number: '${{ github.event.number }}'
}
});

slack-notifications:
name: Slack Notifications
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@trunk
permissions:
actions: read
contents: read
needs: [ test-core-build-process, test-core-build-process-macos, test-gutenberg-build-process, test-gutenberg-build-process-macos, playground-comment ]
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' && always() }}
with:
calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }}
Expand All @@ -154,7 +128,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
actions: write
needs: [ playground-comment ]
needs: [ slack-notifications ]
if: |
always() &&
github.repository == 'WordPress/wordpress-develop' &&
Expand Down

0 comments on commit 1850589

Please sign in to comment.