Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-28530 Fix teams notif status detection #839

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading