-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial backports automation #21
Open
squidadm
wants to merge
3
commits into
main
Choose a base branch
from
add-backports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this convoluted
.BASE
hack and related manipulation, I suggest makingsrcbranch
a script parameter withmaster
(or the main official repository branch name if you want to compute that to avoid hard-codingmaster
) as its default value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you propose that script parameter comes from? The script running this script only has the "/path/to/repo" and "vN" branch name available. The requirement to use "master" for development prohibits using
git branch
to determine if there is a newer vN branch existing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact answer depends on how this script is used in its environment. If I were to design this, and I wanted the script to run unattended by default, then
However, I am not implying that something like the above is the best solution, or even that this PR should become hostage to changing the environment to make something like that possible. I am just answering your question, with the rather limited information that I have about the existing environment and, more importantly, about environmental changes you are willing to adopt. Ideally, the whole environment should be designed with certain maintenance automation goals/principles in mind, and I doubt we share those today.