name: Notify CI failures

on:
  workflow_run:
    workflows: ["CI", "Docker Images"]
    types: [completed]

jobs:
  telegram:
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    runs-on: [self-hosted, linux]
    steps:
      - name: Ping Telegram
        run: |
          curl -sS -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
            --data-urlencode "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
            --data-urlencode "text=CI FAILED: ${{ github.event.workflow_run.name }} on ${{ github.event.workflow_run.head_branch }} (${GITHUB_SHA:0:7}). https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" \
            > /dev/null
