script used to release a project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# http://jlorenzen.blogspot.com/2010/05/how-to-create-release-without-maven2.html | |
echo -e "Usage ./project-release.sh [n] [dryRun]\n" | |
INCREMENT_POS=$1 | |
DRY_RUN=$2 | |
DEST_BASE_URL=https://server/svn/project/branches | |
BASE_MSG="[project-release.sh] -" | |
CREATE_BRANCH_MSG="$BASE_MSG Creating Branch" | |
UPDATE_VERSION_MSG="$BASE_MSG Updating POM versions" | |
REMOVE_BRANCH_MSG="$BASE_MSG Removing Branch" | |
SRC_URL="$(xpath -q -e '//scm/url/text()' pom.xml)" | |
PROJECT="$(xpath -q -e '/project/artifactId/text()' pom.xml)" | |
VERSION="$(xpath -q -e '/project/version/text()' pom.xml)" | |
BRANCH_NAME=$PROJECT-${VERSION%-SNAPSHOT*} | |
RELEASE_VERSION=${VERSION%-SNAPSHOT*} | |
DEST_URL=$DEST_BASE_URL/$BRANCH_NAME | |
INCREMENT_VAL="$(echo $VERSION | awk -F . '{print $'$INCREMENT_POS'}')" | |
# Strip off any remaining non version information for patches | |
INCREMENT_VAL=${INCREMENT_VAL%-SNAPSHOT*} | |
INCREMENT_VAL=$(($INCREMENT_VAL+1)) | |
NEXT_VERSION="" | |
arr=($(echo $VERSION | tr "." "\n")) | |
for (( i=0; i < ${#arr[*]}; i++ )) | |
do | |
x=${arr[$i]} | |
if [[ $i == $(($INCREMENT_POS-1)) ]]; then | |
if [[ "$(expr index "$x" SNAPSHOT)" > 0 ]]; then | |
NEXT_VERSION="${NEXT_VERSION}.${INCREMENT_VAL}-SNAPSHOT" | |
else | |
NEXT_VERSION="${NEXT_VERSION}.${INCREMENT_VAL}" | |
fi | |
else | |
NEXT_VERSION="${NEXT_VERSION}.$x" | |
fi | |
done | |
NEXT_VERSION=($(echo $NEXT_VERSION | sed "s/^.//")) | |
echo "Curr Version $VERSION" | |
echo "Rel Version $RELEASE_VERSION" | |
echo "Next Version $NEXT_VERSION" | |
echo "SRC URL - $SRC_URL" | |
echo -e "DST URL - $DEST_URL\n" | |
CREATE_BRANCH_MSG="$CREATE_BRANCH_MSG from $SRC_URL" | |
if [[ $DRY_RUN == "false" ]]; then | |
echo "Creating Release" | |
################################ | |
## Update Trunk | |
################################ | |
svn copy $SRC_URL $DEST_URL -m "$CREATE_BRANCH_MSG" | |
find . -name "pom.xml" | xargs perl -pi~ -e "s/$VERSION/$NEXT_VERSION/" | |
svn commit -m "$UPDATE_VERSION_MSG from $VERSION to $NEXT_VERSION" | |
################################ | |
## Checkout and Update Release | |
################################ | |
rm -rf target ; mkdir target | |
svn checkout $DEST_URL target/checkout | |
find target/checkout -name "pom.xml" | xargs perl -pi~ -e "s/$VERSION/$RELEASE_VERSION/" | |
svn commit -m "$UPDATE_VERSION_MSG from $VERSION to $RELEASE_VERSION" | |
fi | |
################################ | |
## Removing Branch used only when testing | |
################################ | |
#echo "Deleting branch $DEST_URL" | |
#svn remove $DEST_URL -m "$REMOVE_BRANCH_MSG" | |
################################ | |
################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment