From 0f9792d948b3c092b661dbcff270ed0dcabc505b Mon Sep 17 00:00:00 2001 From: Nickolay Loshkarev Date: Tue, 13 Feb 2024 13:15:05 +0400 Subject: [PATCH] Add slack notification --- .github/workflows/slack_notification.yml | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/slack_notification.yml diff --git a/.github/workflows/slack_notification.yml b/.github/workflows/slack_notification.yml new file mode 100644 index 0000000000..cdca0f4fb8 --- /dev/null +++ b/.github/workflows/slack_notification.yml @@ -0,0 +1,50 @@ +name: Check for tests or deployment results +on: + workflow_run: + workflows: ["CI","Dev deployment","Staging deployment","Production deployment"] + types: [completed] + +jobs: + notify-slack: + runs-on: ubuntu-latest + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + steps: + - name: Extract Slack ID for author + id: extract_slack_id + run: | + #!/bin/bash + # user_string="johndoe:U12345678, janedoe:U87654321, alice:U98765432" + user_string="${{ vars.SLACK_USER_IDS }}" + suid="" + + IFS=", " read -r -a users <<< "$user_string" + for user in "${users[@]}"; do + IFS=':' read -r github_username slack_user_id <<< "$user" + if [ "$github_username" == "${{github.actor}}" ]; then + suid="$slack_user_id" + break + fi + done + + echo "::set-output name=suid::$suid" + - name: tests + uses: ravsamhq/notify-slack-action@v2 + if: ${{ github.event.workflow_run.head_branch != 'main' && github.event.workflow_run.head_branch != 'staging' && github.event.workflow_run.head_branch != 'production' }} + with: + status: ${{ github.event.workflow_run.conclusion }} + notification_title: "Tests ${{github.event.workflow_run.conclusion}} on *${{github.event.workflow_run.head_branch}}* - <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View ${{github.event.workflow_run.conclusion}}>" + message_format: "{emoji} *${{github.event.workflow_run.name}}* ${{github.event.workflow_run.conclusion}} in <{repo_url}|{repo}>" + footer: "Linked Repo <${{github.server_url}}/${{github.repository}}|${{github.repository}}> | <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View ${{github.event.workflow_run.conclusion}}>" + mention_users: ${{ steps.extract_slack_id.outputs.suid }} + mention_users_when: "failure,warnings" + - name: deployment + uses: ravsamhq/notify-slack-action@v2 + if: ${{ github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'staging' || github.event.workflow_run.head_branch == 'production' }} + with: + status: ${{ github.event.workflow_run.conclusion }} + notification_title: "Deployment ${{github.event.workflow_run.conclusion}} on *${{github.event.workflow_run.head_branch}}* - <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View ${{github.event.workflow_run.conclusion}}>" + message_format: "{emoji} *${{github.event.workflow_run.name}}* ${{github.event.workflow_run.conclusion}} in <{repo_url}|{repo}>" + footer: "Linked Repo <${{github.server_url}}/${{github.repository}}|${{github.repository}}> | <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View ${{github.event.workflow_run.conclusion}}>" + mention_users: ${{ steps.extract_slack_id.outputs.suid }} + mention_users_when: "failure,warnings"