Skip to content

Commit

Permalink
Add workflows for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
isboston committed Feb 6, 2025
1 parent 995619e commit 0ab2ae7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/workflows-notify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Workflows notify

on:
schedule:
- cron: "30 6 * * *"

jobs:
check-workflows:
runs-on: ubuntu-latest
steps:
- 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"
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
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

0 comments on commit 0ab2ae7

Please sign in to comment.