Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVPLAT-2283] Update job-notification action to use blocks and take … #17

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 52 additions & 40 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
channel:
description: The Slack channel name for receiving the notification
required: true
slack-ts:
description: The timestamp of the message to update
required: false
default: ''
status:
description: Customize the notification status to be "success", "failure" or a custom value.
required: false
Expand Down Expand Up @@ -60,52 +64,60 @@ runs:
commit_message="Link to the latest commit in the repository"
message="<https://github.com/${{ inputs.repository }}/commit/${{ github.sha }}|$commit_message>"
fi
echo "message=$message" >> $GITHUB_OUTPUT
sanitized_message=$(echo "$message" | sed "s/'/\\\'/g")
echo "sanitized_message=$sanitized_message" >> $GITHUB_OUTPUT

author=${{ github.event.pusher.name }} # context from `push` trigger
author=${author:-${{ github.event.sender.login }}} # context from `workflow_dispatch` trigger
echo "author=$author" >> $GITHUB_OUTPUT

- name: Send notification
if: always()
uses: slackapi/slack-github-action@v1.25.0
env:
SLACK_BOT_TOKEN: ${{ inputs.token }}
uses: archive/github-actions-slack@v2.9.0
with:
channel-id: ${{ inputs.channel }}
payload: |
{
"text": ":${{ steps.fields.outputs.emoji }}: *Workflow <https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }}/|${{ github.workflow }}> ${{ inputs.status }}*",
"attachments": [
{
"color": "${{ steps.fields.outputs.color }}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we are not using color in the new format?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, color is not supported in block format, it is the one feature that did not carry over https://api.slack.com/messaging/attachments-to-blocks#direct_equivalents

"fields": [
{
"title": "Repository",
"value": "<https://github.com/${{ inputs.repository }}|${{ inputs.repository }}>",
"short": true
},
{
"title": "Environment/Branch",
"value": "${{ inputs.environment || github.ref_name }}",
"short": true
},
{
"title": "Author",
"value": "<https://github.com/${{ steps.fields.outputs.author }}|${{ steps.fields.outputs.author }}>",
"short": true
},
{
"title": "Job",
"value": "${{ github.job }}",
"short": true
},
{
"title": "Commit Message",
"value": ${{ toJSON(steps.fields.outputs.message) }},
"short": false
}
]
slack-channel: ${{ inputs.channel }}
slack-bot-user-oauth-access-token: ${{ inputs.token }}
slack-optional-thread_ts: ${{ inputs.slack-ts }}
slack-blocks: >-
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":${{ steps.fields.outputs.emoji }}: *Workflow <https://github.com/${{ inputs.repository }}/actions/runs/${{ github.run_id }}/|${{ github.workflow }}> ${{ inputs.status }}*"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Repository*\n<https://github.com/${{ inputs.repository }}|${{ inputs.repository }}>"
},
{
"type": "mrkdwn",
"text": "*Environment/Branch*\n${{ inputs.environment || github.ref_name }}"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Author*\n<https://github.com/${{ steps.fields.outputs.author }}|${{ steps.fields.outputs.author }}>"
},
{
"type": "mrkdwn",
"text": "*Job*\n${{ github.job }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": '*Commit Message*\n${{ steps.fields.outputs.sanitized_message }}'
}
]
}
}
]