From c1f2eb052cf4ffdb07c9a0cb6e20c0a94d31d8b0 Mon Sep 17 00:00:00 2001 From: Kevin Meinhardt Date: Fri, 14 Feb 2025 14:27:00 +0100 Subject: [PATCH] slack message (#15362) --- .github/actions/slack/action.yml | 39 ++++++++++++++++++++++++++++++++ .github/workflows/push.yml | 27 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/actions/slack/action.yml create mode 100644 .github/workflows/push.yml diff --git a/.github/actions/slack/action.yml b/.github/actions/slack/action.yml new file mode 100644 index 0000000..8a6ecba --- /dev/null +++ b/.github/actions/slack/action.yml @@ -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 }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..71f6e29 --- /dev/null +++ b/.github/workflows/push.yml @@ -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 }}