Skip to content

Commit 3464677

Browse files
[infinispan#16813] Linkify flaky test names and show occurrence count in PR comments
1 parent e874d26 commit 3464677

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

.github/actions/comment-pr-flaky-test/action.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,39 @@ runs:
2222
PR="${{ inputs.pr-number }}"
2323
if [ "$PR" != "" ]; then
2424
shopt -s nullglob globstar
25+
26+
# Load flaky-test-issues mapping (written by track_flaky_tests.sh)
27+
declare -A ISSUE_MAP
28+
declare -A COMMENT_COUNT_MAP
29+
if [ -f flaky-test-issues.map ]; then
30+
while IFS=$'\t' read -r key number count; do
31+
ISSUE_MAP["$key"]="$number"
32+
COMMENT_COUNT_MAP["$key"]="$count"
33+
done < flaky-test-issues.map
34+
fi
35+
2536
FLAKY_TEST_GLOB="**/target/*-reports*/**/TEST-*FLAKY.xml"
2637
TESTS=(${FLAKY_TEST_GLOB})
2738
for TEST in "${TESTS[@]}"
2839
do
29-
FULL_TEST_NAME=$(xmlstarlet sel -T -t -m "/testsuite/testcase" -o ' - '\
40+
RAW_NAMES=$(xmlstarlet sel -T -t -m "/testsuite/testcase" \
3041
-v "concat(@classname,'#',@name)" -n ${TEST} \
3142
| sed 's/(Flaky Test)//' | sed 's/\[[0-9]\]//')
32-
FLAKES_PR_COMMENT="$FLAKES_PR_COMMENT$FULL_TEST_NAME\n"
43+
while IFS= read -r LINE; do
44+
[ -z "$LINE" ] && continue
45+
# Strip leading/trailing whitespace
46+
LINE=$(echo "$LINE" | xargs)
47+
# Build lookup key by stripping parameters (same logic as track_flaky_tests.sh)
48+
LOOKUP_KEY="${LINE%%\[*}"
49+
LOOKUP_KEY="${LOOKUP_KEY%%(*}"
50+
if [ -n "${ISSUE_MAP[$LOOKUP_KEY]+x}" ]; then
51+
ISSUE_NUM="${ISSUE_MAP[$LOOKUP_KEY]}"
52+
SEEN_COUNT=$(( ${COMMENT_COUNT_MAP[$LOOKUP_KEY]} + 1 ))
53+
FLAKES_PR_COMMENT="$FLAKES_PR_COMMENT - [${LINE}](https://github.com/${{ github.repository }}/issues/${ISSUE_NUM}) (seen ${SEEN_COUNT} times)\n"
54+
else
55+
FLAKES_PR_COMMENT="$FLAKES_PR_COMMENT - ${LINE}\n"
56+
fi
57+
done <<< "$RAW_NAMES"
3358
done
3459
if [ "$FLAKES_PR_COMMENT" != "" ]; then
3560
pr_url=https://github.com/${{ github.repository }}/pull/$PR

bin/gh/track_flaky_tests.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ for TEST in "${TESTS[@]}"; do
6969
ISSUE_NUMBER=$(echo "${ISSUE_URL}" | grep -oE '[0-9]+$')
7070
# Set the issue type to Bug via API
7171
gh api -X PATCH "/repos/${GITHUB_REPOSITORY}/issues/${ISSUE_NUMBER}" --field type=Bug
72+
COMMENT_COUNT=0
7273
else
73-
export ISSUE_KEY=$(echo "${ISSUES}" | jq '.[0].number')
74+
ISSUE_NUMBER=$(echo "${ISSUES}" | jq -r '.[0].number')
75+
# Fetch issue data to check state and get comment count in a single API call
76+
ISSUE_DATA=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${ISSUE_NUMBER}")
77+
COMMENT_COUNT=$(echo "${ISSUE_DATA}" | jq .comments)
7478
# Re-open the issue if it was previously resolved
75-
if [ "$(gh issue view ${ISSUE_KEY} --json state | jq .state)" == '"CLOSED"' ]; then
76-
gh issue reopen ${ISSUE_KEY}
79+
if [ "$(echo "${ISSUE_DATA}" | jq -r .state)" == 'closed' ]; then
80+
gh issue reopen ${ISSUE_NUMBER}
7781
fi
78-
gh issue comment ${ISSUE_KEY} --body "${BODY}"
82+
gh issue comment ${ISSUE_NUMBER} --body "${BODY}"
7983
fi
84+
echo -e "${TEST_CLASS}#${TEST_NAME_NO_PARAMS}\t${ISSUE_NUMBER}\t${COMMENT_COUNT}" >> flaky-test-issues.map
8085
done
8186
done

0 commit comments

Comments
 (0)