From a5db29924fc566894af7f303d2bf7ca1d1b28f4a Mon Sep 17 00:00:00 2001 From: Liu Shilong Date: Wed, 30 Nov 2022 11:28:06 +0800 Subject: [PATCH] [action] Add github action to merge mssonicbld's PRs which can be merged (#12564) * [action] Add github action to scan auto-mergeable PRs --- .github/workflows/automerge_scan.yml | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/automerge_scan.yml diff --git a/.github/workflows/automerge_scan.yml b/.github/workflows/automerge_scan.yml new file mode 100644 index 0000000000..d2c970a159 --- /dev/null +++ b/.github/workflows/automerge_scan.yml @@ -0,0 +1,59 @@ +name: AutoMergeScan +on: + schedule: + - cron: '31 */2 * * *' + workflow_dispatch: + +jobs: + automerge_scan: + 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