From cd0ae1f24586a4f8bbc6410846e491e2f20d0200 Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:43:20 +0100 Subject: [PATCH 1/7] AAE-28530 Fix teams notif status detection The old action checks completed jobs status: sometimes we notify while there's only one job and none completed, sometimes the job is not completed but there's a failed step. Modified the jq command to check ".jobs[].steps[]" status instead of ".jobs[]" --- .../send-teams-notification/action.yml | 25 ++++++++++++++++++- version.txt | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 69dd5e332..3b46ce7cc 100644 --- a/.github/actions/send-teams-notification/action.yml +++ b/.github/actions/send-teams-notification/action.yml @@ -30,7 +30,30 @@ runs: - name: Compute workflow status id: compute-workflow-status - uses: martialonline/workflow-status@fe13c6a4716673e224038aa1b02387352fb35e13 # v4 + shell: bash + run: | + url="${GITHUB_API_URL}/repos" + repo="${GITHUB_REPOSITORY}" + run_id="${GITHUB_RUN_ID}" + token="${{ github.token }}" + + 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 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 From 6ee38cb684e51152c55288d1c80ba3f05be89f34 Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:04:16 +0100 Subject: [PATCH 2/7] debug --- .github/actions/send-teams-notification/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 3b46ce7cc..9f5108b13 100644 --- a/.github/actions/send-teams-notification/action.yml +++ b/.github/actions/send-teams-notification/action.yml @@ -37,6 +37,7 @@ runs: run_id="${GITHUB_RUN_ID}" token="${{ github.token }}" + curl -s -H "Authorization: token ${token}" "${url}/${repo}/actions/runs/${run_id}/jobs?per_page=100" 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) From cef5418fcfa0c4b2a534e92bd8a51634f4e0365c Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:26:37 +0100 Subject: [PATCH 3/7] Revert "debug" This reverts commit 6ee38cb684e51152c55288d1c80ba3f05be89f34. --- .github/actions/send-teams-notification/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 9f5108b13..3b46ce7cc 100644 --- a/.github/actions/send-teams-notification/action.yml +++ b/.github/actions/send-teams-notification/action.yml @@ -37,7 +37,6 @@ runs: run_id="${GITHUB_RUN_ID}" token="${{ github.token }}" - curl -s -H "Authorization: token ${token}" "${url}/${repo}/actions/runs/${run_id}/jobs?per_page=100" 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) From ed1ee9f3841729e405275e8a8c3905abc4c60b11 Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:30:42 +0100 Subject: [PATCH 4/7] add ability to control status explicitly --- .github/actions/send-teams-notification/action.yml | 7 ++++++- docs/README.md | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 3b46ce7cc..19eb36cd3 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,6 +34,7 @@ runs: - name: Compute workflow status id: compute-workflow-status + if: ${{ inputs.status == '' }} shell: bash run: | url="${GITHUB_API_URL}/repos" @@ -59,7 +64,7 @@ runs: 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..066a74d52 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. +Is 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) From 226f48b95a7420458536f2d49c7d711ff06aaf34 Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:04:40 +0100 Subject: [PATCH 5/7] Update docs/README.md Co-authored-by: Domenico Sibilio --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 066a74d52..652781ed6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1489,7 +1489,7 @@ 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. +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. From 4c925cbeb3bd76bd06a4637d961b6d71f77a8329 Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:11:09 +0100 Subject: [PATCH 6/7] simplify bash logic --- .github/actions/send-teams-notification/action.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 19eb36cd3..5a6a64af8 100644 --- a/.github/actions/send-teams-notification/action.yml +++ b/.github/actions/send-teams-notification/action.yml @@ -37,16 +37,15 @@ runs: if: ${{ inputs.status == '' }} shell: bash run: | - url="${GITHUB_API_URL}/repos" - repo="${GITHUB_REPOSITORY}" - run_id="${GITHUB_RUN_ID}" - token="${{ github.token }}" + API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs?per_page=100" - failure=$(curl -s -H "Authorization: token ${token}" "${url}/${repo}/actions/runs/${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=$(curl -s -H "Authorization: token ${token}" "${url}/${repo}/actions/runs/${run_id}/jobs?per_page=100" | \ + failure=$(echo $RUNS | \ jq -r '.jobs[].steps[] | select(.status == "completed" and .conclusion == "cancelled").conclusion' | \ wc -l) From 035fa1fb5cdb56606a1fabe45c958bc1bcaa791a Mon Sep 17 00:00:00 2001 From: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:09:05 +0100 Subject: [PATCH 7/7] fix --- .github/actions/send-teams-notification/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/send-teams-notification/action.yml b/.github/actions/send-teams-notification/action.yml index 5a6a64af8..3d1c7e0f7 100644 --- a/.github/actions/send-teams-notification/action.yml +++ b/.github/actions/send-teams-notification/action.yml @@ -45,7 +45,7 @@ runs: jq -r '.jobs[].steps[] | select(.status == "completed" and .conclusion == "failure").conclusion' | \ wc -l) - failure=$(echo $RUNS | \ + cancelled=$(echo $RUNS | \ jq -r '.jobs[].steps[] | select(.status == "completed" and .conclusion == "cancelled").conclusion' | \ wc -l)