Skip to content

Commit

Permalink
slack job
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Hlushchenko committed Apr 5, 2024
1 parent cb15565 commit 057d9bc
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/slack_notification.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'Hello World'
description: 'Greet someone'
inputs:
slack_header: # id of input
required: true
default: 'Default Slack Header'
slack_context:
required: true
default: 'Default Slack Context'
slack_id:
required: true
outputs:
random-number:
description: "Random number"
value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
using: "composite"
steps:
- name: Prepare Slack Message
if: ${{ steps.publish.outcome == 'success' && !contains(matrix.package, 'Meta') }}
id: slack-prepare
shell: bash
run: |
channel_id=$(echo "${}" | jq -r .\"${{ github.actor }}\")
echo "::add-mask::$channel_id"
echo SLACK_CHANNEL=$channel_id >> $GITHUB_ENV
header="Package *${{ matrix.package }}* version *${{ matrix.version }}* published to <https://www.npmjs.com/package/$(jq -r .name "packages/${{ matrix.package }}/package.json")/v/${{ matrix.version }}|NPM>"
echo SLACK_MESSAGE_HEADER=$header >> $GITHUB_ENV
context="*GitHub Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }} ${{ github.run_number }}>\n*Commit:* <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|$(echo "${{ github.sha }}" | cut -c1-8) $(echo -e "${{ github.event.head_commit.message }}" | head -n1 | sed -e 's/"/\\"/g')>"
echo SLACK_MESSAGE_CONTEXT=$context >> $GITHUB_ENV
- name: Send to Slack
id: slack
if: steps.slack-prepare.outcome == 'success'
uses: slackapi/[email protected]
with:
channel-id: ${{ env.SLACK_CHANNEL }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ env.SLACK_MESSAGE_HEADER }}"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "${{ env.SLACK_MESSAGE_CONTEXT }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACKBOT_TOKEN }}

0 comments on commit 057d9bc

Please sign in to comment.