Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Teams notification action
Browse files Browse the repository at this point in the history
  • Loading branch information
vkamra committed Oct 31, 2023
1 parent 73b4ba3 commit 0886f5b
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 72 deletions.
58 changes: 0 additions & 58 deletions .github/actions/slack-message/action.yml

This file was deleted.

91 changes: 91 additions & 0 deletions .github/actions/teams-message/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Send a message to Teams

inputs:
msg:
description: The teams message text
teams_url:
description: passthrough for secrets.TEAMS_CORSO_CI_WEBHOOK_URL

runs:
using: composite
steps:
- uses: actions/checkout@v3

- name: set github ref
shell: bash
run: |
echo "github_reference=${{ github.ref }}" >> $GITHUB_ENV
- name: trim github ref
shell: bash
run: |
echo "trimmed_ref=${github_reference#refs/}" >> $GITHUB_ENV
- name: build urls
shell: bash
run: |
echo "logurl=$(printf 'https://github.com/alcionai/corso/actions/runs/%s' ${{ github.run_id }})" >> $GITHUB_ENV
echo "commiturl=$(printf 'https://github.com/alcionai/corso/commit/%s' ${{ github.sha }})" >> $GITHUB_ENV
echo "refurl=$(printf 'https://github.com/alcionai/corso/%s' ${{ env.trimmed_ref }})" >> $GITHUB_ENV
- name: use url or blank val
shell: bash
run: |
echo "STEP=${{ env.trimmed_ref || '' }}" >> $GITHUB_ENV
echo "JOB=${{ github.job || '' }}" >> $GITHUB_ENV
echo "LOGS=${{ github.run_id && env.logurl || '-' }}" >> $GITHUB_ENV
echo "COMMIT=${{ github.sha && env.commiturl || '-' }}" >> $GITHUB_ENV
echo "REF=${{ env.trimmed_ref && env.refurl || '-' }}" >> $GITHUB_ENV
- name: Send JSON payload to Teams Webhook
shell: bash
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"type":"message",
"attachments":[
{
"contentType":"application/vnd.microsoft.card.adaptive",
"contentUrl":null,
"content":{
"$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
"type":"AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "${{ inputs.msg }}",
"color": "Attention"
},
{
"type": "TextBlock",
"text": "${{ env.JOB }} :: ${{ env.STEP }}",
"wrap": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Action",
"url": "${{ env.LOGS }}"
},
{
"type": "Action.OpenUrl",
"title": "Commit",
"url": "${{ env.COMMIT }}"
},
{
"type": "Action.OpenUrl",
"title": "Ref",
"url": "${{ env.REF }}"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5"
}
}
]
}' \
${{ inputs.teams_url }}
12 changes: 6 additions & 6 deletions .github/workflows/ci_test_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
m365-admin-user: ${{ secrets.M365_TENANT_ADMIN_USER }}
m365-admin-password: ${{ secrets.M365_TENANT_ADMIN_PASSWORD }}

- name: Notify failure in slack
- name: Notify failure in teams
if: failure()
uses: ./.github/actions/slack-message
uses: ./.github/actions/teams-message
with:
msg: "[FAILED] ${{ vars[matrix.user] }} CI Cleanup"
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
teams_url: ${{ secrets.TEAMS_CORSO_CI_WEBHOOK_URL }}

Test-Site-Data-Cleanup:
environment: Testing
Expand Down Expand Up @@ -71,9 +71,9 @@ jobs:
m365-admin-user: ${{ secrets.M365_TENANT_ADMIN_USER }}
m365-admin-password: ${{ secrets.M365_TENANT_ADMIN_PASSWORD }}

- name: Notify failure in slack
- name: Notify failure in teams
if: failure()
uses: ./.github/actions/slack-message
uses: ./.github/actions/teams-message
with:
msg: "[FAILED] ${{ vars[matrix.site] }} CI Cleanup"
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
teams_url: ${{ secrets.TEAMS_CORSO_CI_WEBHOOK_URL }}
6 changes: 3 additions & 3 deletions .github/workflows/longevity_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ jobs:
if-no-files-found: error
retention-days: 14

- name: Notify failure in slack
- name: Notify failure in teams
if: failure()
uses: ./.github/actions/slack-message
uses: ./.github/actions/teams-message
with:
msg: "[FAILED] Longevity Test"
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
teams_url: ${{ secrets.TEAMS_CORSO_CI_WEBHOOK_URL }}
6 changes: 3 additions & 3 deletions .github/workflows/nightly_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ jobs:
if-no-files-found: error
retention-days: 14

- name: Notify failure in slack
- name: Notify failure in teams
if: failure()
uses: ./.github/actions/slack-message
uses: ./.github/actions/teams-message
with:
msg: "[FAILED] Nightly Checks"
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
teams_url: ${{ secrets.TEAMS_CORSO_CI_WEBHOOK_URL }}
4 changes: 2 additions & 2 deletions .github/workflows/sanity-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ jobs:

- name: Notify failure in slack
if: failure()
uses: ./.github/actions/slack-message
uses: ./.github/actions/teams-message
with:
msg: "[FAILED] Sanity Tests"
slack_url: ${{ secrets.SLACK_WEBHOOK_URL }}
teams_url: ${{ secrets.SLACK_WEBHOOK_URL }}
26 changes: 26 additions & 0 deletions .github/workflows/testnotification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Manually Test Teams Action

on:
push:
branches: [slack_message_to_teams]

workflow_dispatch:
inputs:
msg:
description: 'Message to send:'
required: true
default: 'This is a test message'

jobs:
notify:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Send notification
uses: ./.github/actions/teams-message
with:
msg: ${{ github.event.inputs.msg }}
teams_url: ${{ secrets.TEAMS_CORSO_CI_WEBHOOK_URL }}

0 comments on commit 0886f5b

Please sign in to comment.