Fix commit msg to version correctly on bump
[releng/builder.git] / jjb / autorelease / version-bump.sh
index a44337e0e42713ae66411f7f559a4a5f49f0d27e..12e1b849b3c50c378e53802cad12b3e9ea9d91b2 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -l
 # SPDX-License-Identifier: EPL-1.0
 ##############################################################################
 # Copyright (c) 2017 The Linux Foundation and others.
@@ -9,12 +9,14 @@
 # http://www.eclipse.org/legal/epl-v10.html
 ##############################################################################
 
-# This script performs version bumping activities for an ODL release.
+# This script performs version bumping activities for an ODL release and branch
+# cutting.
 echo "---> version-bump.sh"
 
 # The only purpose of RELEASE_TAG in this script is to set the Gerrit topic.
 # It is also used as a placeholder for version bumping but gets wiped out
 # immediately to bump versions by x.y.(z+1).
+TOPIC="${RELEASE_TAG}"
 RELEASE_TAG="${STREAM^}"
 
 mkdir -p "$WORKSPACE/archives"
@@ -24,32 +26,48 @@ BRANCH="$GERRIT_BRANCH"
 # Ensure we fail the job if any steps fail.
 set -eu -o pipefail
 
-git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
+pip install --user --quiet --upgrade git-review
 
-# TODO: Simplify once stable/nitrogen is no longer supported.
-for module in $(git submodule | awk '{ print $2 }')
-do
-    pushd "$module"
-    if [ "$GERRIT_BRANCH" == "stable/nitrogen" ] && [ "$module" == "yangtools" ]; then
-        git checkout -b "v1.2.x" "origin/v1.2.x"
-    else
+# Fail if branch cutting is not on master
+if [ "$BRANCH_CUT" = "true" ] && [ "$BRANCH" != "master" ]; then
+    echo "ERROR: Cannot branch cut on $BRANCH, its required to be on the master branch."
+    exit 1
+fi
+
+if [ "$BRANCH_CUT" = "false" ]; then
+    git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
+
+    for module in $(git submodule | awk '{ print $2 }')
+    do
+        pushd "$module"
         git checkout -b "${BRANCH,,}" "origin/${BRANCH,,}"
-    fi
-    popd
-done
+        popd
+    done
+fi
 
-# Setup Gerrit remove to ensure Change-Id gets set on commit.
-git config --global --add gitreview.username "jenkins-releng"
+# Setup Gerrit remote to ensure Change-Id gets set on commit.
+git config --global --add gitreview.username "jenkins-$SILO"
 git review -s
+git remote -v
 git submodule foreach "git review -s"
 
 # Check if git state is clean
 git status
 
-lftools version release "$RELEASE_TAG"
+if [ "$BRANCH_CUT" = "false" ]; then
+    lftools version release "$RELEASE_TAG"
+    commit_msg="Bump versions by x.y.(z+1)"
+else
+    commit_msg="Bump versions by x.(y+1).z"
+fi
 lftools version bump "$RELEASE_TAG"
 
-git submodule foreach "git commit -asm 'Bump versions by x.y.(z+1)'"
+# Ignore changes to Final distribution since that will be released separately
+pushd integration/distribution || true
+    git checkout -f opendaylight/pom.xml || true
+popd || true
+
+git submodule foreach "git commit -asm '${commit_msg}'"
 # Only submodules need to be bumped, we can ignore autorelease's bump information
 git checkout -f
 
@@ -59,18 +77,15 @@ mkdir -p "$patch_dir"
 for module in $(git submodule | awk '{ print $2 }')
 do
     pushd "$module"
-    # TODO: Remove once stable/nitrogen is no longer supported.
-    if [ "$GERRIT_BRANCH" == "stable/nitrogen" ] && [ "$module" == "yangtools" ]; then
-        git format-patch --stdout "origin/v1.2.x" > "$patch_dir/${module//\//-}.patch"
-        git bundle create "$patch_dir/${module//\//-}.bundle" "origin/v1.2.x..HEAD"
-    else
-        git format-patch --stdout "origin/${BRANCH,,}" > "$patch_dir/${module//\//-}.patch"
-        git bundle create "$patch_dir/${module//\//-}.bundle" "origin/${BRANCH,,}..HEAD"
-    fi
+    git format-patch --stdout "origin/${BRANCH,,}" > "$patch_dir/${module//\//-}.patch"
+    git bundle create "$patch_dir/${module//\//-}.bundle" "origin/${BRANCH,,}..HEAD"
     popd
 done
 
-# Verify
+##########
+# Verify #
+##########
+
 {
     echo "----> Verify version bump"
     git submodule foreach git show HEAD
@@ -80,29 +95,42 @@ done
     ls "$patch_dir"
 } | tee -a "$LOG_FILE"
 
-# Push
+#########
+# Build #
+#########
+
+MVN_GOALS=(clean install)
 if [ "$DRY_RUN" = "false" ]
 then
-    # Run a build here! Should be safe to run mvn clean deploy as nothing should be
+    # Should be safe to run mvn clean deploy as nothing should be
     # using the version bumped versions just yet.
-    ./scripts/fix-relativepaths.sh
-    "$MVN" clean deploy -Pq \
-    -s "$SETTINGS_FILE" \
-    -gs "$GLOBAL_SETTINGS_FILE" \
-    -DaltDeploymentRepository="opendaylight-snapshot::default::https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot" \
-    --show-version \
-    --batch-mode \
-    -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
-    -Djenkins \
-    -Dmaven.repo.local=/tmp/r \
-    -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r
-
-    # Clear any changes caused by Maven build
-    git checkout -f
-    git submodule foreach git checkout -f
+    MVN_GOALS=(clean deploy)
+fi
 
+./scripts/fix-relativepaths.sh
+"$MVN" "${MVN_GOALS[@]}" -Pq \
+-s "$SETTINGS_FILE" \
+-gs "$GLOBAL_SETTINGS_FILE" \
+-DaltDeploymentRepository="opendaylight-snapshot::default::https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot" \
+--show-version \
+--batch-mode \
+-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
+-Djenkins \
+-Dmaven.repo.local=/tmp/r \
+-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r
+
+# Clear any changes caused by Maven build
+git checkout -f
+git submodule foreach git checkout -f
+
+########
+# Push #
+########
+
+if [ "$DRY_RUN" = "false" ]
+then
     # Push up patches last, as long as nothing failed.
-    git submodule foreach git review --yes -t "${RELEASE_TAG}"
+    git submodule foreach git review --yes -t "${TOPIC}"
 fi
 
 echo "Version bumping complete."