Skip to content

Commit

Permalink
Update workflows-notify.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
isboston committed Feb 7, 2025
1 parent 3c12057 commit 3c6bed1
Showing 1 changed file with 64 additions and 22 deletions.
86 changes: 64 additions & 22 deletions .github/workflows/workflows-notify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Workflows notify
on:
schedule:
- cron: "30 6 * * *"
push:
branches:
- feature/workflows-notify

jobs:
check-workflows:
Expand All @@ -11,29 +14,68 @@ jobs:
- name: Notify failed runs
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
REPOSITORIES: "ONLYOFFICE/DocSpace-buildtools,ONLYOFFICE/OneClickInstall-Workspace,ONLYOFFICE/OneClickInstall-Docs"
TELEGRAM_CHAT_ID: 226855156
WORKFLOWS: |
DocSpace-buildtools|build_packages.yml
DocSpace-buildtools|ci-oci-docker-install.yml
DocSpace-buildtools|ci-oci-install.yml
DocSpace-buildtools|oci-release.yml
DocSpace-buildtools|offline-release.yml
OneClickInstall-Workspace|ci.yml
OneClickInstall-Workspace|ci-update.yml
OneClickInstall-Workspace|s3-release.yml
OneClickInstall-Docs|ci-docs-test.yml
OneClickInstall-Docs|ci-update.yml
OneClickInstall-Docs|scripts-upload-s3.yml
run: |
IFS=',' read -ra REPO_LIST <<< "$REPOSITORIES"
for REPO in "${REPO_LIST[@]}"; do
FAILS="$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$REPO/actions/runs?per_page=100" | \
jq --arg start "$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ)" '[.workflow_runs[]
| select(.created_at >= $start and ((.conclusion? // "failure") | test("failure|failed|error|startup_failure")))
| select(.head_branch | test("^(master|release/.+|hotfix/.+|develop)$"))]')"
COUNT="$(jq length <<< "$FAILS")"
if (( COUNT > 0 )); then
LINES="$(jq -r '[.[] |
"\u25FB [\(.name[:29] + (if .name|length>26 then "..." else "" end))](\(.html_url)) (\(.head_branch))"
] | join("\n")' <<< "$FAILS")"
RESULT+="*\u274C $COUNT FAILED | 24h | REPO: $REPO*\n$LINES\n\n"
fi
declare -A WORKFLOW_NAMES=(
["build_packages.yml"]="Build packages"
["ci-oci-docker-install.yml"]="Install OneClickInstall Docker"
["ci-oci-install.yml"]="Install OneClickInstall DocSpace"
["oci-release.yml"]="Upload OneClickInstall scripts on S3"
["offline-release.yml"]="Upload offline self-extracting archive"
["ci.yml"]="Installation test OneClickInstall-Workspace"
["ci-update.yml"]="OneClickTests-Update"
["s3-release.yml"]="Upload scripts on S3"
["ci-docs-test.yml"]="OneClickDocs-Install"
["ci-update.yml"]="OneClickDocs-Update"
["scripts-upload-s3.yml"]="Upload on S3"
)
declare -A REPO_STATUS
declare -A REPO_LIST
while IFS='|' read -r REPO WORKFLOW; do
[[ -z "$REPO" || -z "$WORKFLOW" ]] && continue
FULL_REPO="ONLYOFFICE/$REPO"
REPO_LIST["$REPO"]=1
WORKFLOW_NAME="${WORKFLOW_NAMES[$WORKFLOW]:-$WORKFLOW}"
WORKFLOW_URL="https://github.com/$FULL_REPO/actions/workflows/$WORKFLOW"
RUNS_API_URL="https://api.github.com/repos/$FULL_REPO/actions/workflows/$WORKFLOW/runs?per_page=50"
RUNS_RESPONSE="$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$RUNS_API_URL")"
[[ ! $(echo "$RUNS_RESPONSE" | jq -e .workflow_runs) ]] && continue
RUNS=$(echo "$RUNS_RESPONSE" | jq --arg start "$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ)" \
'[.workflow_runs[]
| select(.created_at >= $start)
| select(.head_branch | test("^(master|release/.+|hotfix/.+|develop)$"))]')
TOTAL_COUNT=$(echo "$RUNS" | jq 'length')
FAIL_COUNT=$(echo "$RUNS" | jq '[.[] | select((.conclusion? // "failure") | test("failure|failed|error|startup_failure"))] | length')
STATUS="\u26AA"
(( TOTAL_COUNT > 0 )) && STATUS=$([[ $FAIL_COUNT -gt 0 ]] && echo "\uD83D\uDD34" || echo "\uD83D\uDFE2")
REPO_STATUS["$REPO"]+="$STATUS [$WORKFLOW_NAME]($WORKFLOW_URL)\n"
done <<< "$WORKFLOWS"
for REPO in "${!REPO_LIST[@]}"; do
[[ -n "${REPO_STATUS[$REPO]}" ]] && RESULT+="*$REPO*\n${REPO_STATUS[$REPO]}\n"
done
if [[ -n "$RESULT" ]]; then
curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": \"${TELEGRAM_CHAT_ID}\", \"text\": \"$RESULT\", \"parse_mode\": \"Markdown\", \"disable_web_page_preview\": true}"
fi
[[ -n "$RESULT" ]] && curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": \"${TELEGRAM_CHAT_ID}\", \"text\": \"$RESULT\", \"parse_mode\": \"Markdown\", \"disable_web_page_preview\": true}"

0 comments on commit 3c6bed1

Please sign in to comment.