diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 69dd5e332..3d1c7e0f7 100644 --- a/.github/actions/send-teams-notification/action.yml +++ b/.github/actions/send-teams-notification/action.yml @@ -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 @@ -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 diff --git a/docs/README.md b/docs/README.md index 6dc3ed351..652781ed6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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) diff --git a/version.txt b/version.txt index fa9d61610..9127c00fe 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v8.6.2 +v8.6.3