From 6052f15a7e2dd22ee6de586326a457b998945d69 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Mon, 18 Nov 2013 10:25:29 +0100 Subject: [PATCH] #27 - Introduced shell script to automatically create issue branches and update pom versions. Previously every branch push / commit ended up in the same BUILD-SNAPSHOT artefact. In order to avoid potential confusion we now change the pom versions to create issue specific snapshot-builds next to the build-snapshot that is created for the master branch. As an example the version number in SD Commons 1.7.0.BUILD-SNAPSHOT for issue DATACMNS-42 becomes 1.7.0.DATACMNS-42-SNAPSHOT. This is automatically performed by the new-issue-branch.sh script. When one begins to work on a ticket just execute: new-issue-branch.sh DATAMODULE-ISSUENUMBER E.g.: new-issue-branch.sh DATACMNS-42 will create a new branch issue/DATACMNS-42 in SD Commons. --- etc/scripts/new-issue-branch.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 etc/scripts/new-issue-branch.sh diff --git a/etc/scripts/new-issue-branch.sh b/etc/scripts/new-issue-branch.sh new file mode 100755 index 00000000..6bc1bde0 --- /dev/null +++ b/etc/scripts/new-issue-branch.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# This script creates a new local issue branch for the given issue id. +# Previous changes are stashed before the issue branch is created and are reapplied after branch creation. +# +# executing new-issue-branch.sh DATACMNS-42 +# will create a new (local) branch issue/DATACMNS-42 + +TICKET_ID=${1:?"TICKET_ID Parameter is missing!"} +OLD_VERSION_TMP=$(mvn -o org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev '^\[.*') + +OLD_POM_VERSION=${OLD_VERSION_TMP:?"Could not extract current project version from pom.xml"} + +# Replaces BUILD in BUILD-SNAPSHOT with the given TICKET_ID +NEW_POM_VERSION=${OLD_POM_VERSION/"BUILD"/$TICKET_ID} +ISSUE_BRANCH="issue/$TICKET_ID" + +echo "Creating feature branch $TICKET_ID: $OLD_POM_VERSION -> $NEW_POM_VERSION" + +echo "Stashing potential intermediate changes..." && git stash\ +&& git checkout -b $ISSUE_BRANCH\ +&& mvn -o -q versions:set -DgenerateBackupPoms=false -DnewVersion=$NEW_POM_VERSION\ +&& ( \ + (\ + git commit -am "$TICKET_ID - Prepare branch"\ + && echo "Created feature branch: $ISSUE_BRANCH"\ + && echo "Reapplying potentially stashed changes... " && git stash pop)\ + || echo "Something went wrong!") +