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