Skip to content

Commit 56c3ae8

Browse files
[release] notify release status via slack (#79409)
This PR adds a step to send Slack notifications of the status of the release. --------- Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
1 parent d8be11a commit 56c3ae8

File tree

4 files changed

+114
-1
lines changed

4 files changed

+114
-1
lines changed

.github/workflows/build_and_deploy.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,15 @@ jobs:
618618
if: steps.changesets.outputs.pullRequestNumber
619619
run: 'gh pr edit ${{ steps.changesets.outputs.pullRequestNumber }} --add-label "created-by: CI"'
620620
env:
621-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
621+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }
622+
623+
- name: Send a Slack notification of the publish status
624+
run: pnpm tsx scripts/release/slack.ts
625+
env:
626+
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
627+
RELEASE_STATUS: ${{ steps.changesets.outputs.published }}
628+
WORKFLOW_LINK: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
629+
WORKFLOW_ACTOR: ${{ github.actor }}
622630

623631
- name: Upload npm log artifact
624632
if: steps.changesets.outputs.published == 'true'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"@picocss/pico": "1.5.10",
119119
"@rspack/core": "1.3.9",
120120
"@rspack/plugin-react-refresh": "1.2.0",
121+
"@slack/web-api": "7.9.1",
121122
"@swc/cli": "0.1.55",
122123
"@swc/core": "1.11.24",
123124
"@swc/helpers": "0.5.15",

pnpm-lock.yaml

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/release/slack.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { WebClient } from '@slack/web-api'
2+
3+
async function slack() {
4+
if (!process.env.SLACK_TOKEN) {
5+
throw new Error('SLACK_TOKEN not set')
6+
}
7+
8+
const workflowLink = process.env.WORKFLOW_LINK
9+
if (!workflowLink) {
10+
throw new Error('WORKFLOW_LINK not set')
11+
}
12+
13+
const channel = process.env.SLACK_CHANNEL_ID ?? 'C0668R2391V' // #next-releases
14+
// TODO: Configure SLACK_ envs for dry run testing to not ping the oncall.
15+
// TODO: It'll become `@oncall-nextjs`
16+
const ping = process.env.SLACK_PING ?? '@nextjs-oncall'
17+
18+
const message =
19+
process.env.SLACK_MESSAGE ?? process.env.RELEASE_STATUS === 'true'
20+
? `Successfully published a new release!\n<https://github.com/vercel/next.js/releases|Releases Link>`
21+
: `Failed to publish a new release triggered by "${process.env.WORKFLOW_ACTOR}". ${ping}\n<${workflowLink}|Workflow Link>`
22+
23+
const slackClient = new WebClient(process.env.SLACK_TOKEN)
24+
const res = await slackClient.chat.postMessage({
25+
channel,
26+
text: message,
27+
username: 'Next.js Bot',
28+
icon_emoji: ':nextjs:',
29+
})
30+
31+
if (!res.ok) {
32+
throw new Error(
33+
`Failed to send message "${message}" to Slack channel #next-releases: ${res.error}`
34+
)
35+
}
36+
37+
console.log('Successfully sent message to Slack!')
38+
}
39+
40+
slack()

0 commit comments

Comments
 (0)