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 4 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
32 changes: 30 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,37 @@ runs:

- name: Compute workflow status
id: compute-workflow-status
uses: martialonline/workflow-status@fe13c6a4716673e224038aa1b02387352fb35e13 # v4
if: ${{ inputs.status == '' }}
shell: bash
run: |
url="${GITHUB_API_URL}/repos"
repo="${GITHUB_REPOSITORY}"
run_id="${GITHUB_RUN_ID}"
token="${{ github.token }}"
atchertchian marked this conversation as resolved.
Show resolved Hide resolved

failure=$(curl -s -H "Authorization: token ${token}" "${url}/${repo}/actions/runs/${run_id}/jobs?per_page=100" | \
jq -r '.jobs[].steps[] | select(.status == "completed" and .conclusion == "failure").conclusion' | \
wc -l)

cancelled=$(curl -s -H "Authorization: token ${token}" "${url}/${repo}/actions/runs/${run_id}/jobs?per_page=100" | \
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.

Is the `status` input is not filled, it will be computed based on the status of completed steps in currently running workflow.
atchertchian marked this conversation as resolved.
Show resolved Hide resolved
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