11#! /usr/bin/env bash
22
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-
73# Clippy ascii art copied from https://github.com/gbigwood/Clippo
84echo -e "
95################################################
@@ -17,243 +13,13 @@ echo -e "
1713
1814A new merge script is available using ` ng-dev` !
1915
20- In the future, this script will be removed in
21- favor of using ng-dev.
22-
2316To merge a pr using the new tooling run:
2417
2518$ yarn -s ng-dev pr merge <pr-number>
2619
27- ################################################"
28- # Sleep a short time to highlight deprecate notice.
29- sleep 2;
30-
31- BOLD=' printf \e[1m'
32- RESET_STYLES=' printf \e[0m'
33- LIGHT_CYAN=' printf \e[96m'
34- LIGHT_MAGENTA=' printf \e[95m'
35- GREEN=' printf \e[32m'
36- RED=' printf \e[31m'
37-
38- BASEDIR=$( dirname " $0 " )
39- BASEDIR=` (cd $BASEDIR ; pwd)`
40-
41- PR_NUMBER=0
42- PUSH_UPSTREAM=1
43- FORCE=0
44- while [[ $# -gt 0 ]]
45- do
46- key=" $1 "
47-
48- case $key in
49- --dryrun)
50- PUSH_UPSTREAM=0
51- shift # past argument
52- ;;
53- --force)
54- FORCE=1
55- shift # past argument
56- ;;
57- * ) # unknown option
58- PR_NUMBER=" $1 " # save it in an array for later
59- shift # past argument
60- ;;
61- esac
62- done
63-
64- if [ " $PR_NUMBER " -eq 0 ]; then
65- echo " Merge github PR into the target branches if status is green"
66- echo
67- echo " $0 PR_NUMBER [--dryrun] [--force]"
68- echo
69- echo --dryrun Performs all operations but does not push the merge back to
[email protected] :angular/angular.git.
70- echo --force Continues even if PR status is not green.
71- exit 0
72- fi
73-
74- if [ -z ${TOKEN:- ' ' } ]; then
75- $RED
76- echo " ############################################################"
77- echo " ############################################################"
78- echo " WARNING: you should set the TOKEN variable to a github token"
79- echo " ############################################################"
80- echo " ############################################################"
81- $RESET_STYLES
82- GH_AUTH=" "
83- else
84- GH_AUTH=" Authorization: token $TOKEN "
85- fi
86-
87- PULL_JSON=` curl -H " $GH_AUTH " -s https://api.github.com/repos/angular/angular/pulls/$PR_NUMBER `
88- PR_SHA_COUNT=` node $BASEDIR /utils/json_extract.js commits <<< " " " $PULL_JSON " " " `
89- STATUS_JSON_URL=` node $BASEDIR /utils/json_extract.js _links.statuses.href <<< " " " $PULL_JSON " " " `
90- STATUS=` curl -H " $GH_AUTH " -s $STATUS_JSON_URL | node $BASEDIR /utils/json_extract.js description | cut -d ' |' -f1`
91- PR_LABELS=` curl -H " $GH_AUTH " -s https://api.github.com/repos/angular/angular/issues/$PR_NUMBER /labels`
92- PR_ACTION=` echo " $PR_LABELS " | node $BASEDIR /utils/json_extract.js " name=^PR action:" `
93- PR_TARGET=` echo " $PR_LABELS " | node $BASEDIR /utils/json_extract.js " name=^PR target:" `
94- PR_CLA=` echo " $PR_LABELS " | node $BASEDIR /utils/json_extract.js " name=^cla" `
95- MASTER_BRANCH=' master'
9620
97- if [[ ! " $PR_ACTION " =~ " PR action: merge" ]]; then
98- $RED
99- echo The PR is missing ' PR action: merge(-assistance)' label, found: $PR_ACTION
100- $RESET_STYLES
101- exit 1
102- fi
103-
104- if [[ " $PR_CLA " != " cla: yes" ]]; then
105- $RED
106- echo The PR is missing ' cla: Yes' label, found: $PR_CLA
107- $RESET_STYLES
108- exit 1
109- fi
110-
111- if [[ " $STATUS " != " All checks passed!" ]]; then
112- echo PR $PR_NUMBER is failing with: $STATUS
113- if [[ $FORCE == 1 ]]; then
114- $BOLD
115- $LIGHT_MAGENTA
116- echo FORCING: --force flag used to ignore PR status.
117- $RESET_STYLES
118- else
119- echo Exiting...
120- exit 1
121- fi
122- fi
123-
124- if [[ $PR_TARGET == " PR target: master & patch" ]]; then
125- MERGE_MASTER=1
126- MERGE_PATCH=1
127- elif [[ $PR_TARGET == " PR target: master-only" ]]; then
128- MERGE_MASTER=1
129- MERGE_PATCH=0
130- elif [[ $PR_TARGET == " PR target: patch-only" ]]; then
131- MERGE_MASTER=0
132- MERGE_PATCH=1
133- else
134- $RED
135- echo " Unknown PR target format: $PR_TARGET "
136- $RESET_STYLES
137- exit 1;
138- fi
139-
140- CURRENT_BRANCH=` git rev-parse --abbrev-ref HEAD`
141- PATCH_BRANCH=
` git ls-remote --heads [email protected] :angular/angular.git | grep -E ' refs\/heads\/[0-9]+\.[0-9]+\.x' | cut -d ' /' -f3 | sort -r | head -n1` 142-
143- CHECKOUT_MASTER=" git checkout merge_pr_master"
144- CHECKOUT_PATCH=" git checkout merge_pr_patch"
145- RESTORE_BRANCH=" git checkout $CURRENT_BRANCH "
146-
147- FETCH_PR=
" git fetch [email protected] :angular/angular.git pull/$PR_NUMBER /head:merge_pr heads/$MASTER_BRANCH :merge_pr_master heads/$PATCH_BRANCH :merge_pr_patch -f" 148- BASE_PR=" git checkout merge_pr~$PR_SHA_COUNT -B merge_pr_base"
149- SQUASH_PR=" git rebase --autosquash --interactive merge_pr_base merge_pr"
150- REWRITE_MESSAGE=" git filter-branch -f --msg-filter \" $BASEDIR /utils/github_closes.js $PR_NUMBER \" merge_pr_base..merge_pr"
151- PUSH_BRANCHES=
" git push [email protected] :angular/angular.git merge_pr_master:$MASTER_BRANCH merge_pr_patch:$PATCH_BRANCH " 152- CHERRY_PICK_PR=" git cherry-pick merge_pr_base..merge_pr"
153-
154- # Checks that each PR branch to be merged upstream contains SHAs of commits that significantly changed our CI infrastructure.
155- #
156- # This check is used to enforce that we don't merge PRs that have not been rebased recently and could result in merging
157- # of non-approved or otherwise bad changes.
158- REQUIRED_BASE_SHA_MASTER=" 4341743b4a6d7e23c6f944aa9e34166b701369a1" # `commit-message` script update
159- REQUIRED_BASE_SHA_PATCH=" 2a53f471592f424538802907aca1f60f1177a86d" # `commit-message` script update
160- if [[ $MERGE_MASTER == 1 ]]; then
161- REQUIRED_BASE_SHA=" $REQUIRED_BASE_SHA_MASTER "
162- # check patch only if patch-only PR
163- elif [[ $MERGE_PATCH == 1 ]]; then
164- REQUIRED_BASE_SHA=" $REQUIRED_BASE_SHA_PATCH "
165- fi
166- CHECK_IF_PR_REBASED=" git branch --quiet merge_pr --contains $REQUIRED_BASE_SHA "
167-
168- $BOLD
169- $LIGHT_CYAN
170- echo " ======================"
171- echo " GitHub Merge PR Steps"
172- echo " ======================"
173- echo " $FETCH_PR "
174- echo " $BASE_PR "
175- echo " $CHECK_IF_PR_REBASED "
176- echo " $SQUASH_PR "
177- echo " $REWRITE_MESSAGE "
178- if [[ $MERGE_MASTER == 1 ]]; then
179- echo " $CHECKOUT_MASTER && $CHERRY_PICK_PR "
180- fi
181- if [[ $MERGE_PATCH == 1 ]]; then
182- echo " $CHECKOUT_PATCH && $CHERRY_PICK_PR "
183- fi
184- echo " $PUSH_BRANCHES "
185- echo " $RESTORE_BRANCH "
186- echo " ----------------------"
187- $RESET_STYLES
188- $BOLD
189- echo " "
190- echo " >>> Fetch PR: $FETCH_PR "
191- $RESET_STYLES
192- $FETCH_PR
193- $BOLD
194- echo " "
195- echo " >>> Mark base: $BASE_PR "
196- $RESET_STYLES
197- $BASE_PR
198- $BOLD
199- echo " "
200- echo " >>> Check if PR rebased: $CHECK_IF_PR_REBASED "
201- $RESET_STYLES
202- if [[ $( $CHECK_IF_PR_REBASED ) != " " ]]; then
203- $GREEN
204- echo " The PR is sufficiently rebased!"
205- $RESET_STYLES
206- else
207- $RED
208- echo " "
209- echo " "
210- echo " Failed to merge pull request #${PR_NUMBER} because it hasn't been rebased recently and could be bypassing new or updated CI checks!"
211- echo " "
212- echo " Please rebase the PR and try again."
213- echo " " |
214- $RESET_STYLES
215- $RESTORE_BRANCH
216- exit 1
217- fi
218- $BOLD
219- echo " "
220- echo " >>> Autosquash: $SQUASH_PR "
221- $RESET_STYLES
222- GIT_EDITOR=echo $SQUASH_PR
223- $BOLD
224- echo " "
225- echo " >>> Rewrite message: $REWRITE_MESSAGE "
226- # Next line should work, but it errors, hence copy paste the command.
227- # $REWRITE_MESSAGE
228- $RESET_STYLES
229- git filter-branch -f --msg-filter " $BASEDIR /utils/github_closes.js $PR_NUMBER " merge_pr_base..merge_pr
230- if [[ $MERGE_MASTER == 1 ]]; then
231- $BOLD
232- echo
233- echo " >>> Cherry pick to master: $CHECKOUT_MASTER && $CHERRY_PICK_PR "
234- $RESET_STYLES
235- $CHECKOUT_MASTER
236- $CHERRY_PICK_PR
237- fi
238- if [[ $MERGE_PATCH == 1 ]]; then
239- $BOLD
240- echo
241- echo " >>> Cherry pick to patch: $CHECKOUT_PATCH && $CHERRY_PICK_PR "
242- $RESET_STYLES
243- $CHECKOUT_PATCH
244- $CHERRY_PICK_PR
245- fi
246- $RESTORE_BRANCH
247-
248- if [[ $PUSH_UPSTREAM == 1 ]]; then
249- $BOLD
250- echo
251- echo " >>> Push branches to angular repo"
252- $RESET_STYLES
253- $PUSH_BRANCHES
254- fi
255- $BOLD
256- $GREEN
257- echo
258- echo " >>>>>> SUCCESS <<<<<< PR#$PR_NUMBER merged."
259- $RESET_STYLES
21+ This script has been fully deprecated as it no
22+ longer correctly determines branch targets due
23+ to how it determines the current version and
24+ defines patch branches.
25+ ################################################"
0 commit comments