diff --git a/maintenance/code-backports.sh b/maintenance/code-backports.sh new file mode 100755 index 0000000..13d1427 --- /dev/null +++ b/maintenance/code-backports.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +# silence debug output from VCS +beQuiet="--quiet" +#beQuiet="" +verpath="$1" +version=`basename "$verpath" | sed s/squid-//` +vnext=$(( $version + 1 )) +srcbranch=v$vnext + +cd $verpath + +# Dev branch does not receive backports +test -f .BASE && exit 0 + +# clean the current workspace +gitCleanWorkspace () +{ + git clean $beQuiet -xdf --exclude="\.BASE" + git checkout $beQuiet -- . +} + +if ! test -d .git ; then + echo "ERROR: missing git repository" + exit 1; +fi +if ! test -d ../squid-$vnext ; then + echo "ERROR: missing git repository to backport from" + exit 1; +fi +if test -e ../squid-$vnext/.BASE ; then + srcbranch=`cat ../squid-$vnext/.BASE` +fi + +abortAndExit () +{ + git $1 --abort 2>&1 >/dev/null + exit 1 +} + +abortAndContinue () +{ + git $1 --abort 2>&1 >/dev/null || true +} + +# Prepare backports branch for updates +git checkout $beQuiet v$version-next-backports 2>/dev/null && + gitCleanWorkspace && + git fetch $beQuiet --all && + git pull $beQuiet origin v$version-next-backports && + git rebase origin/v$version 2>/dev/null && + git push -u origin +v$version-next-backports || abortAndExit rebase + +# Find backports to attempt: +prlist=`gh pr list -L 1 --repo squid-cache/squid --state closed --label backport-to-v$version | wc -l` +if test "$prlist" -ne 0; then + gh pr list --repo squid-cache/squid --state closed --label backport-to-v$version | while read prnum text; do + # find a commit in $srcbranch with " (#$prnum)" subject suffix + git log --oneline github/$srcbranch --grep=" (#$prnum)\$" | while read sha rest; do + msg=`git cherry-pick $beQuiet $sha 2>&1 || abortAndContinue cherry-pick` + if ! test -z "$msg" ; then + echo "$msg" | grep -E "^error:" + unlabel=`echo "$msg" | grep -E "The.previous.cherry-pick.is.now.empty"` + if ! test -z "$unlabel" ; then + gh pr edit --repo squid-cache/squid $prnum --remove-label backport-to-v$version + gh pr comment --repo squid-cache/squid $prnum --body "queued for backport to v$version" + fi + fi + gitCleanWorkspace + done + done + git push $beQuiet 2>&1 >/dev/null || true + + # Create a PR to merge (if needed) + if test `git diff github/$srcbranch v$version-next-backports 2>/dev/null | wc -l` -ne 0 ; then + git push $beQuiet -u origin +v$version-next-backports >/dev/null || exit 1 + # skip if there is an existing PR already open awaiting merge + prlist=`gh pr list -L 1 --repo squid-cache/squid --head v$version-next-backports | wc -l` + if test "$prlist" -eq 0 ; then + gh pr create --repo squid-cache/squid --base v$version --title "v$version Next Backports" --body "" || true + fi + fi + +fi diff --git a/maintenance/code-maintenance.sh b/maintenance/code-maintenance.sh index 75a1644..7e514c5 100755 --- a/maintenance/code-maintenance.sh +++ b/maintenance/code-maintenance.sh @@ -21,6 +21,12 @@ gitCleanWorkspace () git checkout $beQuiet -- . } +abortAndExit () +{ + git "$1" --abort 2>&1 >/dev/null + exit 1 +} + runMaintenanceScript () { script=$1 @@ -29,18 +35,18 @@ runMaintenanceScript () if test -x "$script" ; then - git checkout $beQuiet $forkPoint 2>/dev/null && - git checkout $beQuiet $branch 2>/dev/null && + git checkout $beQuiet $forkPoint 2>&1 >/dev/null && + git checkout $beQuiet $branch 2>&1 >/dev/null && gitCleanWorkspace && - git rebase github/$forkPoint 2>/dev/null || ( git rebase --abort 2>/dev/null ; exit 1 ) + git rebase github/$forkPoint 2>&1 >/dev/null || abortAndExit rebase gitCleanWorkspace && $script >/dev/null || exit 1 # only update modified files. Ignore deleted, added, etc. - git status 2>&1 | grep "modified:" | while read a b; do git add $b; done - git commit $beQuiet --all -m "$prtitle" || true - git push $beQuiet -f --set-upstream origin +$branch || exit 1 + git status 2>&1 | grep "modified:" | while read a b; do git add $beQuiet $b >/dev/null; done + git commit $beQuiet --all -m "$prtitle" >/dev/null || true + git push $beQuiet -f --set-upstream origin +$branch >/dev/null || exit 1 gitCleanWorkspace if test `git diff $beQuiet $forkPoint $branch 2>/dev/null | wc -l` -ne 0 ; then @@ -56,7 +62,6 @@ runMaintenanceScript () fi } - ( cd $1 version=`basename "$1" | sed s/squid-//` @@ -71,20 +76,21 @@ runMaintenanceScript () exit 1; fi - git fetch $beQuiet --all + git fetch $beQuiet --all >/dev/null gitCleanWorkspace - git pull $beQuiet --all + # Update version branch to match github + git checkout $beQuiet $forkPoint >/dev/null + + git pull $beQuiet --all >/dev/null gitCleanWorkspace - # Update version branch to match github - git checkout $beQuiet $forkPoint # ON CONFLICTS: abort - git rebase github/$forkPoint || ( git rebase --abort ; exit 1 ) + git rebase github/$forkPoint >/dev/null || abortAndExit rebase gitCleanWorkspace - git push $beQuiet -f --set-upstream origin +$forkPoint 2>&1 - git push $beQuiet --tags github + git push $beQuiet -f --set-upstream origin +$forkPoint 2>&1 >/dev/null + git push $beQuiet --tags github 2>&1 >/dev/null gitCleanWorkspace runMaintenanceScript ./bootstrap.sh v$version-bootstrap "Bootstrapped"