-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
36855bf
commit 6f5a1d9
Showing
8 changed files
with
117 additions
and
2 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 @@ | ||
# Slack Notify |
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,11 @@ | ||
--- | ||
name: 'Notify Slack Publish Status' | ||
description: 'Notify Slack with the completion status of the publish action' | ||
inputs: | ||
message: | ||
description: 'Message to send to Slack' | ||
required: true | ||
default: '' | ||
runs: | ||
using: 'node20' | ||
main: 'index.js' |
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,52 @@ | ||
const core = require('@actions/core'); | ||
const webhook = process.env.SDK_PUBLISH_SLACK_WEBHOOK; | ||
|
||
const run = async () => { | ||
if (webhook) { | ||
try { | ||
await postSlackNotification(); | ||
} catch (e) { | ||
console.log(e); | ||
throw new Error(`failed because : ${e}`) | ||
} | ||
} else { | ||
throw new Error('No SDK_PUBLISH_SLACK_WEBHOOK environment variable found'); | ||
} | ||
} | ||
|
||
const postSlackNotification = async () => { | ||
const message = core.getInput('message'); | ||
|
||
if (!message) { | ||
throw new Error('No message input found'); | ||
} | ||
|
||
const options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
text: message, | ||
blocks: [ | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: message, | ||
} | ||
} | ||
] | ||
}), | ||
}; | ||
|
||
const response = await fetch(webhook, options); | ||
|
||
if (response.status == 200) { | ||
console.log('Posted message to Slack successfully'); | ||
} else { | ||
throw new Error(`Failed to post message to Slack. Status code: ${response.status}`); | ||
} | ||
} | ||
|
||
run(); |
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
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
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
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
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