Skip to content

Commit

Permalink
AAE-28530 Fix teams notif status detection (#839)
Browse files Browse the repository at this point in the history
Co-authored-by: Domenico Sibilio <[email protected]>
  • Loading branch information
atchertchian and dsibilio authored Dec 18, 2024
1 parent c2ebfbb commit bcebeb8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
31 changes: 29 additions & 2 deletions .github/actions/send-teams-notification/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
description: Do not actually send the message
required: false
default: 'false'
status:
description: 'The workflow status: if not filled, it will be computed based on the completed steps status'
required: false
default: ''

runs:
using: composite
Expand All @@ -30,13 +34,36 @@ runs:

- name: Compute workflow status
id: compute-workflow-status
uses: martialonline/workflow-status@fe13c6a4716673e224038aa1b02387352fb35e13 # v4
if: ${{ inputs.status == '' }}
shell: bash
run: |
API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs?per_page=100"
RUNS=$(curl -s -H "Authorization: token ${{ github.token }}" "${API_URL}")
failure=$(echo $RUNS | \
jq -r '.jobs[].steps[] | select(.status == "completed" and .conclusion == "failure").conclusion' | \
wc -l)
cancelled=$(echo $RUNS | \
jq -r '.jobs[].steps[] | select(.status == "completed" and .conclusion == "cancelled").conclusion' | \
wc -l)
if [ "${failure}" -gt 0 ]; then
status="failure"
elif [ "${cancelled}" -gt 0 ]; then
status="cancelled"
else
status="success"
fi
echo "status=${status}" >> $GITHUB_OUTPUT
- name: Compute color
shell: bash
id: compute-color
env:
STATUS: ${{ steps.compute-workflow-status.outputs.status }}
STATUS: ${{ inputs.status || steps.compute-workflow-status.outputs.status }}
run: |
COLOR=808080
case $STATUS in
Expand Down
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,9 @@ Sends a teams notification with a pre-defined payload.

The above webhook URL is a mandatory parameter. Make sure to [Create Incoming Webhooks](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet) before using this action. Add the webhook URL as a `secret` at the repo level.

If the `status` input is not filled, it will be computed based on the status of completed steps in currently running workflow.
The workflow permissions will require "actions: read" in this case.

Sample of a SUCCESS notification on a `push` event.

![Teams Success](./images/send-teams-push-success.png)
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.6.2
v8.6.3

0 comments on commit bcebeb8

Please sign in to comment.