mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-12 07:59:29 -05:00
ci: refactor teams notification action (#2600)
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
02b4ba8413
commit
6d6ef66a31
@ -1,4 +1,4 @@
|
|||||||
name: notify failure
|
name: notify e2e failure
|
||||||
description: "Post a failure message to project board and teams"
|
description: "Post a failure message to project board and teams"
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
@ -82,32 +82,43 @@ runs:
|
|||||||
echo "opensearchURL=${opensearchURL}" | tee -a "$GITHUB_OUTPUT"
|
echo "opensearchURL=${opensearchURL}" | tee -a "$GITHUB_OUTPUT"
|
||||||
echo "issueURL=${issueURL}" | tee -a "$GITHUB_OUTPUT"
|
echo "issueURL=${issueURL}" | tee -a "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Notify teams channel
|
- name: Create notification fields
|
||||||
|
id: create-fields
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
cp .github/teams_payload_template.json teams_payload.json
|
echo '[ { "title": "CloudProvider", "value": "${{ inputs.provider }}" }, { "title": "Test", "value": "${{ inputs.test }}" } ]' > facts.json
|
||||||
yq -iP '.attachments[0].content.body[0].columns[1].items[1].text = "${{ github.workflow }}"' teams_payload.json
|
|
||||||
yq -iP '.attachments[0].content.body[0].columns[1].items[2].facts += [ { "title": "CloudProvider", "value": "${{ inputs.provider }}" } ]' teams_payload.json
|
|
||||||
yq -iP '.attachments[0].content.body[0].columns[1].items[2].facts += [ { "title": "Test", "value": "${{ inputs.test }}" } ]' teams_payload.json
|
|
||||||
if [[ -n "${{ inputs.kubernetesVersion }}" ]]; then
|
if [[ -n "${{ inputs.kubernetesVersion }}" ]]; then
|
||||||
yq -iP '.attachments[0].content.body[0].columns[1].items[2].facts += [ { "title": "KubernetesVersion", "value": "${{ inputs.kubernetesVersion }}" } ]' teams_payload.json
|
yq -oj -iP '. += [ { "title": "KubernetesVersion", "value": "${{ inputs.kubernetesVersion }}" } ]' facts.json
|
||||||
fi
|
fi
|
||||||
if [[ -n "${{ inputs.refStream }}" ]]; then
|
if [[ -n "${{ inputs.refStream }}" ]]; then
|
||||||
yq -iP '.attachments[0].content.body[0].columns[1].items[2].facts += [ { "title": "RefStream", "value": "${{ inputs.refStream }}" } ]' teams_payload.json
|
yq -oj -iP '. += [ { "title": "RefStream", "value": "${{ inputs.refStream }}" } ]' facts.json
|
||||||
fi
|
fi
|
||||||
text_value="<at>${{ steps.pick-assignee.outputs.assignee }}</at>"
|
|
||||||
entities=$(jq -c '.attachments[0].content.msteams.entities[]' teams_payload.json)
|
|
||||||
# need to filter entities to only have entry of mentioned person
|
|
||||||
filtered_entity=$(echo $entities | jq --arg text_value "$text_value" 'select(.text == $text_value)')
|
|
||||||
yq -iP '.attachments[0].content.msteams.entities = [ '"$filtered_entity"' ]' teams_payload.json
|
|
||||||
|
|
||||||
yq -iP '.attachments[0].content.body[0].columns[1].items[2].facts += [ { "title": "Assignee", "value": "<at>${{ steps.pick-assignee.outputs.assignee }}</at>" } ]' teams_payload.json
|
buttons='[
|
||||||
yq -iP '.attachments[0].content.actions[0].url = "${{ steps.create-project-card.outputs.jobURL }}"' teams_payload.json
|
{
|
||||||
yq -iP '.attachments[0].content.actions[1].url = "${{ steps.create-project-card.outputs.issueURL }}"' teams_payload.json
|
"type": "Action.OpenUrl",
|
||||||
yq -iP ".attachments[0].content.actions[2].url = \"${{ steps.create-project-card.outputs.opensearchURL }}\"" teams_payload.json
|
"title": "Project board issue",
|
||||||
cat teams_payload.json
|
"url": "${{ steps.create-project-card.outputs.issueURL }}",
|
||||||
curl \
|
"style": "positive"
|
||||||
-H "Content-Type: application/json" \
|
},
|
||||||
-d @teams_payload.json \
|
{
|
||||||
"${{ inputs.teamsWebhookUri }}"
|
"type": "Action.OpenUrl",
|
||||||
|
"title": "OpenSearch logs",
|
||||||
|
"url": "${{ steps.create-project-card.outputs.opensearchURL }}",
|
||||||
|
"style": "positive"
|
||||||
|
}
|
||||||
|
]'
|
||||||
|
|
||||||
|
echo "additionalFields=$(cat facts.json)" | tee -a "$GITHUB_OUTPUT"
|
||||||
|
echo "additionalButtons=$buttons" | tee -a "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Notify teams channel
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./.github/actions/notify_teams
|
||||||
|
with:
|
||||||
|
teamsWebhookURI: ${{ inputs.teamsWebhookUri }}
|
||||||
|
title: "Constellation E2E test failed"
|
||||||
|
assignee: ${{ steps.pick-assignee.outputs.assignee }}
|
||||||
|
additionalFields: ${{ steps.create-fields.outputs.additionalFields }}
|
||||||
|
additionalButtons: ${{ steps.create-fields.outputs.additionalButtons }}
|
52
.github/actions/notify_teams/action.yml
vendored
Normal file
52
.github/actions/notify_teams/action.yml
vendored
Normal file
@ -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 }}"
|
14
.github/teams_payload_template.json
vendored
14
.github/teams_payload_template.json
vendored
@ -93,7 +93,7 @@
|
|||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"type": "TextBlock",
|
"type": "TextBlock",
|
||||||
"text": "Constellation E2E test failed",
|
"text": "Title",
|
||||||
"wrap": true,
|
"wrap": true,
|
||||||
"fontType": "Default",
|
"fontType": "Default",
|
||||||
"size": "large",
|
"size": "large",
|
||||||
@ -123,18 +123,6 @@
|
|||||||
"title": "GitHub workflow run",
|
"title": "GitHub workflow run",
|
||||||
"url": "",
|
"url": "",
|
||||||
"style": "positive"
|
"style": "positive"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "Action.OpenUrl",
|
|
||||||
"title": "Project board issue",
|
|
||||||
"url": "",
|
|
||||||
"style": "positive"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "Action.OpenUrl",
|
|
||||||
"title": "OpenSearch logs",
|
|
||||||
"url": "",
|
|
||||||
"style": "positive"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
23
.github/workflows/build-os-image-scheduled.yml
vendored
23
.github/workflows/build-os-image-scheduled.yml
vendored
@ -114,3 +114,26 @@ jobs:
|
|||||||
labels: no changelog
|
labels: no changelog
|
||||||
# We need to push changes using a token, otherwise triggers like on:push and on:pull_request won't work.
|
# We need to push changes using a token, otherwise triggers like on:push and on:pull_request won't work.
|
||||||
token: ${{ !github.event.pull_request.head.repo.fork && secrets.CI_COMMIT_PUSH_PR || '' }}
|
token: ${{ !github.event.pull_request.head.repo.fork && secrets.CI_COMMIT_PUSH_PR || '' }}
|
||||||
|
|
||||||
|
notify-failure:
|
||||||
|
if: failure()
|
||||||
|
needs: [ "stream", "build-image", "update-code" ]
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
||||||
|
with:
|
||||||
|
ref: ${{ github.head_ref }}
|
||||||
|
|
||||||
|
- name: Pick assignee
|
||||||
|
id: pick-assignee
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./.github/actions/pick_assignee
|
||||||
|
|
||||||
|
- name: Notify failure
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./.github/actions/notify_teams
|
||||||
|
with:
|
||||||
|
teamsWebhookURI: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
|
title: "Constellation image build failed"
|
||||||
|
assignee: ${{ steps.pick-assignee.outputs.assignee }}
|
||||||
|
4
.github/workflows/e2e-test-daily.yml
vendored
4
.github/workflows/e2e-test-daily.yml
vendored
@ -114,7 +114,7 @@ jobs:
|
|||||||
github.ref == 'refs/heads/main' &&
|
github.ref == 'refs/heads/main' &&
|
||||||
github.event_name == 'schedule'
|
github.event_name == 'schedule'
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./.github/actions/notify_failure
|
uses: ./.github/actions/notify_e2e_failure
|
||||||
with:
|
with:
|
||||||
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
||||||
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
@ -162,7 +162,7 @@ jobs:
|
|||||||
github.ref == 'refs/heads/main' &&
|
github.ref == 'refs/heads/main' &&
|
||||||
github.event_name == 'schedule'
|
github.event_name == 'schedule'
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./.github/actions/notify_failure
|
uses: ./.github/actions/notify_e2e_failure
|
||||||
with:
|
with:
|
||||||
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
||||||
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
|
4
.github/workflows/e2e-test-weekly.yml
vendored
4
.github/workflows/e2e-test-weekly.yml
vendored
@ -282,7 +282,7 @@ jobs:
|
|||||||
github.ref == 'refs/heads/main' &&
|
github.ref == 'refs/heads/main' &&
|
||||||
github.event_name == 'schedule'
|
github.event_name == 'schedule'
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./.github/actions/notify_failure
|
uses: ./.github/actions/notify_e2e_failure
|
||||||
with:
|
with:
|
||||||
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
||||||
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
@ -351,7 +351,7 @@ jobs:
|
|||||||
github.ref == 'refs/heads/main' &&
|
github.ref == 'refs/heads/main' &&
|
||||||
github.event_name == 'schedule'
|
github.event_name == 'schedule'
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./.github/actions/notify_failure
|
uses: ./.github/actions/notify_e2e_failure
|
||||||
with:
|
with:
|
||||||
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
||||||
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
|
2
.github/workflows/e2e-upgrade.yml
vendored
2
.github/workflows/e2e-upgrade.yml
vendored
@ -305,7 +305,7 @@ jobs:
|
|||||||
github.ref == 'refs/heads/main' &&
|
github.ref == 'refs/heads/main' &&
|
||||||
inputs.scheduled
|
inputs.scheduled
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./.github/actions/notify_failure
|
uses: ./.github/actions/notify_e2e_failure
|
||||||
with:
|
with:
|
||||||
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
||||||
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
|
2
.github/workflows/e2e-windows.yml
vendored
2
.github/workflows/e2e-windows.yml
vendored
@ -171,7 +171,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Notify about failure
|
- name: Notify about failure
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./.github/actions/notify_failure
|
uses: ./.github/actions/notify_e2e_failure
|
||||||
with:
|
with:
|
||||||
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
projectWriteToken: ${{ secrets.PROJECT_WRITE_TOKEN }}
|
||||||
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
teamsWebhookUri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
|
||||||
|
Loading…
Reference in New Issue
Block a user