-
Notifications
You must be signed in to change notification settings - Fork 4
Failure notification on the daily sync and add persist-credentials: false and a permissions. #74
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
whisper67265
wants to merge
5
commits into
cppalliance:master
Choose a base branch
from
whisper67265:feature/sync-failure-slack-alerts
base: master
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
562ac42
failure notification on the daily sync
whisper67265 2de973d
add persist-credentials: false and a permissions: block to add-submod…
whisper67265 3aa8a53
fix the coderabbitai review comments
whisper67265 09f8237
fix the coderabbitai review comments
whisper67265 3a52790
fix the first reviewer comments
whisper67265 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
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,104 @@ | ||
| # shellcheck shell=bash | ||
| # Slack failure notifications for sync-translation and heartbeat workflows. | ||
| # Source env.sh before notify.sh when using workflow globals (e.g. HEARTBEAT_MAX_AGE_HOURS). | ||
|
|
||
| resolve_run_id() { | ||
| echo "${1:-${GITHUB_RUN_ID:-}}" | ||
| } | ||
|
|
||
| github_actions_url() { | ||
| local path="$1" | ||
| echo "${GITHUB_SERVER_URL:-https://github.com}/${GITHUB_REPOSITORY}/actions/${path}" | ||
| } | ||
|
|
||
| # Return workflow run URL for the given run id (defaults to GITHUB_RUN_ID). | ||
| workflow_run_url() { | ||
| local run_id | ||
| run_id="$(resolve_run_id "$1")" | ||
| github_actions_url "runs/${run_id}" | ||
| } | ||
|
|
||
| # Extract matrix lang from a sync-local job name, e.g. "sync-local (zh_Hans)" → zh_Hans. | ||
| # Prints nothing for non-matrix job names (e.g. discover). | ||
| extract_sync_local_lang_from_job_name() { | ||
| local job_name="$1" | ||
| local lang | ||
| lang="$(sed -n 's/.*sync-local[[:space:]]*(\([^)]*\)).*/\1/p' <<<"$job_name")" | ||
| if [[ -n "$lang" && "$lang" != "$job_name" ]]; then | ||
| echo "$lang" | ||
| fi | ||
| } | ||
|
|
||
| # Read gh api /actions/runs/.../jobs JSON from stdin; emit human-readable failed-job lines. | ||
| format_failed_jobs_summary() { | ||
| jq -r ' | ||
| (if type == "object" and has("jobs") then .jobs else . end) | ||
| | .[] | ||
| | select(.conclusion == "failure") | ||
| | select(.name | test("notify-failure") | not) | ||
| | .name as $name | ||
| | ($name | if test("sync-local \\(") | ||
| then (capture("sync-local \\((?<lang>[^)]+)\\)") | .lang // "") | ||
| else "" end) as $lang | ||
| | if ($lang | length) > 0 then " • \($name) — lang=\($lang)" | ||
| else " • \($name)" end | ||
| ' | ||
| } | ||
|
|
||
| # Build a Slack incoming-webhook JSON payload. Args: title run_url summary_lines detail (optional). | ||
| build_slack_failure_payload() { | ||
| local title="$1" run_url="$2" summary="$3" detail="${4:-}" | ||
| local text="${title}"$'\n'"Run: ${run_url}" | ||
| if [[ -n "$summary" ]]; then | ||
| text+=$'\n'"Failed jobs:"$'\n'"${summary}" | ||
| fi | ||
| if [[ -n "$detail" ]]; then | ||
| text+=$'\n'"${detail}" | ||
| fi | ||
| jq -n --arg text "$text" '{text: $text}' | ||
| } | ||
|
|
||
| # POST JSON payload to SLACK_WEBHOOK_URL. | ||
| send_slack_notification() { | ||
| local payload="$1" | ||
| if [[ -z "${SLACK_WEBHOOK_URL:-}" ]]; then | ||
| echo "error: SLACK_WEBHOOK_URL secret is not set." >&2 | ||
| return 1 | ||
| fi | ||
| curl -fsS --connect-timeout 10 --max-time 30 \ | ||
| -X POST -H 'Content-Type: application/json' --data "$payload" "$SLACK_WEBHOOK_URL" | ||
| } | ||
|
|
||
| # Fetch failed jobs for a workflow run and format summary lines. | ||
| collect_workflow_failed_jobs_summary() { | ||
| local run_id | ||
| run_id="$(resolve_run_id "$1")" | ||
| gh run view "$run_id" --repo "$GITHUB_REPOSITORY" --json jobs \ | ||
| | format_failed_jobs_summary | ||
| } | ||
|
|
||
| # Notify Slack about sync-translation workflow failures (discover or sync-local). | ||
| notify_sync_translation_failure() { | ||
| local run_id | ||
| run_id="$(resolve_run_id "$1")" | ||
| local run_url summary payload | ||
| run_url="$(workflow_run_url "$run_id")" | ||
| summary="$(collect_workflow_failed_jobs_summary "$run_id")" | ||
| payload="$(build_slack_failure_payload "Sync translation failed" "$run_url" "$summary" "")" | ||
| send_slack_notification "$payload" | ||
| } | ||
|
|
||
| # Notify Slack when the daily sync heartbeat is stale. | ||
| notify_heartbeat_stale() { | ||
| local last_ts="$1" | ||
| local run_url workflow_url detail payload | ||
| local last_desc="${last_ts:-none on record}" | ||
|
|
||
| run_url="$(workflow_run_url)" | ||
| workflow_url="$(github_actions_url "workflows/sync-translation.yml")" | ||
| detail="Daily sync heartbeat: last successful scheduled run is stale (last=${last_desc}, threshold=${HEARTBEAT_MAX_AGE_HOURS}h). The scheduled sync may have stopped." | ||
| detail+=$'\n'"Workflow: ${workflow_url}" | ||
|
|
||
| payload="$(build_slack_failure_payload "Sync heartbeat alert" "$run_url" "" "$detail")" | ||
| send_slack_notification "$payload" | ||
| } | ||
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.