From 93bce2f5f9643ca582517950b61fc13af1d81a48 Mon Sep 17 00:00:00 2001 From: miampf Date: Thu, 10 Oct 2024 16:04:57 +0200 Subject: [PATCH] ci: use card template for teams post (#925) --- .github/actions/post_to_teams/action.yml | 35 +++++++- .../post_to_teams/teams_card_template.json | 85 +++++++++++++++++++ .github/workflows/e2e.yaml | 2 + .../workflows/e2e_runtime-reproducibility.yml | 7 +- .github/workflows/rpm_updates.yml | 3 +- 5 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 .github/actions/post_to_teams/teams_card_template.json diff --git a/.github/actions/post_to_teams/action.yml b/.github/actions/post_to_teams/action.yml index 1f21f0b2f4..3d1e1e1c43 100644 --- a/.github/actions/post_to_teams/action.yml +++ b/.github/actions/post_to_teams/action.yml @@ -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" \ diff --git a/.github/actions/post_to_teams/teams_card_template.json b/.github/actions/post_to_teams/teams_card_template.json new file mode 100644 index 0000000000..21e9acbc0e --- /dev/null +++ b/.github/actions/post_to_teams/teams_card_template.json @@ -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" + } + ] + } + } + ] +} diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 9cd6679358..9cd4a05496 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -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: | diff --git a/.github/workflows/e2e_runtime-reproducibility.yml b/.github/workflows/e2e_runtime-reproducibility.yml index 5e2f0188f7..3f00cf6105 100644 --- a/.github/workflows/e2e_runtime-reproducibility.yml +++ b/.github/workflows/e2e_runtime-reproducibility.yml @@ -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 @@ -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" diff --git a/.github/workflows/rpm_updates.yml b/.github/workflows/rpm_updates.yml index 112f2958b7..f3da959f90 100644 --- a/.github/workflows/rpm_updates.yml +++ b/.github/workflows/rpm_updates.yml @@ -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: ""