2022-11-29 21:28:06 -06:00
|
|
|
name: AutoMergeScan
|
|
|
|
on:
|
|
|
|
schedule:
|
|
|
|
- cron: '31 */2 * * *'
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
automerge_scan:
|
2023-01-30 02:57:39 -06:00
|
|
|
if: github.repository_owner == 'sonic-net'
|
2022-11-29 21:28:06 -06:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Debug
|
|
|
|
env:
|
|
|
|
TOKEN: ${{ secrets.TOKEN }}
|
|
|
|
run: |
|
|
|
|
set -e
|
|
|
|
|
|
|
|
echo ${TOKEN} | gh auth login --with-token
|
2023-09-07 00:34:34 -05:00
|
|
|
gh pr list -R sonic-net/sonic-buildimage -A mssonicbld -L 100 -S "label:automerge" --json url,body,title,createdAt,labels,statusCheckRollup > prs.log
|
2022-11-29 21:28:06 -06:00
|
|
|
cat prs.log | jq
|
|
|
|
- name: Main
|
|
|
|
run: |
|
|
|
|
set -e
|
|
|
|
|
2023-09-07 00:34:34 -05:00
|
|
|
# PR merge run per 2 hours
|
|
|
|
# Other operation run per day.
|
|
|
|
# Cherry pick PR:
|
|
|
|
# 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
|
|
|
|
date_3d_ago=$(date --date "3 day ago" -u +"%FT%TZ")
|
|
|
|
date_10d_ago=$(date --date "10 day ago" -u +"%FT%TZ")
|
|
|
|
date_28d_ago=$(date --date "28 day ago" -u +"%FT%TZ")
|
|
|
|
date_30d_ago=$(date --date "30 day ago" -u +"%FT%TZ")
|
|
|
|
date_now=$(date -u +"%T")
|
|
|
|
operate=false
|
|
|
|
[[ "$date_now" < "02:00:00" ]] && operate=true
|
|
|
|
|
2022-11-29 21:28:06 -06:00
|
|
|
count=$(cat prs.log | jq 'length')
|
|
|
|
for ((i=0;i<$count;i++))
|
|
|
|
do
|
|
|
|
url=$(cat prs.log | jq -r ".[$i].url")
|
2023-06-18 19:31:56 -05:00
|
|
|
body=$(cat prs.log | jq -r ".[$i].body")
|
|
|
|
title=$(cat prs.log | jq -r ".[$i].title")
|
2023-09-07 00:34:34 -05:00
|
|
|
origin_pr_id=$(echo $title | grep -Eo "\[action\] \[PR:[0-9]*\]" | grep -Eo [0-9]* || true)
|
2022-11-29 21:28:06 -06:00
|
|
|
created_at=$(cat prs.log | jq -r ".[$i].createdAt")
|
2023-09-07 00:34:34 -05:00
|
|
|
echo PR: $(($i+1))/$count, URL: $url, origin PR: $origin_pr_id, createdAt: $created_at, operate: $operate
|
2022-11-29 21:28:06 -06:00
|
|
|
[[ "$url" == "" ]] && continue
|
|
|
|
[[ $created_at > $(date --date "1 hour ago" -u +"%FT%TZ") ]] && continue
|
2023-03-10 00:14:51 -06:00
|
|
|
|
2022-11-29 21:28:06 -06:00
|
|
|
checks=$(cat prs.log | jq ".[$i].statusCheckRollup")
|
|
|
|
checks_count=$(echo $checks | jq 'length')
|
2023-09-07 00:34:34 -05:00
|
|
|
pr_success=true
|
2022-11-29 21:28:06 -06:00
|
|
|
for ((j=0;j<$checks_count;j++))
|
|
|
|
do
|
|
|
|
check=$(echo $checks | jq ".[$j]")
|
2023-09-07 00:34:34 -05:00
|
|
|
status=$(echo $check | jq -r '.status')
|
2022-11-29 21:28:06 -06:00
|
|
|
conclusion=$(echo $check | jq -r '.conclusion')
|
2023-03-10 00:14:51 -06:00
|
|
|
name=$(echo $check | jq -r '.name')
|
2022-11-29 21:28:06 -06:00
|
|
|
|
|
|
|
# EasyCLA success flag: state=SUCCESS
|
|
|
|
# Others success flag: conclusion in SUCCESS,NEUTRAL
|
2023-09-07 00:34:34 -05:00
|
|
|
# only check Azure.sonic-buildimage currently
|
|
|
|
echo "$name" | grep -v "Azure.sonic-buildimage" > /dev/null && continue
|
|
|
|
[[ "$status" != "COMPLETED" ]] && echo "$name: $status" && continue 2
|
|
|
|
|
|
|
|
success=true
|
|
|
|
( [[ "$conclusion" == "FAILURE" ]] || [[ "$conclusion" == "CANCELLED" ]] ) && success=false && pr_success=false
|
|
|
|
! $success && echo "FAIL: $name"
|
2022-11-29 21:28:06 -06:00
|
|
|
done
|
2023-09-07 00:34:34 -05:00
|
|
|
|
|
|
|
# rerun Azure.sonic-buildimage per day
|
|
|
|
! $pr_success && $operate && gh pr comment $url --body "/azp run Azure.sonic-buildimage"
|
|
|
|
|
|
|
|
# If auto cherry pick PRs failed, comment in original PR and close cherry pick PR
|
|
|
|
if [ -n "$origin_pr_id" ] && [[ $created_at < $date_3d_ago ]] && ! $pr_success;then
|
|
|
|
origin_pr_url=https://github.com/sonic-net/sonic-buildimage/pull/$origin_pr_id
|
|
|
|
author=$(gh pr view $origin_pr_url --json author | jq .author.login -r)
|
|
|
|
echo "Original author will check."
|
|
|
|
$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"
|
|
|
|
$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"
|
|
|
|
$operate && [[ $created_at < $date_30d_ago ]] && echo "$url Closed" && gh pr close $url
|
|
|
|
fi
|
|
|
|
|
|
|
|
! $pr_success && continue
|
2022-11-29 21:28:06 -06:00
|
|
|
# merge the PR
|
|
|
|
echo ========Merging PR========
|
2023-06-18 19:31:56 -05:00
|
|
|
if echo $title | grep "^\[submodule\]";then
|
|
|
|
gh pr merge --squash --admin -R sonic-net/sonic-buildimage $url -b "$body" || true
|
|
|
|
else
|
|
|
|
gh pr merge --rebase --admin -R sonic-net/sonic-buildimage $url || true
|
|
|
|
fi
|
2022-11-29 21:28:06 -06:00
|
|
|
echo ========Finished PR========
|
|
|
|
done
|
2023-09-07 00:34:34 -05:00
|
|
|
|