A GitHub action that posts a message to Slack using the Block format
A GitHub action that posts a message to Slack using the Block format.
If both block-json
and block-json-file
are set block-json
will take priority.
GitHub Action Contexts can be used in message
and block-json
.
token
: (Required) A Slack API tokenchannel
: (Required) The channel to post the message inmessage
: (Required) A text string for the message bodyblock-json
: (Optional) A JSON string containing an array of structured Slack blocks
blocks
argument to the Slack chat.postMessage
API
block-json-file
: (Optional) A file containing a JSON-based array of structured Slack blocks
blocks
argument to the Slack chat.postMessage
API
name: Example Slack Message Workflow
on:
release:
types: [published]
jobs:
slack_message:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Post a message to Slack on release
uses: ataylorme/slack-post-message-action@master
with:
token: "${{ secrets.SLACK_TOKEN }}"
channel: "#github-action-test"
message: "Hello from ${{ github.ref }} of ${{ github.repository }}"
block-json: |
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A new release `${{ github.ref }}` for `${{ github.repository }}` was published by ${{ github.actor }}!"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View on GitHub"
},
"url": "https://github.com/${{ github.repository }}/releases/tag/${{ github.ref }}"
}
}
]
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A new release `1.0.0` for `ataylorme/slack-post-message-action` was published by `ataylorme`!"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "GitHub Tag: `1.0.0`"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View on GitHub"
},
"url": "https://github.com/ataylorme/slack-post-message-action/releases/tag/1.0.0"
}
}
]