Skip to content

Commit

Permalink
ci: use card template for teams post (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf authored Oct 10, 2024
1 parent 30aebe7 commit 93bce2f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 6 deletions.
35 changes: 32 additions & 3 deletions .github/actions/post_to_teams/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,47 @@ inputs:
webhook:
description: "The webhook to send the message to."
required: true
title:
description: "The title of the notification."
required: true
message:
description: "The message to be sent. Note that you may not use quotes or escaped quotes in your message."
required: true
additionalFields:
description: "Additional fields to add to the Teams message (JSON formatted)"
default: "[]"
additionalActions:
description: "Additional actions (buttons) to add to the Teams message (JSON formatted)"
default: "[]"
runs:
using: "composite"
steps:
- name: Post to teams
shell: bash
run: |
run_url="${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}"
payload="$(printf '{"workflow_name": "%s", "job_id": "%s", "run_id": "%s", "ref": "%s", "message": "%s", "run_url": "%s"}' \
"${{github.workflow}}" "${{github.job}}" "${{github.run_id}}" "${{github.ref_name}}" "${{inputs.message}}" "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}")"
cp .github/actions/post_to_teams/teams_card_template.json template.json
# add the title
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[0].text = "${{inputs.title}}"' ./template.json
# add the message
yq -oj -iP '.attachments[0].content.body[1].text = "${{inputs.message}}"' ./template.json
# add the run url to the clickable button
yq -oj -iP '.attachments[0].content.actions[0].url = "${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}"' ./template.json
# update the fact set
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[1].facts[0].value = "${{github.job}}"' ./template.json
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[1].facts[1].value = "${{github.run_id}}"' ./template.json
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[1].facts[2].value = "${{github.ref_name}}"' ./template.json
# add additional fields
yq -oj -iP '.attachments[0].content.body[0].columns[1].items[1].facts += ${{inputs.additionalFields}}' ./template.json
# add additional buttons
yq -oj -iP '.attachments[0].content.actions += ${{inputs.additionalActions}}' ./template.json
payload="$(cat ./template.json)"
curl \
-H "Content-Type: application/json" \
-d "$payload" \
Expand Down
85 changes: 85 additions & 0 deletions .github/actions/post_to_teams/teams_card_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": 1,
"items": [
{
"type": "Image",
"url": "https://miro.medium.com/max/552/1*G7s61tFPaLI9JRxWYpRNLw.png",
"size": "Large",
"horizontalAlignment": "Center"
}
],
"horizontalAlignment": "Center",
"verticalContentAlignment": "Center"
},
{
"type": "Column",
"width": 2,
"items": [
{
"type": "TextBlock",
"text": "@@TITLE@@",
"wrap": true,
"fontType": "Default",
"size": "Large",
"weight": "Bolder"
},
{
"type": "FactSet",
"facts": [
{
"title": "Job ID",
"value": "@@JOB_ID@@"
},
{
"title": "Run ID",
"value": "@@RUN_ID@@"
},
{
"title": "Ref",
"value": "@@REF@@"
}
]
}
]
}
]
},
{
"type": "TextBlock",
"text": "@@MESSAGE@@",
"wrap": true,
"horizontalAlignment": "Left",
"spacing": "Medium",
"isSubtle": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "GitHub workflow run",
"url": "@@RUN_URL@@",
"style": "positive"
}
]
}
}
]
}
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ jobs:
uses: ./.github/actions/post_to_teams
with:
webhook: ${{ secrets.TEAMS_CI_WEBHOOK }}
title: "${{ inputs.test-name }} failed"
message: "e2e test ${{ inputs.test-name }} failed"
additionalFields: '[{"title": "Platform", "value": "${{ inputs.platform }}"}]'
- name: Cleanup
if: cancelled() && !inputs.skip-undeploy
run: |
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/e2e_runtime-reproducibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ jobs:
uses: ./.github/actions/post_to_teams
with:
webhook: ${{ secrets.TEAMS_CI_WEBHOOK }}
message: "Runtime reproducibility test failed on ${{ matrix.build-target }}-${{ matrix.os }}"
title: "Runtime reproducibility test failed"
message: "Runtime reproducibility test failed on ${{ matrix.build-target}}-${{matrix.os }}"
additionalFields: '[{"title": "Build target", "value": "${{ matrix.build-target }}"}, {"title": "OS", "value": "${{ matrix.os }}"}]'

collect-checksums:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -87,4 +89,5 @@ jobs:
uses: ./.github/actions/post_to_teams
with:
webhook: ${{ secrets.TEAMS_CI_WEBHOOK }}
message: "Runtime reproducibility test failed to collect checksums"
title: "Runtime reproducibility test failed"
message: "failed to collect checksums"
3 changes: 2 additions & 1 deletion .github/workflows/rpm_updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ jobs:
uses: ./.github/actions/post_to_teams
with:
webhook: ${{ secrets.TEAMS_CI_WEBHOOK }}
message: "Updating RPM packages failed"
title: "Failed to update RPM packages"
message: ""

0 comments on commit 93bce2f

Please sign in to comment.