test-results-to-slack: add workflow_dispatch event support#47389
test-results-to-slack: add workflow_dispatch event support#47389dhruv7539 wants to merge 1 commit intoAutomattic:trunkfrom
Conversation
Add handling for `workflow_dispatch` events so that manually triggered workflow runs produce properly formatted Slack notifications instead of being grouped under a generic fallback. When `sha` and `repository` inputs are provided via workflow inputs, the message includes commit context and links (mirroring the existing `repository_dispatch` behavior). Without those inputs, each run gets a unique message ID based on timestamp to prevent unrelated runs from being grouped together. Fixes Automattic#39412 Made-with: Cursor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so: 🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so: 🔴 Action required: Please add missing changelog entries for the following projects: Use the Jetpack CLI tool to generate changelog entries by running the following command: |
There was a problem hiding this comment.
Pull request overview
Adds first-class handling for workflow_dispatch in the test-results-to-slack GitHub Action so manually triggered runs generate correctly grouped Slack notifications (instead of falling into the generic/undefined-ID path).
Changes:
- Add a
workflow_dispatchbranch increateMessage()to set an appropriatemsgId, message target text, and (optionally) upstream commit context/button frompayload.inputs. - Extend the message test suite with new
workflow_dispatchcases covering text formatting and block/button structure.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/github-actions/test-results-to-slack/src/message.js | Implements workflow_dispatch message formatting and grouping behavior, including optional upstream sha/repo handling. |
| projects/github-actions/test-results-to-slack/tests/message.test.js | Adds coverage for workflow_dispatch text and block/button expectations across input scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else { | ||
| msgId = `workflow_dispatch-${ Date.now() }`; | ||
| const commitUrl = `${ serverUrl }/${ repository }/commit/${ sha }`; | ||
| contextElements.push( | ||
| getTextContextElement( `Last commit: ${ sha.substring( 0, 8 ) }` ) | ||
| ); | ||
| buttons.push( getButton( `Commit ${ sha.substring( 0, 8 ) }`, commitUrl ) ); |
There was a problem hiding this comment.
For the workflow_dispatch case without inputs.sha, using Date.now() for msgId makes the identifier non-deterministic, so the action can’t find/update an existing failure message on reruns (similar to schedule). Since runId (and optionally runAttempt) is already unique per workflow run, consider using workflow_dispatch-${runId} (or ${runId}/${runAttempt}) instead to avoid grouping across runs while still allowing updates when a run is re-attempted.
| `( | ||
| `Workflow dispatch blocks for #description`, | ||
| async ( { inputs, expectedContextLength, expectedButtonsLength } ) => { |
There was a problem hiding this comment.
The test name template uses #description, which doesn’t interpolate in Jest’s test.each title strings (the placeholder is $description). Switching to $description will make the generated test names meaningful in output.
| if ( eventName === 'workflow_dispatch' ) { | ||
| target = `for manual run on ${ refType } _*${ refName }*_`; | ||
|
|
||
| if ( payload.inputs?.sha ) { | ||
| const upstreamSha = payload.inputs.sha; | ||
| msgId = `workflow_dispatch-${ upstreamSha }`; | ||
| contextElements.push( | ||
| getTextContextElement( `Last commit: ${ upstreamSha.substring( 0, 8 ) }` ) | ||
| ); | ||
|
|
||
| if ( payload.inputs?.repository ) { | ||
| const commitUrl = `${ serverUrl }/${ payload.inputs.repository }/commit/${ upstreamSha }`; | ||
| buttons.push( getButton( `Commit ${ upstreamSha.substring( 0, 8 ) }`, commitUrl ) ); | ||
| } |
There was a problem hiding this comment.
This adds support for workflow_dispatch-specific inputs (payload.inputs.sha / payload.inputs.repository) that change grouping and commit-link behavior. It would be helpful to document these optional workflow inputs in the README alongside the existing repository_dispatch payload section, so users know how to enable richer/manual-run grouping.
jeherve
left a comment
There was a problem hiding this comment.
Thank you for your contribution.
Could you address the first feedback from Copilot below, as well as the missing items from the list here?
#47389 (comment)
I think it would also be helpful if you could update the action's readme to mention how this can be used, maybe with a usage example.
Summary
Add handling for
workflow_dispatchevents in thetest-results-to-slackGitHub Action so that manually triggered workflow runs produce properly formatted Slack notifications instead of falling through to the generic fallback.The problem: All
workflow_dispatchevents are grouped into a single Slack message because theeventNameis not handled, making it easy to lose track of individual test runs.The fix:
shaandrepositoryare provided via workflow inputs, the message includes commit context and a link to the commit (mirroring the existingrepository_dispatchbehavior withpayload.inputsinstead ofpayload.client_payload, as suggested by @anomiex)scheduleevents) to prevent unrelated runs from being grouped, and falls back to showing the current SHA contextChanges
projects/github-actions/test-results-to-slack/src/message.js— Newworkflow_dispatchevent handlerprojects/github-actions/test-results-to-slack/tests/message.test.js— 8 new test cases covering text formatting, block structure, and edge casesUsage
Users can optionally pass
shaandrepositoryas workflow inputs for richer messages:Fixes #39412
Made with Cursor