Skip to content

Commit 52568ce

Browse files
[action] Update workflow to parse & monitor pending automation PRs. (sonic-net#16446)
Why I did it There are many automation PRs pending for PR checker failure issue. As PR number grows, github api to list prs comes to its limit. We need to monitor and send alert for these PRs. Work item tracking Microsoft ADO (number only): 25064441 How I did it For auto-cherry pick PRs: - more than 3 days, comment @author to check - more than 10 days, stop comment. - more than 28 days, comment @author PR will be closed - more than 30 days, close PR For submodule update HEAD PRs: - more than 3 days, send alert(submodule PR) How to verify it Which release bra
1 parent 7d2e3cb commit 52568ce

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

.github/workflows/automerge_scan.yml

+43-26
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,74 @@ jobs:
1616
set -e
1717
1818
echo ${TOKEN} | gh auth login --with-token
19-
gh pr list -R sonic-net/sonic-buildimage -A mssonicbld --json additions,assignees,author,baseRefName,body,changedFiles,closed,closedAt,comments,commits,createdAt,deletions,files,headRefName,headRepository,headRepositoryOwner,id,isCrossRepository,isDraft,labels,latestReviews,maintainerCanModify,mergeCommit,mergeStateStatus,mergeable,mergedAt,mergedBy,milestone,number,potentialMergeCommit,projectCards,reactionGroups,reviewDecision,reviewRequests,reviews,state,statusCheckRollup,title,updatedAt,url > prs.log
19+
gh pr list -R sonic-net/sonic-buildimage -A mssonicbld -L 100 -S "label:automerge" --json url,body,title,createdAt,labels,statusCheckRollup > prs.log
2020
cat prs.log | jq
2121
- name: Main
2222
run: |
2323
set -e
2424
25+
# PR merge run per 2 hours
26+
# Other operation run per day.
27+
# Cherry pick PR:
28+
# more than 3 days, comment @author to check
29+
# more than 10 days, stop comment.
30+
# more than 28 days, comment @author PR will be closed
31+
# more than 30 days, close PR
32+
date_3d_ago=$(date --date "3 day ago" -u +"%FT%TZ")
33+
date_10d_ago=$(date --date "10 day ago" -u +"%FT%TZ")
34+
date_28d_ago=$(date --date "28 day ago" -u +"%FT%TZ")
35+
date_30d_ago=$(date --date "30 day ago" -u +"%FT%TZ")
36+
date_now=$(date -u +"%T")
37+
operate=false
38+
[[ "$date_now" < "02:00:00" ]] && operate=true
39+
2540
count=$(cat prs.log | jq 'length')
2641
for ((i=0;i<$count;i++))
2742
do
2843
url=$(cat prs.log | jq -r ".[$i].url")
2944
body=$(cat prs.log | jq -r ".[$i].body")
3045
title=$(cat prs.log | jq -r ".[$i].title")
46+
origin_pr_id=$(echo $title | grep -Eo "\[action\] \[PR:[0-9]*\]" | grep -Eo [0-9]* || true)
3147
created_at=$(cat prs.log | jq -r ".[$i].createdAt")
32-
echo PR: $(($i+1))/$count, URL: $url, createdAt: $created_at, now: $(date -u +"%FT%TZ")
48+
echo PR: $(($i+1))/$count, URL: $url, origin PR: $origin_pr_id, createdAt: $created_at, operate: $operate
3349
[[ "$url" == "" ]] && continue
3450
[[ $created_at > $(date --date "1 hour ago" -u +"%FT%TZ") ]] && continue
35-
# only check automerge PR.
36-
cat prs.log | jq -r ".[$i].labels[].name" | grep automerge || continue
3751
3852
checks=$(cat prs.log | jq ".[$i].statusCheckRollup")
3953
checks_count=$(echo $checks | jq 'length')
40-
echo Checks count: $checks_count
54+
pr_success=true
4155
for ((j=0;j<$checks_count;j++))
4256
do
4357
check=$(echo $checks | jq ".[$j]")
44-
state=$(echo $check | jq -r '.state')
58+
status=$(echo $check | jq -r '.status')
4559
conclusion=$(echo $check | jq -r '.conclusion')
4660
name=$(echo $check | jq -r '.name')
4761
4862
# EasyCLA success flag: state=SUCCESS
4963
# Others success flag: conclusion in SUCCESS,NEUTRAL
50-
# Ignore Azure.sonic-buildimage stage check result. It may be set continueOnError
51-
echo "$name" | grep "Azure.sonic-buildimage (" && continue
52-
# rerun Azure.sonic-buildimage per day
53-
if [[ "$name" == "Azure.sonic-buildimage" ]] && [[ "$conclusion" == "FAILURE" ]];then
54-
completedAt=$(echo $check | jq -r '.completedAt')
55-
[[ "$completedAt" < $(date --date "2 hour ago" -u +"%FT%TZ") ]] && [[ $(date -u +"%T") < "02:00:00" ]] && gh pr comment $url --body "/azp run Azure.sonic-buildimage"
56-
fi
57-
# Ignore Semgrep, it has issues.
58-
[[ "$name" == "Semgrep" ]] && continue
59-
if [[ "$state" == "SUCCESS" ]];then
60-
# check pass
61-
continue
62-
elif [[ "$conclusion" == "SUCCESS" ]] || [[ "$conclusion" == "NEUTRAL" ]];then
63-
# check pass
64-
continue
65-
else
66-
echo "$url Check failed!!!"
67-
echo $check | jq
68-
continue 2
69-
fi
64+
# only check Azure.sonic-buildimage currently
65+
echo "$name" | grep -v "Azure.sonic-buildimage" > /dev/null && continue
66+
[[ "$status" != "COMPLETED" ]] && echo "$name: $status" && continue 2
67+
68+
success=true
69+
( [[ "$conclusion" == "FAILURE" ]] || [[ "$conclusion" == "CANCELLED" ]] ) && success=false && pr_success=false
70+
! $success && echo "FAIL: $name"
7071
done
72+
73+
# rerun Azure.sonic-buildimage per day
74+
! $pr_success && $operate && gh pr comment $url --body "/azp run Azure.sonic-buildimage"
75+
76+
# If auto cherry pick PRs failed, comment in original PR and close cherry pick PR
77+
if [ -n "$origin_pr_id" ] && [[ $created_at < $date_3d_ago ]] && ! $pr_success;then
78+
origin_pr_url=https://github.com/sonic-net/sonic-buildimage/pull/$origin_pr_id
79+
author=$(gh pr view $origin_pr_url --json author | jq .author.login -r)
80+
echo "Original author will check."
81+
$operate && [[ $created_at > $date_10d_ago ]] && gh pr comment $origin_pr_url --body "@$author cherry pick PR didn't pass PR checker. Please check!!!<br>$url"
82+
$operate && [[ $created_at < $date_28d_ago ]] && gh pr comment $origin_pr_url --body "@$author cherry pick PR didn't pass PR checker. Please check!!! Auto cherry pick PR will be closed in 2 days.<br>$url"
83+
$operate && [[ $created_at < $date_30d_ago ]] && echo "$url Closed" && gh pr close $url
84+
fi
85+
86+
! $pr_success && continue
7187
# merge the PR
7288
echo ========Merging PR========
7389
if echo $title | grep "^\[submodule\]";then
@@ -77,3 +93,4 @@ jobs:
7793
fi
7894
echo ========Finished PR========
7995
done
96+

0 commit comments

Comments
 (0)