@@ -16,58 +16,74 @@ jobs:
16
16
set -e
17
17
18
18
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
20
20
cat prs.log | jq
21
21
- name : Main
22
22
run : |
23
23
set -e
24
24
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
+
25
40
count=$(cat prs.log | jq 'length')
26
41
for ((i=0;i<$count;i++))
27
42
do
28
43
url=$(cat prs.log | jq -r ".[$i].url")
29
44
body=$(cat prs.log | jq -r ".[$i].body")
30
45
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)
31
47
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
33
49
[[ "$url" == "" ]] && continue
34
50
[[ $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
37
51
38
52
checks=$(cat prs.log | jq ".[$i].statusCheckRollup")
39
53
checks_count=$(echo $checks | jq 'length')
40
- echo Checks count: $checks_count
54
+ pr_success=true
41
55
for ((j=0;j<$checks_count;j++))
42
56
do
43
57
check=$(echo $checks | jq ".[$j]")
44
- state =$(echo $check | jq -r '.state ')
58
+ status =$(echo $check | jq -r '.status ')
45
59
conclusion=$(echo $check | jq -r '.conclusion')
46
60
name=$(echo $check | jq -r '.name')
47
61
48
62
# EasyCLA success flag: state=SUCCESS
49
63
# 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"
70
71
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
71
87
# merge the PR
72
88
echo ========Merging PR========
73
89
if echo $title | grep "^\[submodule\]";then
77
93
fi
78
94
echo ========Finished PR========
79
95
done
96
+
0 commit comments