This repository has been archived by the owner. It is now read-only.
Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 107 lines (94 sloc) 3.34 KB
#!/bin/sh
#
# Maven release using gitflow stuff
# TODO: moar documentation
# TODO: Add the possibility to specify maven arguments (like MVN_ARGS="-Pprofile1 -Darguments='-Dalt[…]'")
# TODO: Add a check for verifying if everything is update (branches)
# 0. verify the precense of needed command (git, mvn, …)
# 1. get the stable version to come (but let me specify it)
# 2. do your stuff (create the branch, ...)
SELF=$(basename $0)
# The most important line in each script
set -e
# Check for the git command
command -v git >/dev/null || {
echo "$SELF: git command not found." 1>&2
exit 1
}
# Check for the mvn command (maven)
command -v mvn >/dev/null || {
echo "$SELF: mvn command not found." 1>&2
exit 1
}
get_release_branch() {
echo "release/$1"
}
create_release_branch() {
echo -n "Creating release branch... "
RELEASE_BRANCH=$(get_release_branch $1)
echo "$RELEASE_BRANCH"
create_branch=$(git checkout -b ${RELEASE_BRANCH} develop 2>&1)
}
remove_release_branch() {
echo -n "Removing release branch... "
RELEASE_BRANCH=$(get_release_branch $1)
echo "$RELEASE_BRANCH"
remove_branch=$(git branch -D ${RELEASE_BRANCH} 2>&1)
}
mvn_release() {
echo -n "Using maven-release-plugin... "
mvn_release_prepare=$(mvn $MVN_ARGS -B release:prepare)
echo -n "'mvn -B release:prepare' "
mvn_release_perform=$(mvn $MVN_ARGS release:perform)
echo "'mvn release:perform'"
}
# Merging the content of release branch to develop
merging_to_develop() {
echo -n "Merging back to develop... "
RELEASE_BRANCH=$(get_release_branch $1)
git_co_develop=$(git checkout develop 2>&1)
git_merge=$(git merge --no-ff ${RELEASE_BRANCH} 2>&1)
echo "done"
}
# Rewind 1 commit (tag)
# Merge master in release_branch with ours strategy (we have the sure one)
# Merge back release_branch to master
merging_to_master() {
echo -n "Merging back to master... "
RELEASE_BRANCH=$(get_release_branch $1)
git_co_release_branch=$(git checkout ${RELEASE_BRANCH})
git_resete_release_branch=$(git reset --hard HEAD~1)
git_merge_ours=$(git merge -s ours master 2>&1)
git_co_master=$(git checkout master 2>&1)
# We make the assumption "theirs" is the best
git_merge=$(git merge --no-ff ${RELEASE_BRANCH} 2>&1)
echo "done"
}
# First get the working directory
test -n "$MVN_ARGS" && {
echo "Maven arguments provided : $MVN_ARGS."
}
echo -n "Detecting version number... "
if `git rev-parse 2>/dev/null`; then
BRANCH_NAME=$(git symbolic-ref -q HEAD)
BRANCH_NAME=${BRANCH_NAME##refs/heads/}
WORKING_DIR=$(git rev-parse --show-toplevel)
cd $WORKING_DIR
CURRENT_VERSION=`mvn ${MVN_ARGS} org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }'`
if test "$CURRENT_VERSION" = "${CURRENT_VERSION%-SNAPSHOT}"; then
echo "$SELF: version '${CURRENT_VERSION}' specified is not a snapshot"
else
STABLE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
echo "$STABLE_VERSION"
create_release_branch $STABLE_VERSION
mvn_release
merging_to_develop $STABLE_VERSION
merging_to_master $STABLE_VERSION
remove_release_branch $STABLE_VERSION
# Getting back to where we were
git checkout $BRANCH_NAME
fi
else
echo "$SELF: you are not in a git directory"
exit 2
fi