Skip to content

Update push-trigger.yml #27

Update push-trigger.yml

Update push-trigger.yml #27

Workflow file for this run

name: Slack Notification on Pull Request
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- master
- 1.*
- develop
- release*
- MOSIP*
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get PR author
id: author
run: echo "author=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Decode Slack Users Secret
id: slack_id
run: |
# Decode the JSON string from the secret
SLACK_USERS_MAP="${{ secrets.SLACK_USERS_MAP }}"
# Use jq to extract the Slack ID corresponding to the GitHub username
SLACK_USER_ID=$(echo "$SLACK_USERS_MAP" | jq -r --arg github_user "${{ env.author }}" '.[$github_user]')
if [ -z "$SLACK_USER_ID" ] || [ "$SLACK_USER_ID" == "null" ]; then
echo "Slack user ID not found for GitHub user: ${{ env.author }}"
exit 1
fi
echo "SLACK_USER_ID=$SLACK_USER_ID" >> $GITHUB_ENV
- name: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ env.SLACK_USER_ID }}
slack-message: |
*GitHub Action Notification* :rocket:
*Repository*: ${{ github.repository }}
*Message*: ${{ github.event.head_commit.message || github.event.pull_request.title }}
*Commit*: ${{ github.sha }}
*Author*: ${{ github.event.pull_request.user.login }}
*Action*: ${{ github.event.action }}
*Event Name*: ${{ github.event_name }}
*Branch (ref)*: ${{ github.ref }}
*Workflow*: ${{ github.workflow }}
*PR/Commit URL*: ${{ github.event.pull_request.html_url || github.event.head_commit.url }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}