Files
spring-data-build/etc/scripts/new-issue-branch
Greg L. Turnquist d572ad3807 #1101 - Polishing.
2020-05-20 09:49:06 -05:00

42 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 DATACMNS-42
# will create a new (local) branch issue/DATACMNS-42
USAGE="$0 <ticket_id>"
if [ $# -lt 1 ]; then echo -e "ERROR: ticket_id required. \n$USAGE" >&2; exit 1; fi
if [ $# -gt 1 ]; then echo -e "ERROR: One argument maximum.\n$USAGE" >&2; exit 1; fi
TICKET_ID=${1:?"TICKET_ID Parameter is missing!"}
# Warmup the maven plugins before actually using them (avoids "Downloading" messages getting in variables)
echo "Warming up the Maven plugins..."
mvn -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version
mvn -q versions:help
# Now use the plugins to roll the version
echo "Looking up the current version..."
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/"-SNAPSHOT"/"-${TICKET_ID}-SNAPSHOT"}
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 $MAVEN_FLAGS -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!")