Post GitHub Action deploy workflow progress notifications to Slack.
- Posts summary message at beginning of the deploy workflow, surfacing commit message and author
- Maps GitHub actor to Slack user by full name or mapping, mentioning them in the summary message
- Threads intermediate stage completions, sending unexpected failures back to the channel
- Adds summary message reaction to unsuccessful jobs (useful with Reacji Channeler)
- Updates summary message with workflow duration at its conclusion
- Supports
pull_request,push,release,schedule, andworkflow_dispatchevent types
- Create a Slack App for your workspace
- Under OAuth & Permissions, add Bot Token Scopes:
chat:writeto post messageschat:write.customizeto customize messages with GitHub actorreactions:writeto add summary message error reactionsusers:readto map GitHub user to Slack user
- Install the app to your workspace
- Copy the app's Bot User OAuth Token from the OAuth & Permissions page
- Create a GitHub secret with this token, named
SLACK_DEPLOY_BOT_TOKEN - Invite the bot user into the Slack channel you will post messages to (
/invite @bot_user_name) - Click the Slack channel name in the header, and copy its Channel ID from the bottom of the dialog
name: Deploy
on:
push:
branches:
- main
# 1. Configure environment variables
env:
SLACK_DEPLOY_BOT_TOKEN: ${{ secrets.SLACK_DEPLOY_BOT_TOKEN }} # required
SLACK_DEPLOY_CHANNEL: 'C040YVCUDRR' # required - replace with your Slack Channel ID
SLACK_DEPLOY_ERROR_REACTION: 'x' # optional emoji name added as non-successful summary message reaction
jobs:
staging:
runs-on: ubuntu-latest
outputs:
slack_ts: ${{ steps.slack.outputs.ts }}
steps:
# 2. Post summary message at the beginning of your workflow
- name: Post to Slack
uses: Fieldguide/action-slack-deploy-pipeline@v2
id: slack
- name: Deploy to staging
run: sleep 10 # replace with your deploy steps
# 3. Post threaded stage updates throughout
- name: Post to Slack
uses: Fieldguide/action-slack-deploy-pipeline@v2
if: always()
with:
thread_ts: ${{ steps.slack.outputs.ts }}
production:
needs:
- staging
runs-on: ubuntu-latest
steps:
- name: Deploy to production
run: sleep 5 # replace with your deploy steps
# 4. Post last "conclusion" stage
- name: Post to Slack
uses: Fieldguide/action-slack-deploy-pipeline@v2
if: always()
with:
thread_ts: ${{ needs.staging.outputs.slack_ts }}
conclusion: true- Configure required
SLACK_DEPLOY_BOT_TOKENandSLACK_DEPLOY_CHANNELenvironment variables. - Use this action at the beginning of your workflow to post a "Deploying" message in your configured channel.
- As your workflow progresses, use this action with the
thread_tsinput to post threaded replies. - Denote the last step with the
conclusioninput to update the initial message's status.
Global configuration to be used across all Slack Deploy actions within the workflow.
| variable | description |
|---|---|
SLACK_DEPLOY_BOT_TOKEN |
Required Slack bot user OAuth token |
SLACK_DEPLOY_CHANNEL |
Required Slack channel ID |
SLACK_DEPLOY_ERROR_REACTION |
Optional Slack emoji name |
SLACK_DEPLOY_GITHUB_USERS |
Optional mapping of Slack user details by GitHub username in JSON or YAML format |
Optional step-specific input enables threading and denotes the conclusion.
| input | description |
|---|---|
thread_ts |
Initial Slack message timestamp ID |
conclusion |
true denotes last stage |
github_token |
Repository GITHUB_TOKEN or personal access token secret; defaults to github.token |
status |
The current status of the job; defaults to job.status |
| output | description |
|---|---|
ts |
Slack message timestamp ID |
By default, this GitHub Action attempts to mention the Slack user corresponding to the GitHub actor by full name. This process depends on a conservatively rate limited Slack API method; depending on your deploy throughput, it might fail and gracefully fallback to the GitHub username.
To improve reliability, the action can be provided a predefined user mapping via a SLACK_DEPLOY_GITHUB_USERS environment variable. The data should be an object keyed by GitHub username mapped to Slack user detail values in JSON or YAML format.
The data is conventionally JSON generated by the Generate Slack Deploy User Mapping GitHub Action. However, it can also be provided as inline YAML as in the example below:
- uses: Fieldguide/action-slack-deploy-pipeline@v2
env:
SLACK_DEPLOY_GITHUB_USERS: |
namoscato:
slack_user_id: U0411GE5J9J
username: Nick
icon_url: "https://secure.gravatar.com/avatar/d79555502b4c47fc9d31144af55dc3e5.jpg"