Skip to content

Instantly share code, notes, and snippets.

@shamaevnn
Last active February 7, 2022 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamaevnn/86463a304370b8dceeb4bb210d6c50f2 to your computer and use it in GitHub Desktop.
Save shamaevnn/86463a304370b8dceeb4bb210d6c50f2 to your computer and use it in GitHub Desktop.
Example of .yml workflow file for alerting about results of deploy
name: "telegram alert about result of deploy"

on:
  workflow_run:
    workflows: ["deploy"]
    types: [completed]

jobs:
  on-success:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
    - name: Success alert
      env:
        ALERTING_TELEGRAM_TOKEN: ${{ secrets.ALERTING_TELEGRAM_TOKEN }}
        TEXT: "✅ <b>Backend Deployed</b>%0A${{ github.event.workflow_run.head_commit.message }} <i>(${{ github.event.workflow_run.head_branch }})</i>"
        LOG_CHAT_ID: ${{ secrets.TELEGRAM_LOG_CHAT_ID }}
      run: |
        curl -X GET "https://api.telegram.org/bot$ALERTING_TELEGRAM_TOKEN/sendMessage?chat_id=$LOG_CHAT_ID&text=$TEXT"
  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - name: Failure alert
        env:
          ALERTING_TELEGRAM_TOKEN: ${{ secrets.ALERTING_TELEGRAM_TOKEN }}
          TEXT: "🚨🚨🚨 <b>Backend Deployment Failed</b>%0A${{ github.event.workflow_run.head_commit.message }} <i>(${{ github.event.workflow_run.head_branch }})</i>❌"
          LOG_CHAT_ID: ${{ secrets.TELEGRAM_LOG_CHAT_ID }}
        run: |
          curl -X GET "https://api.telegram.org/bot$ALERTING_TELEGRAM_TOKEN/sendMessage?chat_id=$LOG_CHAT_ID&text=$TEXT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment