Skip to content

Commit

Permalink
Revise Slack message (#10)
Browse files Browse the repository at this point in the history
* Revise Slack message

* Fix

* Update README.md
  • Loading branch information
int128 authored Jan 27, 2024
1 parent ac686c0 commit 7b1410e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 38 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ This is an action to notify a status of GitHub Actions to a Slack channel.

## Example

<img width="443" alt="image" src="https://github.com/quipper/slack-notification-action/assets/321266/9a5eb834-db70-4091-ac04-414163022bb7">
<img width="450" alt="image" src="https://github.com/quipper/slack-notification-action/assets/321266/7604b25a-9aae-40c3-aef6-354b4657ec5a">

<!--
{
"blocks": [
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Check the workflow failure of <https://github.com/octocat/example|backend / test>"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "@octocat check the failure\n```\nProcess completed with exit code 1.\n```"
"text": "```\nProcess completed with exit code 1.\n```"
}
},
{
Expand All @@ -29,7 +38,7 @@ This is an action to notify a status of GitHub Actions to a Slack channel.
},
{
"type": "mrkdwn",
"text": "workflow: <https://github.com|api / test>"
"text": "@octocat"
}
]
}
Expand Down
83 changes: 48 additions & 35 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ name: slack-notification-action
description: notify the current workflow run to a Slack channel

inputs:
context-header:
description: Header of the message
required: true
default: |-
Check the workflow ${{ github.event.workflow_run.conclusion }} of <${{ github.event.workflow_run.html_url }}|${{ github.event.workflow_run.name }}>
context-mention:
description: Mention in the message
required: true
default: |-
@${{ github.actor }}
slack-channel-id:
description: ID of the Slack channel
required: true
Expand Down Expand Up @@ -35,52 +45,55 @@ runs:
- uses: actions/github-script@v6
id: payload
env:
bodyHeader: |-
@${{ github.actor }} check the ${{ github.event.workflow_run.conclusion }}
bodyMessage: |-
contextHeader: ${{ inputs.context-header }}
contextMention: ${{ inputs.context-mention }}
failureMessage: |-
${{ steps.summary.outputs.annotation-failure-messages }}
contextBranch: |-
${{ github.repository }}/*${{ github.event.workflow_run.head_branch }}*
contextPullRequest: |-
<${{ steps.summary.outputs.pull-request-url }}|#${{ steps.summary.outputs.pull-request-number }}>
contextWorkflow: |-
workflow: <${{ github.event.workflow_run.html_url }}|${{ github.event.workflow_run.name }}>
with:
# preview on https://app.slack.com/block-kit-builder
script: |
return {
blocks: [
const blocks = [
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": process.env.contextHeader
},
],
},
]
if (process.env.failureMessage) {
blocks.push({
"type": "section",
"text": {
"type": "mrkdwn",
"text": ['```', process.env.failureMessage, '```'].join('\n')
}
})
}
blocks.push({
"type": "context",
"elements": [
{
type: "section",
text: {
type: "mrkdwn",
text: (() => {
if (process.env.bodyMessage) {
return [process.env.bodyHeader, '```', process.env.bodyMessage, '```'].join('\n')
}
return process.env.bodyHeader
})()
}
"type": "mrkdwn",
"text": process.env.contextBranch
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": process.env.contextBranch
},
{
"type": "mrkdwn",
"text": process.env.contextPullRequest
},
{
"type": "mrkdwn",
"text": process.env.contextWorkflow
}
]
}
]
}
"type": "mrkdwn",
"text": process.env.contextPullRequest
},
{
"type": "mrkdwn",
"text": process.env.contextMention
},
],
})
return { blocks }
# Don't notify if conclusion is cancelled or skipped.
# Skip if Slack App token is not set such as test workflow.
Expand Down

0 comments on commit 7b1410e

Please sign in to comment.