Add some more automation to backport script

This commit is contained in:
Joshua M. Boniface 2020-12-31 19:09:56 -05:00
parent 3429017328
commit edf546cae6

View File

@ -2,42 +2,40 @@
# Backport JF PRs to release branch # Backport JF PRs to release branch
project="${1}" org="jellyfin"
release_branch="${2}"
if [[ -z ${project} ]]; then echo "Please select the repo you want to work on:"
echo "Please select the project you want to work on:" echo -e " jellyfin"
echo -e " jellyfin" echo -e " jellyfin-web"
echo -e " jellyfin-web" echo -n "> "
echo -n "> " read repo
read project if [[ ${repo} != 'jellyfin' && ${repo} != 'jellyfin-web' ]]; then
fi echo "Invalid repo!"
if [[ ${project} != 'jellyfin' && ${project} != 'jellyfin-web' ]]; then
echo "Invalid project!"
exit 1 exit 1
fi fi
pushd projects/server/${repo}
pushd projects/server/${project} upstream_repo="${org}/${repo}"
remote="$( grep -w --color=none "${upstream_repo}" <<<"$( git remote -v )" | grep 'fetch' | awk '{ print $1 }' )"
upstream_project="jellyfin/${project}"
remote="$( grep -w --color=none "${upstream_project}" <<<"$( git remote -v )" | grep 'fetch' | awk '{ print $1 }' )"
echo "Project remote: ${remote}" echo "Project remote: ${remote}"
current_branch="$( git branch | grep '^*' | awk '{ print $NF }' )" current_branch="$( git branch | grep '^*' | awk '{ print $NF }' )"
echo "Current branch: ${current_branch}" echo "Current branch: ${current_branch}"
if [[ -z ${release_branch} ]]; then echo "Please select the release branch you want to apply backports to:"
echo "Please select the release branch you want to apply backports to:" git branch | grep --color=none 'release-'
git branch | grep --color=none 'release-' echo -n "> "
echo -n "> " read release_branch
read release_branch
fi
if ! grep -qwo "${release_branch}" <<<"$( git branch )"; then if ! grep -qwo "${release_branch}" <<<"$( git branch )"; then
echo "Invalid branch!" echo "Invalid branch!"
exit 1 exit 1
fi fi
echo "Please enter the release project name (e.g. 'Release 10.7.0')"
echo -n "> "
read gh_project
### REAL MEAT ### ### REAL MEAT ###
git checkout master git checkout master
git fetch --all git fetch --all
@ -48,7 +46,7 @@ if [[ $? -ne 0 ]]; then
fi fi
# Get all the stable-backport PRs # Get all the stable-backport PRs
backport_pr_list="$( gh pr list --limit 999 --state merged --label "stable backport" | sort -n | awk '{ print $1 }' | tr -d '#' )" backport_pr_list="$( gh pr list --limit 999 --state merged --label "stable backport" 2>/dev/null | sort -n | awk '{ print $1 }' | tr -d '#' )"
backport_merges=() backport_merges=()
echo "We will backport the following $( wc -w <<<"${backport_pr_list}" ) PRs:" echo "We will backport the following $( wc -w <<<"${backport_pr_list}" ) PRs:"
@ -59,7 +57,7 @@ read
echo echo
for pr in ${backport_pr_list}; do for pr in ${backport_pr_list}; do
merge_commit="$( hub pr show -f '%sm' ${pr} )" merge_commit="$( hub pr show -f '%sm' ${pr} 2>/dev/null )"
backport_merges+=( "${merge_commit}" ) backport_merges+=( "${merge_commit}" )
done done
@ -71,13 +69,30 @@ for merge in ${backport_merges[@]}; do
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Issue with cherry-pick! Review the changes in another terminal, run 'git add', then press <Enter>." echo "Issue with cherry-pick! Review the changes in another terminal, run 'git add', then press <Enter>."
read read
git cherry-pick --continue git cherry-pick --continue
fi fi
done done
echo
echo "Make sure everything is OK, then press <Enter> to push changes, remove labels, and update projects."
read
git push
export gh_project
gh_project_id="$( gh api -XGET -H'Accept:application/vnd.github.inertia-preview+json' "orgs/${org}/projects" 2>/dev/null | jq '.[] | select(.name==env.gh_project) | .id' )"
gh_project_completed_column_id="$( gh api -XGET -H'Accept:application/vnd.github.inertia-preview+json' "projects/${gh_project_id}/columns" 2>/dev/null | jq '.[] | select(.name=="Completed PRs") | .id' )"
gh_project_jellyfinished_column_id="$( gh api -XGET -H'Accept:application/vnd.github.inertia-preview+json' "projects/${gh_project_id}/columns" 2>/dev/null | jq '.[] | select(.name=="Jellyfinished") | .id' )"
for pr in ${backport_pr_list}; do
echo "Moving project card for PR ${pr}..."
export pr_url="https://api.github.com/repos/${org}/${repo}/issues/${pr}"
gh_project_card_id="$( gh api -XGET -H'Accept:application/vnd.github.inertia-preview+json' "projects/columns/${gh_project_completed_column_id}/cards" 2>/dev/null | jq '.[] | select(.content_url==env.pr_url) | .id' )"
gh api -XPOST -H'Accept:application/vnd.github.inertia-preview+json' /projects/columns/cards/${gh_project_card_id}/moves --field column_id=${gh_project_jellyfinished_column_id} --field position=bottom 2>/dev/null
echo "Removing backport label for PR ${pr}..."
gh api -XDELETE "repos/${org}/${repo}/issues/${pr}/labels/stable%20backport" 2>/dev/null
done
popd popd
echo
echo "You can now review and push the backports."
exit 0 exit 0