tools/monorepo-utils/src/slack-test-report/README.md
A utility tool to send test reports to Slack channels. This tool is particularly useful for notifying teams about test results, especially failures, directly in Slack.
To see available commands run pnpm utils slack-test-report --help from the project root.
-c, --conclusion <conclusion> (Required): Test run conclusion. Expected one of: success, failure, skipped, cancelled-r, --report-name <reportName>: The name of the report (e.g., "post-merge tests", "daily e2e tests")-u, --username <username>: The Slack username (default: "Github reporter")-n, --pr-number <prNumber>: The PR number to include in the message (for pull_request events)-t, --pr-title <prTitle>: The PR title to include in the message (for pull_request events)-m, --commit-message <commitMessage>: The commit message--config <configPath>: Path to a JSON config file containing notification rules or settingsThe following environment variables are required:
SLACK_TOKEN: Slack API token for sending messagesDEFAULT_CHECKS_CHANNEL: Default Slack channel ID for notificationsGITHUB_SHA: Git commit SHAGITHUB_ACTOR: GitHub username of the person who triggered the actionGITHUB_TRIGGERING_ACTOR: GitHub username of the person who triggered the workflowGITHUB_EVENT_NAME: Name of the GitHub event that triggered the workflowGITHUB_RUN_ID: Unique identifier of the workflow runGITHUB_RUN_ATTEMPT: Attempt number of the workflow runGITHUB_SERVER_URL: GitHub server URLGITHUB_REPOSITORY: Repository name with ownerGITHUB_REF_TYPE: The type of ref that triggered the workflowGITHUB_REF_NAME: The branch or tag name that triggered the workflowThe configuration file is optional. If no config file is provided, the tool will simply send notifications to the channel specified in the DEFAULT_CHECKS_CHANNEL environment variable.
When you need more complex routing logic (e.g., sending different types of test results to different channels), you can provide a JSON configuration file. The config file should have the following structure:
{
"defaultChannel": "DEFAULT_CHANNEL_ENV_VAR",
"routes": [
{
"checkType": "release-checks",
"channels": ["CHANNEL_ENV_VAR_1"],
"excludeDefaultChannel": false
},
{
"refName": "release/**",
"channels": ["CHANNEL_ENV_VAR_2"],
"excludeDefaultChannel": true
}
]
}
defaultChannel: Environment variable name for the default Slack channelroutes: Array of routing rules with the following properties:checkType: (Optional) Type of check to match (e.g., "release-checks", "daily-checks")refName: (Optional) Git reference pattern to match (supports glob patterns)channels: Array of environment variable names for Slack channel IDsexcludeDefaultChannel: (Optional) If true, skips sending to the default channel for matching rulesAt least one of checkType or refName must be specified in each route.
The tool sends messages with the following information:
Send a failure report for a pull request:
pnpm utils slack-test-report \
-c failure \
-r "E2E Tests" \
-n "1234" \
-t "Add new feature" \
-m "Fix e2e tests"
Send a failure report with custom routing:
pnpm utils slack-test-report \
--config ".github/workflows/slack-report-config.json" \
-c failure \
-r "Daily Checks" \
-m "Test commit message"
Note: The tool only sends messages for test failures. Other conclusions (success, skipped, cancelled) will be logged but won't trigger Slack notifications.