Merge "Support branch-cutting version bump workflow"
[releng/builder.git] / jjb / autorelease / version-bump.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: 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 performs version bumping activities for an ODL release and branch
13 # cutting.
14 echo "---> version-bump.sh"
15
16 # The only purpose of RELEASE_TAG in this script is to set the Gerrit topic.
17 # It is also used as a placeholder for version bumping but gets wiped out
18 # immediately to bump versions by x.y.(z+1).
19 RELEASE_TAG="${STREAM^}"
20
21 mkdir -p "$WORKSPACE/archives"
22 LOG_FILE="$WORKSPACE/archives/version-bump.log"
23 BRANCH="$GERRIT_BRANCH"
24
25 # Ensure we fail the job if any steps fail.
26 set -eu -o pipefail
27
28 # Fail if branch cutting is not on master
29 if [ "$BRANCH_CUT" = "true" ] && [ "$BRANCH" != "master" ]; then
30     echo "ERROR: Cannot branch cut on $BRANCH, its required to be on the master branch."
31     exit 1
32 fi
33
34 if [ "$BRANCH_CUT" = "false" ]; then
35     git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
36
37     # TODO: Simplify once stable/nitrogen is no longer supported.
38     for module in $(git submodule | awk '{ print $2 }')
39     do
40         pushd "$module"
41         if [ "$GERRIT_BRANCH" == "stable/nitrogen" ] && [ "$module" == "yangtools" ]; then
42             git checkout -b "v1.2.x" "origin/v1.2.x"
43         else
44             git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
45         fi
46         popd
47     done
48 fi
49
50
51 # Setup Gerrit remove to ensure Change-Id gets set on commit.
52 git config --global --add gitreview.username "jenkins-$SILO"
53 git review -s
54 git remote -v
55 git submodule foreach "git review -s"
56
57 # Check if git state is clean
58 git status
59
60 if [ "$BRANCH_CUT" = "false" ]; then
61     lftools version release "$RELEASE_TAG"
62 fi
63 lftools version bump "$RELEASE_TAG"
64
65 git submodule foreach "git commit -asm 'Bump versions by x.y.(z+1)'"
66 # Only submodules need to be bumped, we can ignore autorelease's bump information
67 git checkout -f
68
69 # Generate git patches
70 patch_dir="$WORKSPACE/archives/patches/version-bump"
71 mkdir -p "$patch_dir"
72 for module in $(git submodule | awk '{ print $2 }')
73 do
74     pushd "$module"
75     # TODO: Remove once stable/nitrogen is no longer supported.
76     if [ "$GERRIT_BRANCH" == "stable/nitrogen" ] && [ "$module" == "yangtools" ]; then
77         git format-patch --stdout "origin/v1.2.x" > "$patch_dir/${module//\//-}.patch"
78         git bundle create "$patch_dir/${module//\//-}.bundle" "origin/v1.2.x..HEAD"
79     else
80         git format-patch --stdout "origin/${BRANCH,,}" > "$patch_dir/${module//\//-}.patch"
81         git bundle create "$patch_dir/${module//\//-}.bundle" "origin/${BRANCH,,}..HEAD"
82     fi
83     popd
84 done
85
86 ##########
87 # Verify #
88 ##########
89
90 {
91     echo "----> Verify version bump"
92     git submodule foreach git show HEAD
93     git show HEAD
94     find . -name pom.xml -print0 | xargs -0 grep "$RELEASE_TAG" || true
95     git status
96     ls "$patch_dir"
97 } | tee -a "$LOG_FILE"
98
99 #########
100 # Build #
101 #########
102
103 MVN_GOALS=(clean install)
104 if [ "$DRY_RUN" = "false" ]
105 then
106     # Should be safe to run mvn clean deploy as nothing should be
107     # using the version bumped versions just yet.
108     MVN_GOALS=(clean deploy)
109 fi
110
111 ./scripts/fix-relativepaths.sh
112 "$MVN" "${MVN_GOALS[@]}" -Pq \
113 -s "$SETTINGS_FILE" \
114 -gs "$GLOBAL_SETTINGS_FILE" \
115 -DaltDeploymentRepository="opendaylight-snapshot::default::https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot" \
116 --show-version \
117 --batch-mode \
118 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
119 -Djenkins \
120 -Dmaven.repo.local=/tmp/r \
121 -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r
122
123 # Clear any changes caused by Maven build
124 git checkout -f
125 git submodule foreach git checkout -f
126
127 ########
128 # Push #
129 ########
130
131 if [ "$DRY_RUN" = "false" ]
132 then
133     # Push up patches last, as long as nothing failed.
134     git submodule foreach git review --yes -t "${RELEASE_TAG}"
135 fi
136
137 echo "Version bumping complete."