Fix: Upgrade global-jjb to v0.90.7
[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 # shellcheck disable=SC1090
32 . ~/lf-env.sh
33
34 lf-activate-venv --python python3 "git-review==2.3.1"
35
36 # Validate inputs
37 if [ -z "$RELEASE" ]; then
38     echo "ERROR: RELEASE variable must be set to a release name. Eg Carbon"
39     exit 1
40 fi
41
42 # Workaround for git-review failing to copy the commit-msg hook to submodules
43 git config core.hooksPath "$(git rev-parse --show-toplevel)/.git/hooks"
44
45 # Setup Gerrit remote to ensure Change-Id gets set on commit.
46 git config --global --add gitreview.username "jenkins-$SILO"
47 git remote -v
48 git submodule foreach git review -s
49 git review -s
50
51 # --- Start create new maintenance branch
52 echo "---> Creating new mainenance branch"
53 git submodule foreach git fetch origin
54 git fetch origin
55 git submodule foreach git checkout -b "stable/${RELEASE,,}" origin/master
56 git checkout -b "stable/${RELEASE,,}" origin/master
57
58 ##########
59 # Verify #
60 ##########
61
62 {
63     echo "---> Verify maintenance branch"
64     git submodule foreach git branch
65     git branch
66 } | tee -a "$LOG_FILE"
67
68 ########
69 # Push #
70 ########
71
72 if [ "$DRY_RUN" = false ]
73 then
74     echo "Pushing stable/${RELEASE,,} branches to Gerrit"
75     git submodule foreach git push gerrit "stable/${RELEASE,,}"
76     git push gerrit "stable/${RELEASE,,}"
77 fi
78 # --- End create new maintenance branch
79
80 # --- Start update .gitreview
81 echo "---> Update .gitreview"
82 git submodule foreach sed -i -e "s#defaultbranch=master#defaultbranch=stable/${RELEASE,,}#" .gitreview
83 git submodule foreach git add .gitreview
84 git submodule foreach "git commit -sm 'Update .gitreview to stable/${RELEASE,,}'"
85 sed -i -e "s#defaultbranch=master#defaultbranch=stable/${RELEASE,,}#" .gitreview
86 git add .gitreview
87 git commit -sm "Update .gitreview to stable/${RELEASE,,}"
88
89 # Generate git patches
90 patch_dir="$WORKSPACE/archives/patches/git-review"
91 mkdir -p "$patch_dir"
92 for module in $(git submodule | awk '{ print $2 }')
93 do
94     pushd "$module"
95     git format-patch --stdout "origin/master" > "$patch_dir/${module//\//-}.patch"
96     git bundle create "$patch_dir/${module//\//-}.bundle" "origin/master..HEAD"
97     popd
98 done
99
100 ##########
101 # Verify #
102 ##########
103
104 {
105     echo "---> Verify .gitreview"
106     git submodule foreach git show HEAD
107     git show HEAD
108     git submodule foreach git log --oneline -2 --graph --decorate
109     git log --oneline -2 --graph --decorate
110 } | tee -a "$LOG_FILE"
111
112 ########
113 # Push #
114 ########
115
116 if [ "$DRY_RUN" = false ]
117 then
118     echo "Pushing .gitreview patches to Gerrit"
119     git submodule foreach git review -t "branch-cut-${RELEASE,,}"
120     git review -t "branch-cut-${RELEASE,,}"
121 fi
122 # --- Stop update .gitreview