summaryrefslogtreecommitdiffstats
path: root/.github/workflows/telegram_scheduled_notifications.yml
blob: 66b0386a0d9efc92a098cebe9a6808919d5921f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Telegram scheduled notifications

# Scheduled Telegram output: (1) mute-issue digests from YDB digest_queue via send_digest.py,
# (2) stuck GitHub Actions queue alerts via alert_queued_jobs.py. Same cron; separate jobs.

# Digest: new mute issues are written to YDB digest_queue by mute/create_new_muted_ya.py (not sent from mute PR workflows).
# Job send-digest runs send_digest.py which dequeues unsent rows and sends Telegram, then sets sent_at.
# Digest schedule: mute_issue_and_digest_config.json (schedule_utc_hours + schedule_weekdays).
# send_digest.py checks UTC hour and ISO weekday (1=Mon … 7=Sun) — defaults to Mon–Fri if weekdays omitted.

on:
  schedule:
    - cron: '*/30 * * * *'
  workflow_dispatch:
    inputs:
      force:
        description: "Force digest regardless of schedule hour"
        type: boolean
        default: false
      profile:
        description: "Digest: run only this profile ID (leave empty for all active)"
        type: string
        default: ""
      dry_run:
        description: "Print messages without sending"
        type: boolean
        default: false

concurrency:
  group: telegram-scheduled-notifications
  cancel-in-progress: false

jobs:
  check-queued-jobs:
    name: CI queue Telegram alerts
    runs-on: [ self-hosted, auto-provisioned, build-preset-analytic-node]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v5

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: '3.11'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install requests

      - name: Run queued jobs checker and send to Telegram
        env:
          TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_YDBOT_TOKEN }}
          GH_ALERTS_TG_LOGINS: ${{ vars.GH_ALERTS_TG_LOGINS }}
        run: |
          python .github/scripts/telegram/alert_queued_jobs.py \
            --chat-id 3017506311 \
            --send-when-all-good \
            --notify-on-api-errors \
            --blacklist "${{ vars.GH_ALERTS_RUNS_BLACK_LIST }}"

  send-digest:
    name: Mute digest to Telegram
    runs-on: [ self-hosted, auto-provisioned, build-preset-analytic-node]

    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Setup YDB access
        uses: ./.github/actions/setup_ci_ydb_service_account_key_file_credentials
        with:
          ci_ydb_service_account_key_file_credentials: ${{ secrets.CI_YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS }}
          ydb_qa_config: ${{ vars.YDB_QA_CONFIG }}

      - name: Install dependencies
        run: python3 -m pip install "ydb[yc]" requests matplotlib numpy

      - name: Send digest
        env:
          TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_YDBOT_TOKEN }}
          TG_TEAM_CHANNELS: ${{ vars.TG_TEAM_CHANNELS }}
        run: |
          ARGS=""
          if [ "${{ inputs.force }}" = "true" ]; then
            ARGS="$ARGS --force"
          fi
          if [ -n "${{ github.event.inputs.profile }}" ]; then
            ARGS="$ARGS --profile ${{ github.event.inputs.profile }}"
          fi
          if [ "${{ inputs.dry_run }}" = "true" ]; then
            ARGS="$ARGS --dry-run"
          fi
          python3 .github/scripts/telegram/send_digest.py \
            --config .github/config/mute_issue_and_digest_config.json \
            $ARGS