Skip to content

Commit

Permalink
Merge pull request #50 from cenevan/main
Browse files Browse the repository at this point in the history
Create Slack Notification GHA workflow
  • Loading branch information
AndyBoWu authored May 22, 2024
2 parents 0a5bf03 + 4f88df4 commit 99081fb
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/reusable-slack-notifs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Reusable workflow to create slack notifications

on:
workflow_call:
inputs:
short-desc:
description: 'Description of the slack messsage'
required: true
type: string
title:
description: 'Title of slack message'
required: true
type: string
img-url:
description: 'url of image in slack message'
required: true
type: string
img-alt-text:
description: 'alt text of image'
required: true
type: string
secrets:
channel-name:
required: true
slack-bot-token:
required: true

jobs:
slack-notif:
runs-on: ubuntu-latest
steps:
- name: Push Slack Notification
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.channel-name }}
payload: |
{
"text": "${{ inputs.short-desc }}",
"blocks": [
{ "type": "divider" },
{
"type": "image",
"title": {
"type": "plain_text",
"text": "${{ inputs.title }}"
},
"image_url": "${{ inputs.img-url }}",
"alt_text": "${{ inputs.img-alt-text }}"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ inputs.short-desc }}"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.slack-bot-token }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
|----------|----------|----------|
| reusable-timestamp.yml | print out timestamp of the workflow | [README](docs/utility/readme-reusable-timestamp.md)
| reusable-lint-go-workflow.yml | lint Go code | [README](docs/utility/readme-reusable-lint-go-workflow.md)
| reusable-slack-notifs.yml | send slack notifications | [README](docs/utility/readme-reusable-slack-notifs.md)

## CI/CD

Expand Down
18 changes: 18 additions & 0 deletions docs/readme-doc-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Workflow Configuration

## Name

Reusable workflow name

## Triggers

Workflow triggers

## Inputs

- Workflow input #1 (type):
- Workflow input #2 (type):

## Secrets

- Secret name #1:
21 changes: 21 additions & 0 deletions docs/utility/readme-reusable-slack-notifs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Workflow Configuration

## Name

Reusable workflow to create slack notifications

## Triggers

The workflow is triggered using workflow_call, allowing it to be reused in other workflows.

## Inputs

- short-desc (string, required): A brief description of the Slack message.
- title (string, required): The title of the Slack message.
- img-url (string, required): URL of the image to be included in the Slack message. Requires downloadable image file (.png, .jpg, etc.)
- img-alt-text (string, required): Alt text for the image.

## Secrets

- channel-name (required): The name of the Slack channel where the message will be sent.
- slack-bot-token (required): The token for the Slack bot to authenticate the API request.

0 comments on commit 99081fb

Please sign in to comment.