Skip to content

Commit

Permalink
ft: workflow to post release notes to slack
Browse files Browse the repository at this point in the history
  • Loading branch information
NgoKimPhu committed Jan 16, 2025
1 parent b4db056 commit 8a914b3
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/post-to-slack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: 'Post messages to Slack'

# Must use secrets: inherit

# Check that your service repo is private if this service-framework repo is also private
# Sample concurrency config:
# concurrency:
# group: ci-workflow-${{ github.ref }}-${{ github.event_name }}
# cancel-in-progress: true

on:
workflow_call:
inputs:
channel_id:
description: 'Channel ID where the release notes will be posted'
type: string
required: true
title:
description: 'Title of the message'
type: string
required: true
body:
description: 'Body of the message'
type: string
required: true
runs-on:
description: 'Type of machine to run the job on'
type: string
default: ${{ github.event.repository.private && 'self-hosted' || 'ubuntu-latest' }}

jobs:
prepare:
runs-on: ${{ inputs.runs-on }}
env:
title: ${{ inputs.title }}
body: ${{ inputs.body }}
steps:
- run: |
for env_var in title body; do
echo "$env_var=$(<<<"${!env_var}" sed -E '
s/^\* /• / # bullet point
s/## (.+)/*\1*\n/ # heading
s/\*\*(.+?)\*\*/_\1_/g # emphasis
s/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g # escape
s,https://.+?/(pull/[0-9]+|[^/ ]+\.\.\.[^/ ]+),<&|\1>,g # shorten GitHub links
1h;1!H;$!d;x;s/\n/\\n/g # escape newlines')" >> "$GITHUB_ENV"
done
post_to_slack:
runs-on: ${{ inputs.runs-on }}
steps:
- uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ inputs.channel_id }}
text: ${{ env.title }}
blocks:
- type: section
text:
type: mrkdwn
text: {{ env.title }}
- type: divider
- type: section
text:
type: mrkdwn
text: {{ env.body }}

0 comments on commit 8a914b3

Please sign in to comment.