-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft: workflow to post release notes to slack
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/&/\&/g;s/</\</g;s/>/\>/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 }} |