Github action – Slack notification

Here is good one package to use

https://github.com/slackapi/slack-github-action

And here is my implement

      - name: Slack Notification
        id: slack
        uses: slackapi/[email protected]
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
        with:
          # Slack channel id, channel name, or user id to post message.
          # See also: https://api.slack.com/methods/chat.postMessage#channels
          # You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs.
          channel-id: 'xcrawler-github'

          # This data can be any valid JSON from a previous step in the GitHub Action
          # For posting a rich message using Block Kit
          payload: |
            {
              "attachments": [
                {
                  "blocks": [
                    {
                      "type": "header",
                      "text": {
                        "type": "plain_text",
                        "text": "Github Action",
                        "emoji": true
                      }
                    },
                    {
                      "type": "section",
                      "fields": [
                        {
                          "type": "mrkdwn",
                          "text": "*Name:*\n ${{ github.event_name }} "
                        },
                        {
                          "type": "mrkdwn",
                          "text": "*Type:*\n ${{ github.event.action }} ${{ github.event.ref_type }} ${{ github.event.ref }}"
                        }
                      ]
                    },
                    {
                      "type": "section",
                      "fields": [
                        {
                          "type": "mrkdwn",
                          "text": "*Branch:*\n ${{ github.event.pull_request.head.ref }}"
                        },
                        {
                          "type": "mrkdwn",
                          "text": "*Status:*\n `${{ job.status }}`"
                        }
                      ]
                    },
                    {
                      "type": "context",
                      "elements": [
                        {
                          "type": "mrkdwn",
                          "text": "${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
                        }
                      ]
                    }
                  ]
                }
              ]
            }

Leave a Reply

Your email address will not be published. Required fields are marked *