In this workshop, we’ll use GitHub Actions to allow you to notify team members in Slack when a GitHub issue requires their attention.
First, we’ll create a new Action that will parse your issues and comments for a special "/cc Slack" string. Then, we’ll combine the Action we created with an existing Action from the GitHub Marketplace that posts messages to Slack. Finally, we’ll verify that our workflow works as intended by creating some test issues and comments.
- Create a new public repository for your GitHub Action.
- Create a
Dockerfile
at the root of the repository. Give it access to JavaScript using thenode:slim
as the base image. Set theENTRYPOINT
to/index.js
. - Create a
package.json
at the root of the repository. Include the dependencies your Action will use. - Create a
index.js
at the root of the repository.require
theactions-toolkit
library to get access to some great helpers for writing an Action in JavaScript. Specify which events you want the Action to respond to, and implement the logic to identify "/cc Slack" in issue bodies and comments and persist message data to the shared workspace.
- Create a new Slack App.
- Find or create a new repository from which you’d like to CC team members in Slack.
- Click the "Actions" tab and then the "Create a new workflow" button to create a new
.github/main.workflow
file. - Create a new workflow triggered by the
issues
event. Add the Action you created above as the first Action in the new workflow. Add theslack-bot-action
as the second action. Using the information from your Slack App, createCONVERSATION_ID
andSLACK_BOT_TOKEN
secrets and expose them to theslack-bot-action
. - Create another workflow triggered by the
issue_comment
event and repeat the previous step.
- Create a new issue with "/cc Slack" in the body. Click the Actions tab to monitor your workflow and view Action logs. Verify that you receive a message in Slack referencing the new issue.
- Comment on the issue with "/cc Slack" in the body. Verify that you receive a message in Slack referencing the new issue.
- Comment on the issue without "/cc Slack" in the body. Verify that you don’t receive any new messages in Slack.