Merge "Update cloud image Ubuntu18.04 mininet ovs"
[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 # shellcheck disable=SC1090
30 . ~/lf-env.sh
31
32 lf-activate-venv --python python3 "git-review==2.3.1"
33
34 # Fail if branch cutting is not on master
35 if [ "$BRANCH_CUT" = "true" ] && [ "$BRANCH" != "master" ]; then
36     echo "ERROR: Cannot branch cut on $BRANCH, its required to be on the master branch."
37     exit 1
38 fi
39
40 if [ "$BRANCH_CUT" = "false" ]; then
41     git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
42
43     for module in $(git submodule | awk '{ print $2 }')
44     do
45         pushd "$module"
46         git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
47         popd
48     done
49 fi
50
51 # Workaround for git-review failing to copy the commit-msg hook to submodules
52 git config core.hooksPath "$(git rev-parse --show-toplevel)/.git/hooks"
53
54 # Setup Gerrit remote to ensure Change-Id gets set on commit.
55 git config --global --add gitreview.username "jenkins-$SILO"
56 git review -s
57 git remote -v
58 git submodule foreach "git review -s"
59
60 # Check if git state is clean
61 git status
62
63 if [ "$BRANCH_CUT" = "false" ]; then
64     lftools version release "$RELEASE_TAG"
65     commit_msg="Bump versions by x.y.(z+1)"
66 else
67     commit_msg="Bump versions by x.(y+1).z"
68     # If we are branch cutting we also need to bump the docs/conf.yaml version
69     find . -type f -name conf.yaml -exec sed -i "s/version:.*/version: ${STREAM^}/" {} \;
70 fi
71 lftools version bump "$RELEASE_TAG"
72
73 # Ignore changes to Final distribution since that will be released separately
74 pushd integration/distribution || true
75     git checkout -f opendaylight/pom.xml || true
76 popd || true
77
78 git submodule foreach "git commit -asm '${commit_msg}'"
79 # Only submodules need to be bumped, we can ignore autorelease's bump information
80 git checkout -f
81
82 # Generate git patches
83 patch_dir="$WORKSPACE/archives/patches/version-bump"
84 mkdir -p "$patch_dir"
85 for module in $(git submodule | awk '{ print $2 }')
86 do
87     pushd "$module"
88     git format-patch --stdout "origin/${BRANCH,,}" > "$patch_dir/${module//\//-}.patch"
89     git bundle create "$patch_dir/${module//\//-}.bundle" "origin/${BRANCH,,}..HEAD"
90     popd
91 done
92
93 ##########
94 # Verify #
95 ##########
96
97 {
98     echo "----> Verify version bump"
99     git submodule foreach git show HEAD
100     git show HEAD
101     find . -name pom.xml -print0 | xargs -0 grep "$RELEASE_TAG" || true
102     git status
103     ls "$patch_dir"
104 } | tee -a "$LOG_FILE"
105
106 #########
107 # Build #
108 #########
109
110 MVN_GOALS=(clean install)
111 if [ "$DRY_RUN" = "false" ]
112 then
113     # Should be safe to run mvn clean deploy as nothing should be
114     # using the version bumped versions just yet.
115     MVN_GOALS=(clean deploy)
116 fi
117
118 ./scripts/fix-relativepaths.sh
119 "$MVN" "${MVN_GOALS[@]}" -Pq \
120 -s "$SETTINGS_FILE" \
121 -gs "$GLOBAL_SETTINGS_FILE" \
122 -DaltDeploymentRepository="opendaylight-snapshot::default::https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot" \
123 --show-version \
124 --batch-mode \
125 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
126 -Djenkins \
127 -Dmaven.repo.local=/tmp/r \
128 -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r
129
130 # Clear any changes caused by Maven build
131 git checkout -f
132 git submodule foreach git checkout -f
133
134 ########
135 # Push #
136 ########
137
138 if [ "$DRY_RUN" = "false" ]
139 then
140     # Push up patches last, as long as nothing failed.
141     git submodule foreach git review --yes -t "${TOPIC}"
142 fi
143
144 echo "Version bumping complete."