Skip to content

Commit

Permalink
WIP: notify about release PR
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin committed Sep 5, 2023
1 parent 4904613 commit 8f8dea3
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
- release
- ci-run/pr-*
pull_request:
# pull_request:

defaults:
run:
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/release-notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# This workflow notifies Slack channel about upcoming releases.

name: Notify Slack channel about upcoming release

on:
pull_request:
# branches:
# - release

jobs:
notify:
runs-on: [ ubuntu-latest ]

steps:
- uses: actions/github-script@v6
id: commitlist
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
retries: 5
result-encoding: string
script: |
// Slack Message layout is created with https://app.slack.com/block-kit-builder
const linkify = function (text) {
return text.replace(/#(\d+)/g, (match, prNumber) => { return `<${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/pulls/${prNumber}|#${prNumber}>` })
}
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
// pull_number: context.payload.number,
// Try real release PR
pull_number: 5202
});
const header = `"${pullRequest.title}" is coming :tada:`
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
// pull_number: context.payload.number,
// Try real release PR
pull_number: 5202
});
const blocks = []
blocks.push({
type: "header",
text: {
type: "plain_text",
text: header,
},
})
blocks.push({
type: "context",
elements: [
{
type: "mrkdwn",
text: `<${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/pulls/${context.payload.number}|Release PR>`,
},
],
})
for (const commit of commits) {
const message = commit.commit.message.replace(/\r\n/g, "\n")
const title = message.split("\n\n", 1)[0]
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text: `- ${linkify(title)}`,
},
})
}
const slackMessage = {
text: header,
blocks,
}
console.log(JSON.stringify(slackMessage, null, 2))
return JSON.stringify(slackMessage)
- uses: slackapi/slack-github-action@v1
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: "C05QQ9J1BRC" # #test-release-notifications
payload: ${{ steps.commitlist.outputs.result }}

0 comments on commit 8f8dea3

Please sign in to comment.