-
Notifications
You must be signed in to change notification settings - Fork 14
github-actions: Add Slack notifications for kernelCI failures #1217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shreeya-patel98
wants to merge
1
commit into
main
Choose a base branch
from
shreeya_kernelci_slack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Builds a Slack chat.postMessage payload for a kernelCI failure and writes | ||
| # it to stdout (or to a file via --output). The caller is responsible for | ||
| # posting it (e.g. via slackapi/slack-github-action with a bot token). | ||
| # | ||
| # Usage: | ||
| # notify-slack-kernelci.sh \ | ||
| # --channel-id CHANNEL_ID \ | ||
| # --base-branch BRANCH --head-ref BRANCH --head-sha SHA \ | ||
| # --pr-number N --is-pr true|false \ | ||
| # --repo OWNER/REPO --run-id ID \ | ||
| # --failed-stages "stage1, stage2, ..." \ | ||
| # [--mention-id SLACK_USER_ID] \ | ||
| # [--output PATH] | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| CHANNEL_ID="" | ||
| BASE_BRANCH="" | ||
| HEAD_REF="" | ||
| HEAD_SHA="" | ||
| PR_NUMBER="0" | ||
| IS_PR="false" | ||
| REPO="" | ||
| RUN_ID="" | ||
| FAILED_STAGES="" | ||
| MENTION_ID="" | ||
| OUTPUT="" | ||
|
|
||
| # Guard so a missing flag value gives a clear error under `set -u` instead of | ||
| # the opaque "unbound variable" message when we try to read $2. | ||
| require_value() { | ||
| if [ $# -lt 2 ]; then | ||
| echo "Error: $1 requires a value" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --channel-id) require_value "$@"; CHANNEL_ID="$2"; shift 2 ;; | ||
| --base-branch) require_value "$@"; BASE_BRANCH="$2"; shift 2 ;; | ||
| --head-ref) require_value "$@"; HEAD_REF="$2"; shift 2 ;; | ||
| --head-sha) require_value "$@"; HEAD_SHA="$2"; shift 2 ;; | ||
| --pr-number) require_value "$@"; PR_NUMBER="$2"; shift 2 ;; | ||
| --is-pr) require_value "$@"; IS_PR="$2"; shift 2 ;; | ||
| --repo) require_value "$@"; REPO="$2"; shift 2 ;; | ||
| --run-id) require_value "$@"; RUN_ID="$2"; shift 2 ;; | ||
| --failed-stages) require_value "$@"; FAILED_STAGES="$2"; shift 2 ;; | ||
| --mention-id) require_value "$@"; MENTION_ID="$2"; shift 2 ;; | ||
| --output) require_value "$@"; OUTPUT="$2"; shift 2 ;; | ||
| *) echo "Error: Unknown option: $1" >&2; exit 1 ;; | ||
| esac | ||
| done | ||
|
|
||
| for var in CHANNEL_ID BASE_BRANCH HEAD_REF HEAD_SHA REPO RUN_ID FAILED_STAGES; do | ||
| if [ -z "${!var}" ]; then | ||
| # Render the var name back into the actual CLI flag (lowercase + _→-) | ||
| flag="--${var,,}" | ||
| flag="${flag//_/-}" | ||
| echo "Error: $flag is required" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| SHORT_SHA="${HEAD_SHA:0:12}" | ||
| RUN_URL="https://github.com/$REPO/actions/runs/$RUN_ID" | ||
| COMMIT_URL="https://github.com/$REPO/commit/$HEAD_SHA" | ||
|
|
||
| MENTION="" | ||
| if [ -n "$MENTION_ID" ]; then | ||
| MENTION="<@${MENTION_ID}> " | ||
| fi | ||
|
|
||
| PR_LINE="" | ||
| if [ "$IS_PR" = "true" ] && [ "$PR_NUMBER" != "0" ]; then | ||
| PR_LINE=$'\n'"*PR:* <https://github.com/$REPO/pull/$PR_NUMBER|#$PR_NUMBER>" | ||
| fi | ||
|
|
||
| MESSAGE=$( | ||
| printf '%s:x: *kernelCI failed on `%s`*\n' "$MENTION" "$BASE_BRANCH" | ||
| printf '*Branch:* `%s`\n' "$HEAD_REF" | ||
| printf '*Commit:* <%s|%s>' "$COMMIT_URL" "$SHORT_SHA" | ||
| printf '%s\n' "$PR_LINE" | ||
| printf '*Failed stages:* %s\n' "$FAILED_STAGES" | ||
| printf '*Run:* <%s|view logs>' "$RUN_URL" | ||
| ) | ||
|
|
||
| # Build chat.postMessage payload: channel + text. mrkdwn is on by default. | ||
| PAYLOAD=$(jq -n \ | ||
| --arg channel "$CHANNEL_ID" \ | ||
| --arg text "$MESSAGE" \ | ||
| '{channel: $channel, text: $text}') | ||
|
|
||
| if [ -n "$OUTPUT" ]; then | ||
| printf '%s\n' "$PAYLOAD" > "$OUTPUT" | ||
| echo "Payload written to $OUTPUT" >&2 | ||
| else | ||
| printf '%s\n' "$PAYLOAD" | ||
| fi |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.