Skip to content

test-results-to-slack: add workflow_dispatch event support#47389

Open
dhruv7539 wants to merge 1 commit intoAutomattic:trunkfrom
dhruv7539:add-workflow-dispatch-support
Open

test-results-to-slack: add workflow_dispatch event support#47389
dhruv7539 wants to merge 1 commit intoAutomattic:trunkfrom
dhruv7539:add-workflow-dispatch-support

Conversation

@dhruv7539
Copy link
Copy Markdown

Summary

Add handling for workflow_dispatch events in the test-results-to-slack GitHub Action so that manually triggered workflow runs produce properly formatted Slack notifications instead of falling through to the generic fallback.

The problem: All workflow_dispatch events are grouped into a single Slack message because the eventName is not handled, making it easy to lose track of individual test runs.

The fix:

  • When sha and repository are provided via workflow inputs, the message includes commit context and a link to the commit (mirroring the existing repository_dispatch behavior with payload.inputs instead of payload.client_payload, as suggested by @anomiex)
  • Without those inputs, each run gets a unique message ID based on timestamp (like schedule events) to prevent unrelated runs from being grouped, and falls back to showing the current SHA context
  • Added corresponding test cases for all workflow_dispatch scenarios

Changes

  • projects/github-actions/test-results-to-slack/src/message.js — New workflow_dispatch event handler
  • projects/github-actions/test-results-to-slack/tests/message.test.js — 8 new test cases covering text formatting, block structure, and edge cases

Usage

Users can optionally pass sha and repository as workflow inputs for richer messages:

on:
  workflow_dispatch:
    inputs:
      sha:
        description: 'Commit tested'
        type: string
      repository:
        description: 'Repository tested'
        type: string

Fixes #39412

Made with Cursor

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
Copilot AI review requested due to automatic review settings February 27, 2026 19:41
@github-actions github-actions Bot added [Tests] Includes Tests Actions GitHub actions used to automate some of the work around releases and repository management labels Feb 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add testing instructions.
  • 🔴 Specify whether this PR includes any changes to data or privacy.
  • 🔴 Add changelog entries to affected projects

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:

## Testing instructions:

* Go to '..'
*

🔴 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:

## Does this pull request change what data or activity we track or use?

My PR adds *x* and *y*.

🔴 Action required: Please add missing changelog entries for the following projects: projects/github-actions/test-results-to-slack

Use the Jetpack CLI tool to generate changelog entries by running the following command: jetpack changelog add.
Guidelines: /docs/writing-a-good-changelog-entry.md


@github-actions github-actions Bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. OSS Citizen This Pull Request was opened by an Open Source contributor. labels Feb 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_dispatch branch in createMessage() to set an appropriate msgId, message target text, and (optionally) upstream commit context/button from payload.inputs.
  • Extend the message test suite with new workflow_dispatch cases 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.

Comment on lines +94 to +100
} 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 ) );
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +177 to +179
`(
`Workflow dispatch blocks for #description`,
async ( { inputs, expectedContextLength, expectedButtonsLength } ) => {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +93
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 ) );
}
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Actions GitHub actions used to automate some of the work around releases and repository management OSS Citizen This Pull Request was opened by an Open Source contributor. [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

action-test-results-to-slack doesn't support workflow_dispatch

3 participants