Setup gerrit.username properly with git-config
[releng/builder.git] / jjb / autorelease / branch-cut.sh
1 #!/bin/bash -l
2 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # This script requires the user running the script to have "Create References"
13 # permission in Gerrit for the "stable/RELEASE" branch. Where RELEASE is an
14 # official OpenDaylight release. Eg. Oxygen, Nitrogen, Carbon, etc...
15 #
16 # Performs 2 actions:
17 #
18 #     1) Creates a new branch stable/RELEASE (where release is a ODL release,
19 #        eg Oxygen, Nitrogen, Carbon, etc...)
20 #     2) Updates .gitreview in the new stable/RELEASE branch to set the
21 #        defaultbranch to the new branch.
22 #
23 # Required Parameters:
24 #     RELEASE: The name of the release to create a branch for.
25
26 mkdir -p "$WORKSPACE/archives"
27 LOG_FILE="$WORKSPACE/archives/branch-cut.log"
28
29 set -eu -o pipefail
30
31 # Validate inputs
32 if [ -z "$RELEASE" ]; then
33     echo "ERROR: RELEASE variable must be set to a release name. Eg Carbon"
34     exit 1
35 fi
36
37 # Setup Gerrit remote to ensure Change-Id gets set on commit.
38 git config --global --add gitreview.username "jenkins-$SILO"
39 git remote -v
40 git submodule foreach git review -s
41 git review -s
42
43 # --- Start create new maintenance branch
44 echo "---> Creating new mainenance branch"
45 git submodule foreach git fetch origin
46 git fetch origin
47 git submodule foreach git checkout -b "stable/${RELEASE,,}" origin/master
48 git checkout -b "stable/${RELEASE,,}" origin/master
49
50 ##########
51 # Verify #
52 ##########
53
54 {
55     echo "---> Verify maintenance branch"
56     git submodule foreach git branch
57     git branch
58 } | tee -a "$LOG_FILE"
59
60 ########
61 # Push #
62 ########
63
64 if [ "$DRY_RUN" = false ]
65 then
66     echo "Pushing stable/${RELEASE,,} branches to Gerrit"
67     git submodule foreach git push gerrit "stable/${RELEASE,,}"
68     git push gerrit "stable/$RELEASE"
69 fi
70 # --- End create new maintenance branch
71
72 # --- Start update .gitreview
73 echo "---> Update .gitreview"
74 git submodule foreach sed -i -e "s#defaultbranch=master#defaultbranch=stable/${RELEASE,,}#" .gitreview
75 git submodule foreach git add .gitreview
76 git submodule foreach "git commit -sm 'Update .gitreview to stable/${RELEASE,,}'"
77 sed -i -e "s#defaultbranch=master#defaultbranch=stable/${RELEASE,,}#" .gitreview
78 git add .gitreview
79 git commit -sm "Update .gitreview to stable/${RELEASE,,}"
80
81 # Generate git patches
82 patch_dir="$WORKSPACE/archives/patches/git-review"
83 mkdir -p "$patch_dir"
84 for module in $(git submodule | awk '{ print $2 }')
85 do
86     pushd "$module"
87     git format-patch --stdout "origin/master" > "$patch_dir/${module//\//-}.patch"
88     git bundle create "$patch_dir/${module//\//-}.bundle" "origin/master..HEAD"
89     popd
90 done
91
92 ##########
93 # Verify #
94 ##########
95
96 {
97     echo "---> Verify .gitreview"
98     git submodule foreach git show HEAD
99     git show HEAD
100     git submodule foreach git log --oneline -2 --graph --decorate
101     git log --oneline -2 --graph --decorate
102 } | tee -a "$LOG_FILE"
103
104 ########
105 # Push #
106 ########
107
108 if [ "$DRY_RUN" = false ]
109 then
110     echo "Pushing .gitreview patches to Gerrit"
111     git submodule foreach git review -t "branch-cut-${RELEASE,,}"
112     git review -t "branch-cut-${RELEASE,,}"
113 fi
114 # --- Stop update .gitreview