Skip to content

Commit

Permalink
Add slack notification
Browse files Browse the repository at this point in the history
  • Loading branch information
saenom committed Feb 13, 2024
1 parent f3ad52f commit 0f9792d
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/slack_notification.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0f9792d

Please sign in to comment.