Skip to content

Commit 2647593

Browse files
committed
chore: make release script create PRs for protected branches
Signed-off-by: Mykhailo Kuznietsov <mkuznets@redhat.com>
1 parent 33a8c8e commit 2647593

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

make-release.sh

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ releaseMachineExec() {
5454
echo "Pushed ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${VERSION}"
5555
}
5656

57+
commitChangeOrCreatePR()
58+
{
59+
if [[ ${NOCOMMIT} -eq 1 ]]; then
60+
echo "[INFO] NOCOMMIT = 1; so nothing will be committed. Run this script with no flags for usage + list of flags/options."
61+
else
62+
aVERSION="$1"
63+
aBRANCH="$2"
64+
PR_BRANCH="$3"
65+
66+
COMMIT_MSG="chore: release: bump to ${aVERSION} in ${aBRANCH}"
67+
68+
# commit change into branch
69+
git add -A || true
70+
git commit -s -m "${COMMIT_MSG}"
71+
git pull origin "${aBRANCH}"
72+
73+
PUSH_TRY="$(git push origin "${aBRANCH}")"
74+
# shellcheck disable=SC2181
75+
if [[ $? -gt 0 ]] || [[ $PUSH_TRY == *"protected branch hook declined"* ]]; then
76+
# create pull request for main branch, as branch is restricted
77+
git branch "${PR_BRANCH}"
78+
git checkout "${PR_BRANCH}"
79+
git pull origin "${PR_BRANCH}"
80+
git push origin "${PR_BRANCH}"
81+
gh pr create -f -B "${aBRANCH}" -H "${PR_BRANCH}"
82+
fi
83+
fi
84+
}
85+
5786
# derive branch from version
5887
BRANCH=${VERSION%.*}.x
5988

@@ -85,6 +114,7 @@ if [[ ${NOCOMMIT} -eq 0 ]]; then
85114
git commit -s -m "${COMMIT_MSG}" VERSION
86115
git pull origin "${BRANCH}"
87116
git push origin "${BRANCH}"
117+
commitChangeOrCreatePR "${VERSION}" "${BRANCH}" "pr-${BRANCH}-to-${NEXTVERSION}"
88118
fi
89119

90120
if [[ $TRIGGER_RELEASE -eq 1 ]]; then
@@ -115,21 +145,5 @@ fi
115145
# change VERSION file
116146
echo "${NEXTVERSION}" > VERSION
117147
if [[ ${NOCOMMIT} -eq 0 ]]; then
118-
BRANCH=${BASEBRANCH}
119-
# commit change into branch
120-
COMMIT_MSG="chore: release: bump to ${NEXTVERSION} in ${BRANCH}"
121-
git commit -s -m "${COMMIT_MSG}" VERSION
122-
git pull origin "${BRANCH}"
123-
124-
PUSH_TRY="$(git push origin "${BRANCH}")"
125-
# shellcheck disable=SC2181
126-
if [[ $? -gt 0 ]] || [[ $PUSH_TRY == *"protected branch hook declined"* ]]; then
127-
PR_BRANCH=pr-main-to-${NEXTVERSION}
128-
# create pull request for main branch, as branch is restricted
129-
git branch "${PR_BRANCH}"
130-
git checkout "${PR_BRANCH}"
131-
git pull origin "${PR_BRANCH}"
132-
git push origin "${PR_BRANCH}"
133-
gh pr create -f -B "${BRANCH}" -H "${PR_BRANCH}"
134-
fi
148+
commitChangeOrCreatePR "$NEXTVERSION" "$BASEBRANCH" pr-main-to-${NEXTVERSION}
135149
fi

0 commit comments

Comments
 (0)