Skip to content

Commit

Permalink
AAE-28530 Teams notifications improvements (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
atchertchian authored Dec 5, 2024
1 parent 6068c61 commit 9789882
Show file tree
Hide file tree
Showing 18 changed files with 757 additions and 99 deletions.
12 changes: 12 additions & 0 deletions .github/actions/reportportal-summarize/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ outputs:
slack-message:
description: Outcome message for slack
value: ${{ steps.slack-message.outputs.message }}
teams-message:
description: Outcome message for teams
value: ${{ steps.teams-message.outputs.message }}

runs:
using: composite
Expand Down Expand Up @@ -54,3 +57,12 @@ runs:
RP_CONTENT: ${{ steps.rp-output.outputs.content }}
RP_LAUNCH_URL: ${{ steps.rp-output.outputs.url }}
run: ${{ github.action_path }}/get-slack-message.sh

- name: Compute Teams message
id: teams-message
shell: bash
env:
RP_LAUNCH_KEY: ${{ inputs.rp-launch-key }}
RP_CONTENT: ${{ steps.rp-output.outputs.content }}
RP_LAUNCH_URL: ${{ steps.rp-output.outputs.url }}
run: ${{ github.action_path }}/get-teams-message.sh
8 changes: 4 additions & 4 deletions .github/actions/reportportal-summarize/get-slack-message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ if [[ -n "$RP_LAUNCH_KEY" ]]; then
read -r status
case $status in
PASSED)
sstatus="" ;;
status_icon="" ;;
FAILED)
sstatus=""
status_icon=""
;;
*)
sstatus="$status"
status_icon="$status"
;;
esac
MSG+="\n<$RP_LAUNCH_URL/$id|Report #$number> $sstatus"
MSG+="\n<$RP_LAUNCH_URL/$id|Report #$number> $status_icon"
done < <(echo "$RP_CONTENT" | jq -r '.content[] | .id, .number, .status')
fi
fi
Expand Down
34 changes: 34 additions & 0 deletions .github/actions/reportportal-summarize/get-teams-message.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -e

if [[ -n "$RP_LAUNCH_KEY" ]]; then

NB=$(echo "$RP_CONTENT" | jq -r '.page.totalElements // "0"')
if [[ "$NB" == "0" || -z "$NB" ]]; then
MSG+="No report found for key "'`'"$RP_LAUNCH_KEY"'`'"."
MSG+="\n\nSee [latest reports]($RP_LAUNCH_URL)."
elif [ "$NB" == "1" ]; then
RP_LAUNCH_ID=$(echo "$RP_CONTENT" | jq -r '.content[0].id // empty')
STATUS=$(echo "$RP_CONTENT" | jq -r '.content[0].status // empty')
[[ "$STATUS" == 'PASSED' ]] && ICON="" || ICON=""
MSG+="See [report]($RP_LAUNCH_URL/$RP_LAUNCH_ID) $ICON"
else
MSG+="$NB reports found for key "'`'"$RP_LAUNCH_KEY"'`'"."
while read -r id ; do
read -r number
read -r status
case $status in
PASSED)
status_icon="" ;;
FAILED)
status_icon=""
;;
*)
status_icon="$status"
;;
esac
MSG+="\n\n[Report #$number]($RP_LAUNCH_URL/$id) $status_icon"
done < <(echo "$RP_CONTENT" | jq -r '.content[] | .id, .number, .status')
fi
fi

echo "message=$MSG" >> $GITHUB_OUTPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
setup() {
# Runs everywhere
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/..:$PATH"

export GITHUB_OUTPUT="$BATS_TMPDIR"/test-get-teams-message_ghoutput_"$RANDOM"'.log'
> $GITHUB_OUTPUT

export RP_LAUNCH_KEY=my-tests-push-3665876492
export RP_TOKEN=tok
export RP_URL=https://rpserver:8080

export RP_CONTENT=""
export RP_LAUNCH_URL=https://rpserver:8080/ui/#my-project/launches/all

export NO_MESSAGE="message="
export KEY_NO_REPORT="message=No report found for key \`my-tests-push-3665876492\`.\n\nSee [latest reports](https://rpserver:8080/ui/#my-project/launches/all)."
export SINGLE_REPORT="message=See [report](https://rpserver:8080/ui/#my-project/launches/all/88) ✅"
export MULTIPLE_REPORTS=$(cat << BATS
message=3 reports found for key \`my-tests-push-3665876492\`.\n\n[Report #3](https://rpserver:8080/ui/#my-project/launches/all/91) ❌\n\n[Report #2](https://rpserver:8080/ui/#my-project/launches/all/90) WHATEVER_STATUS\n\n[Report #1](https://rpserver:8080/ui/#my-project/launches/all/89) ✅
BATS
)
}

teardown() {
rm -f $GITHUB_OUTPUT
}

@test "teams message rp disabled" {
export RP_LAUNCH_KEY=""
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$NO_MESSAGE" ]
}

@test "teams message no launch id" {
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$KEY_NO_REPORT" ]
}

@test "teams message single" {
export RP_CONTENT="$(< $BATS_TEST_DIRNAME/sample-launch.json)"
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$SINGLE_REPORT" ]
}

@test "teams message multiple" {
export RP_CONTENT="$(< $BATS_TEST_DIRNAME/sample-launches.json)"
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$MULTIPLE_REPORTS" ]
}

@test "teams message rp failure no results" {
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$KEY_NO_REPORT" ]
}

@test "teams message rp failure no results empty json" {
export RP_CONTENT="{}"
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$KEY_NO_REPORT" ]
}

@test "teams message rp success no results" {
export OUTCOME="success"
export RP_CONTENT="$(< $BATS_TEST_DIRNAME/empty-launch.json)"
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$KEY_NO_REPORT" ]
}

@test "teams message rp failure no results empty json no launch key" {
export RP_LAUNCH_KEY=""
export RP_CONTENT="{}"
run get-teams-message.sh
[ "$status" -eq 0 ]
echo "$(< $GITHUB_OUTPUT)"
[ "$(< $GITHUB_OUTPUT)" = "$NO_MESSAGE" ]

}
Loading

0 comments on commit 9789882

Please sign in to comment.