Skip to content

Commit 9dabeea

Browse files
IgorMinaralxhub
authored andcommitted
ci: add a rebase check to the merge-pr script (angular#28250)
Adds a check to verify that each PR branch to be merged upstream contains SHAs of commits that significantly changed our CI infrastructure. This check is used to enforce that we don't merge PRs that have not been rebased recently and could result in merging of non-approved or otherwise bad changes. PR Close angular#28250
1 parent 73dcd72 commit 9dabeea

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

scripts/github/merge-pr

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22

3-
set -u -e -o pipefail
3+
# https://www.tldp.org/LDP/abs/html/options.html#AEN19601
4+
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
5+
set -u -e -E -o pipefail
6+
47

58
BASEDIR=$(dirname "$0")
69
BASEDIR=`(cd $BASEDIR; pwd)`
@@ -107,11 +110,26 @@ REWRITE_MESSAGE="git filter-branch -f --msg-filter \"$BASEDIR/utils/github_close
107110
PUSH_BRANCHES="git push [email protected]:angular/angular.git merge_pr_master:$MASTER_BRANCH merge_pr_patch:$PATCH_BRANCH"
108111
CHERRY_PICK_PR="git cherry-pick merge_pr_base..merge_pr"
109112

113+
# Checks that each PR branch to be merged upstream contains SHAs of commits that significantly changed our CI infrastructure.
114+
#
115+
# This check is used to enforce that we don't merge PRs that have not been rebased recently and could result in merging
116+
# of non-approved or otherwise bad changes.
117+
REQUIRED_BASE_SHA_MASTER="3fba6eff79a9b50909199eaa4ebf754c1c4adba6" # pullapprove => CODEOWNERS migration
118+
REQUIRED_BASE_SHA_PATCH="e3853e842ea5c10fafbc310a76a4a7f47ed8c65e" # pullapprove => CODEOWNERS migration
119+
if [[ $MERGE_MASTER == 1 ]]; then
120+
REQUIRED_BASE_SHA="$REQUIRED_BASE_SHA_MASTER"
121+
# check patch only if patch-only PR
122+
elif [[ $MERGE_PATCH == 1 ]]; then
123+
REQUIRED_BASE_SHA="$REQUIRED_BASE_SHA_PATCH"
124+
fi
125+
CHECK_IF_PR_REBASED="git branch --quiet merge_pr --contains $REQUIRED_BASE_SHA"
126+
110127
echo "======================"
111128
echo "GitHub Merge PR Steps"
112129
echo "======================"
113130
echo " $FETCH_PR"
114131
echo " $BASE_PR"
132+
echo " $CHECK_IF_PR_REBASED"
115133
echo " $SQUASH_PR"
116134
echo " $REWRITE_MESSAGE"
117135
if [[ $MERGE_MASTER == 1 ]]; then
@@ -127,6 +145,19 @@ echo ">>> Fetch PR: $FETCH_PR"
127145
$FETCH_PR
128146
echo ">>> Mark base: $BASE_PR"
129147
$BASE_PR
148+
echo ">>> Check if PR rebased: $CHECK_IF_PR_REBASED"
149+
if [[ $($CHECK_IF_PR_REBASED) != "" ]]; then
150+
echo "The PR is sufficiently rebased!"
151+
else
152+
echo ""
153+
echo ""
154+
echo "Failed to merge pull request #${PR_NUMBER} because it hasn't been rebased recently and could be bypassing new or updated CI checks!"
155+
echo ""
156+
echo "Please rebase the PR and try again."
157+
echo ""
158+
$RESTORE_BRANCH
159+
exit 1
160+
fi
130161
echo ">>> Autosquash: $SQUASH_PR"
131162
GIT_EDITOR=echo $SQUASH_PR
132163
echo ">>> Rewrite message: $REWRITE_MESSAGE"
@@ -153,4 +184,3 @@ if [[ $PUSH_UPSTREAM == 1 ]]; then
153184
fi
154185
echo
155186
echo ">>>>>> SUCCESS <<<<<< PR#$PR_NUMBER merged."
156-

0 commit comments

Comments
 (0)