Skip to content

Commit c7c5214

Browse files
committed
build: merge PR to all branches per target: label (angular#21739)
PR Close angular#21739
1 parent 12f801e commit c7c5214

2 files changed

Lines changed: 54 additions & 34 deletions

File tree

docs/CARETAKER.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Caretaker is responsible for merging PRs into the individual branches and intern
55
## Responsibilities
66

77
- Draining the queue of PRs ready to be merged. (PRs with [`PR action: merge`](https://github.com/angular/angular/pulls?q=is%3Aopen+is%3Apr+label%3A%22PR+action%3A+merge%22) label)
8-
- Assigining [new issues](https://github.com/angular/angular/issues?q=is%3Aopen+is%3Aissue+no%3Alabel) to individual component authors.
8+
- Assigning [new issues](https://github.com/angular/angular/issues?q=is%3Aopen+is%3Aissue+no%3Alabel) to individual component authors.
99

1010
## Merging the PR
1111

@@ -19,12 +19,12 @@ $ ./scripts/github/merge-pr 1234
1919
```
2020

2121
The `merge-pr` script will:
22-
- Ensure that all approriate labels are on the PR.
23-
- That the current branch (`master` or `?.?.x` patch) mathches the `PR target: *` label.
22+
- Ensure that all appropriate labels are on the PR.
2423
- Fetches the latest PR code from the `angular/angular` repo.
25-
- It will `cherry-pick` all of the SHAs from the PR into the current branch.
24+
- It will `cherry-pick` all of the SHAs from the PR into the current corresponding branches `master` and or `?.?.x` (patch).
2625
- It will rewrite commit history by automatically adding `Close #1234` and `(#1234)` into the commit message.
2726

27+
NOTE: The `merge-pr` will land the PR on `master` and or `?.?.x` (patch) as described by `PR target: *` label.
2828

2929
### Recovering from failed `merge-pr` due to conflicts
3030

scripts/github/merge-pr

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BASEDIR=$(dirname "$0")
66
BASEDIR=`(cd $BASEDIR; pwd)`
77

88
if [ $# -eq 0 ]; then
9-
echo "Merge github PR into the current branch"
9+
echo "Merge github PR into the target branches"
1010
echo
1111
echo "$0 PR_NUMBER"
1212
echo
@@ -22,9 +22,7 @@ PR_TARGET=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^PR ta
2222
PR_CLA=`echo "$PR_LABELS" | node $BASEDIR/utils/json_extract.js "name=^cla"`
2323
MASTER_BRANCH='master'
2424
SHA=`git rev-parse HEAD`
25-
PATCH_BRANCH=`git branch --list '*.x' | cut -d ' ' -f2- | sort -r | head -n1`
26-
# Trim whitespace
27-
PATCH_BRANCH=`echo $PATCH_BRANCH`
25+
PATCH_BRANCH=`git ls-remote --heads [email protected]:angular/angular.git | grep -E 'refs\/heads\/\d+\.\d+\.x' | cut -d '/' -f3 | sort -r | head -n1`
2826

2927
if [[ "$PR_ACTION" != "PR action: merge" ]]; then
3028
echo The PR is missing 'PR action: merge' label, found: $PR_ACTION
@@ -51,43 +49,65 @@ else
5149
exit 1;
5250
fi
5351

54-
if [[ $CURRENT_BRANCH == $MASTER_BRANCH ]]; then
55-
if [[ $MERGE_MASTER == 0 ]]; then
56-
echo "This PR is not intended for master branch: $PR_TARGET"
57-
exit 1
58-
fi
59-
elif [[ $CURRENT_BRANCH == $PATCH_BRANCH ]]; then
60-
if [[ $MERGE_PATCH == 0 ]]; then
61-
echo "This PR is not intended for patch branch: $PR_TARGET"
62-
exit 1
63-
fi
64-
else
65-
echo "Current branch $CURRENT_BRANCH does not match $MASTER_BRANCH or $PATCH_BRANCH."
66-
exit 1
67-
fi
68-
6952

70-
FETCH_PR="git fetch https://github.com/angular/angular.git pull/$PR_NUMBER/head:angular/pr/$PR_NUMBER -f"
53+
CHECKOUT_MASTER="git checkout merge_pr_master"
54+
CHECKOUT_PATCH="git checkout merge_pr_$PATCH_BRANCH"
55+
RESTORE_BRANCH="git checkout $CURRENT_BRANCH"
56+
FETCH_PR="git fetch [email protected]:angular/angular.git pull/$PR_NUMBER/head:angular/pr/$PR_NUMBER heads/master:merge_pr_master heads/$PATCH_BRANCH:merge_pr_$PATCH_BRANCH -f"
57+
PUSH_BRANCHES="git push [email protected]:angular/angular.git merge_pr_master:master merge_pr_$PATCH_BRANCH:$PATCH_BRANCH"
7158
CHERRY_PICK_PR="git cherry-pick angular/pr/$PR_NUMBER~$PR_SHA_COUNT..angular/pr/$PR_NUMBER"
7259
REWRITE_MESSAGE="git filter-branch -f --msg-filter \"$BASEDIR/utils/github_closes.js $PR_NUMBER\" HEAD~$PR_SHA_COUNT..HEAD"
7360

7461
echo "======================"
7562
echo "GitHub Merge PR Steps"
7663
echo "======================"
7764
echo " $FETCH_PR"
78-
echo " $CHERRY_PICK_PR"
79-
echo " $REWRITE_MESSAGE"
65+
if [[ $MERGE_MASTER == 1 ]]; then
66+
echo " $CHECKOUT_MASTER"
67+
echo " $CHERRY_PICK_PR"
68+
echo " $REWRITE_MESSAGE"
69+
fi
70+
if [[ $MERGE_PATCH == 1 ]]; then
71+
echo " $CHECKOUT_PATCH"
72+
echo " $CHERRY_PICK_PR"
73+
echo " $REWRITE_MESSAGE"
74+
fi
75+
echo " $PUSH_BRANCHES"
76+
echo " $RESTORE_BRANCH"
8077
echo "----------------------"
8178

82-
echo ">>> Cherry Pick: $CHERRY_PICK_PR"
8379
$FETCH_PR
84-
$CHERRY_PICK_PR
80+
if [[ $MERGE_MASTER == 1 ]]; then
81+
echo
82+
echo ">>> Checkout master: $CHECKOUT_MASTER"
83+
$CHECKOUT_MASTER
84+
echo
85+
echo ">>> Cherry pick pr: $CHERRY_PICK_PR"
86+
$CHERRY_PICK_PR
87+
echo
88+
echo ">>> Rewrite message: $REWRITE_MESSAGE"
89+
# Next line should work, but it errors, hence copy paste the command.
90+
# $REWRITE_MESSAGE
91+
git filter-branch -f --msg-filter "$BASEDIR/utils/github_closes.js $PR_NUMBER" HEAD~$PR_SHA_COUNT..HEAD
8592

86-
echo
87-
echo ">>> Rewrite Messages: $REWRITE_MESSAGE"
88-
# Next line should work, but it errors, hence copy paste the command.
89-
# $REWRITE_MESSAGE
90-
git filter-branch -f --msg-filter "$BASEDIR/utils/github_closes.js $PR_NUMBER" HEAD~$PR_SHA_COUNT..HEAD
93+
fi
94+
if [[ $MERGE_PATCH == 1 ]]; then
95+
echo
96+
echo ">>> Checkout $PATCH_BRANCH: $CHECKOUT_PATCH"
97+
$CHECKOUT_PATCH
98+
echo
99+
echo ">>> Cherry pick pr: $CHERRY_PICK_PR"
100+
$CHERRY_PICK_PR
101+
echo
102+
echo ">>> Rewrite message: $REWRITE_MESSAGE"
103+
# Next line should work, but it errors, hence copy paste the command.
104+
# $REWRITE_MESSAGE
105+
git filter-branch -f --msg-filter "$BASEDIR/utils/github_closes.js $PR_NUMBER" HEAD~$PR_SHA_COUNT..HEAD
106+
fi
107+
$RESTORE_BRANCH
91108

109+
echo ">>> Push branches to angular repo"
110+
$PUSH_BRANCHES
92111
echo
93-
echo ">>>>>> SUCCESS <<<<<<"
112+
echo ">>>>>> SUCCESS <<<<<< PR#$PR_NUMBER merged."
113+

0 commit comments

Comments
 (0)