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