This is a Heroku Buildpack you can add to your Heroku deployments that will notify a Slack channel every time your application is deployed.
- Visit https://api.slack.com/incoming-webhooks to create a new Slack Application that can receive a webook. You only need the "Incomming Webhooks" feature.
- As part of the configuration, you will choose a workspace and channel to connect the application to.
- Take note of the webook URL, which looks something like this
https://hooks.slack.com/services/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S
- Feel free to configure the app's icon and name!
- Enable Dyno Metadata for your application
heroku labs:enable runtime-dyno-metadata
- Save your new webook URL as a Heroku config setting for the variable
SLACK_DEPLOYMENT_WEBHOOK_URL
, i.e.:heroku config:set SLACK_DEPLOYMENT_WEBHOOK_URL="https://hooks.slack.com/services/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S"
- Add this buildpack:
heroku buildpacks:set https://github.com/evantahler/heroku-buildpack-notify-slack-deploy.git
(or add it via the Heroku dashboard if you have multiple buildpacks)
By default, there's very little information about the commit that we can get from Heroku. However, we can curl the Github API and try to learn more about the commit. If you set the following additional environment variables, we can load the commit information, committer, and URL from Github:
DEPLOY_NOTIFY_GITHUB_AUTH_TOKEN
: A Github PAT Token. You can generate one here Important note: you must grant repo access when creating this PAT Token, or else it will default to "Public Access" and won't work!DEPLOY_NOTIFY_GITHUB_ORG
: The name of your Github Org (or Github User Name)DEPLOY_NOTIFY_GITHUB_PROJECT
: The name of your Github Project (i.e. repository name)
Now, the message in Slack can look like:
*my-heroku-app* was deployed - Deploy 04a2729b
> Evan Tahler - [email protected]
> Fix all the bugs and make everything great
https://github.com/COMPANY/PROJECT/commit/abc123