-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: refactor teams notification action (#2600)
Signed-off-by: Daniel Weiße <[email protected]>
- Loading branch information
1 parent
02b4ba8
commit 6d6ef66
Showing
8 changed files
with
115 additions
and
41 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
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 @@ | ||
name: notify teams | ||
description: "Post a message to Teams" | ||
|
||
inputs: | ||
teamsWebhookURI: | ||
description: "URI to send a message to the Teams channel" | ||
required: true | ||
title: | ||
description: "Title of the Teams notification" | ||
required: true | ||
assignee: | ||
description: "Assignee of the message" | ||
required: true | ||
additionalFields: | ||
description: "Additional fields to add to the Teams message (JSON formatted)" | ||
default: "[]" | ||
additionalButtons: | ||
description: "Additional Buttons to add to the Teams message (JSON formatted)" | ||
default: "[]" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Notify Teams channel | ||
continue-on-error: true | ||
shell: bash | ||
run: | | ||
cp .github/teams_payload_template.json teams_payload.json | ||
# Add workflow name to the notification | ||
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[0].text = "${{ inputs.title }}"' teams_payload.json | ||
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[1].text = "${{ github.workflow }}"' teams_payload.json | ||
# Add additional fields | ||
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[2].facts += ${{ inputs.additionalFields }} ' teams_payload.json | ||
# Remove everyone but the assignee from the JSON payload so the final message only contains the assignee | ||
filtered_entity=$(yq -oj '.attachments[0].content.msteams.entities[] | select(.text == "<at>${{ inputs.assignee }}</at>")' teams_payload.json) | ||
yq -oj -iP '.attachments[0].content.msteams.entities = [ '"$filtered_entity"' ]' teams_payload.json | ||
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[2].facts += [ { "title": "Assignee", "value": "<at>${{ inputs.assignee }}</at>" } ]' teams_payload.json | ||
# Add clickable button which links to the workflow triggering this notification | ||
yq -oj -iP '.attachments[0].content.actions[0].url = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"' teams_payload.json | ||
# Add additional buttons | ||
yq -oj -iP '.attachments[0].content.actions += ${{ inputs.additionalButtons }}' teams_payload.json | ||
cat teams_payload.json | ||
curl \ | ||
-H "Content-Type: application/json" \ | ||
-d @teams_payload.json \ | ||
"${{ inputs.teamsWebhookURI }}" |
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
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