Skip to content

Commit

Permalink
slack message (#15362)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind authored Feb 14, 2025
1 parent a9dcc71 commit c1f2eb0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/actions/slack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'Send Slack Message'
description: 'Sends a message to a specified Slack channel'

inputs:
slack_token:
description: 'Slack Bot User OAuth Token'
required: true
message:
description: 'Message to send to Slack'
required: true
channel_id:
description: 'Slack Channel ID to send message to'
required: true

runs:
using: 'composite'

steps:
- name: Post formatted message to Slack channel
uses: slackapi/slack-github-action@v2.0.0
env:
workflow_run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
errors: true
method: chat.postMessage
token: ${{ inputs.slack_token }}
payload: |
channel: ${{ inputs.channel_id }}
blocks:
- type: context
elements:
- type: mrkdwn
text: ":github: *Workflow Run:* ${{ env.workflow_run }}"
- type: mrkdwn
text: ":bust_in_silhouette: *Triggered by:* @${{ github.actor }}"
- type: section
text:
type: mrkdwn
text: ${{ inputs.message }}
27 changes: 27 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test Actions on Push

on:
push:
workflow_dispatch:
inputs:
message:
description: 'Message to send to Slack'
required: true
default: 'Hello, world!'
channel_id:
description: 'Slack Channel ID to send message to'
required: true

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Send Slack Message
uses: ./.github/actions/slack
with:
slack_token: ${{ secrets.SLACK_BOT_TOKEN }}
message: ${{ inputs.message || 'Hello, world!' }}
channel_id: ${{ inputs.channel_id || secrets.SLACK_DEFAULT_CHANNEL_ID }}

0 comments on commit c1f2eb0

Please sign in to comment.