forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (56 loc) · 2.37 KB
/
automerge_scan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: AutoMergeScan
on:
schedule:
- cron: '31 */2 * * *'
workflow_dispatch:
jobs:
automerge_scan:
if: github.repository_owner == 'sonic-net'
runs-on: ubuntu-latest
steps:
- name: Debug
env:
TOKEN: ${{ secrets.TOKEN }}
run: |
set -e
echo ${TOKEN} | gh auth login --with-token
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
cat prs.log | jq
- name: Main
run: |
set -e
count=$(cat prs.log | jq 'length')
for ((i=0;i<$count;i++))
do
url=$(cat prs.log | jq -r ".[$i].url")
created_at=$(cat prs.log | jq -r ".[$i].createdAt")
echo PR: $(($i+1))/$count, URL: $url, createdAt: $created_at, now: $(date -u +"%FT%TZ")
[[ "$url" == "" ]] && continue
[[ $created_at > $(date --date "1 hour ago" -u +"%FT%TZ") ]] && continue
checks=$(cat prs.log | jq ".[$i].statusCheckRollup")
checks_count=$(echo $checks | jq 'length')
echo Checks count: $checks_count
for ((j=0;j<$checks_count;j++))
do
check=$(echo $checks | jq ".[$j]")
state=$(echo $check | jq -r '.state')
conclusion=$(echo $check | jq -r '.conclusion')
# EasyCLA success flag: state=SUCCESS
# Others success flag: conclusion in SUCCESS,NEUTRAL
if [[ "$state" == "SUCCESS" ]];then
# check pass
continue
elif [[ "$conclusion" == "SUCCESS" ]] || [[ "$conclusion" == "NEUTRAL" ]];then
# check pass
continue
else
echo "$url Check failed!!!"
echo $check | jq
continue 2
fi
done
# merge the PR
echo ========Merging PR========
gh pr merge --rebase --admin -R sonic-net/sonic-buildimage $url || true
echo ========Finished PR========
done