#!/bin/bash
DISTRIBUTION=$1
-VERSION=$(mvn -B -N help:evaluate -Dexpression=project.version | grep -v "^\[")
+VERSION=$(mvn -B -N help:evaluate -Dexpression=project.version 2>/dev/null| grep -v "^\[")
VALID_DISTROS=("unstable" "wheezy" "squeeze" "production" \
- "production-proposed-updates" "pre-staging" "staging" "experimental")
+ "production-proposed-updates" "pre-staging" "staging")
SPECIAL_BRANCHES=("feature/" "hotfix/" "poc/" "integration")
function containsElement () {
function validateInput
{
+ APPEND_TO_VERSION = ""
+
+ if [[ -z "${VERSION}" ]] ; then
+ echo "ERROR: Cannot get version from maven using 'mvn -B -N help:evaluate -Dexpression=project.version'"
+ mvn -B -N help:evaluate -Dexpression=project.version
+ exit 1
+ fi
+
if startswithElement $GIT_BRANCH_NAME "${SPECIAL_BRANCHES[@]}" ; then
if [ "$GIT_BRANCH_NAME" = "integration" ] ; then
- DISTRIBUTION="unstable"
+ DISTRIBUTION="dev-integration"
else
- DISTRIBUTION="experimental"
+ # set proper DISTRIBUTION for feature branches
+ DISTRIBUTION= $(echo "dev-${GIT_BRANCH_NAME}" | tr '/' '-')
fi
- fi
-
- if ! containsElement $DISTRIBUTION "${VALID_DISTROS[@]}" ; then
+ APPEND_TO_VERSION = "experimental"
+ elif ! containsElement $DISTRIBUTION "${VALID_DISTROS[@]}" ; then
echo "\$DISTRIBUTION is set to $DISTRIBUTION but thats not a valid distribution, which are: $VALID_DISTROS"
exit 1
+ if [ "$DISTRIBUTION" = "unstable" ] || [ "$DISTRIBUTION" = "pre-staging" ] ;
+ APPEND_TO_VERSION = "develop"
+ fi
fi
- if [ "$DISTRIBUTION" = "experimental" ] ; then
- # set proper DISTRIBUTION for feature branches
- DISTRIBUTION= $(echo "dev-${GIT_BRANCH_NAME}" | tr '/' '-')
- fi
-
- if [[ -z "${VERSION}" ]] ; then
- echo "Need to specify version"
- exit 1
+ if [ ! -z "$APPEND_TO_VERSION" ] ; then
+ # remove -SNAPSHOT
+ VERSION=$(echo $VERSION | sed -s "s#-SNAPSHOT##g")
+ BUILD_START=$(date +%Y%m%d%H%M%S)
+ VERSION="${VERSION}~${APPEND_TO_VERSION}${BUILD_START}+{BUILD_NUMBER}+g${GIT_COMMIT:0:7}"
+ echo "=================================="
+ echo $VERSION
+ echo "=================================="
fi
-
- # TODO: we need to do better
- VERSION=$(echo $VERSION | sed -s "s#SNAP#0SNAP#g")
- echo "=================================="
- echo $VERSION
- echo "=================================="
}
#############
set -e # fail on error
set -x # echo commands executed
-# change version in changelog
-git-dch -a --ignore-branch --no-full --no-meta --id-length=7
-# replace first version (enclosed in brackets) with real version
-sed -i "0,/(.*)/s//($VERSION)/" debian/changelog
-# replace first UNRELEASED with $DISTRIBUTION
-sed -i "0,/UNRELEASED/s//$DISTRIBUTION/" debian/changelog
+if [ "$GIT_BRANCH_NAME" = "master" ] || [ "${GIT_BRANCH_NAME:0:7}" = "hotfix/" ] ; then
+ git-dch -a --ignore-branch --no-full --no-meta --id-length=7 -N $VERSION
+ sed -i "0,/UNRELEASED/s//$DISTRIBUTION/" debian/changelog
+else
+ # change version in changelog
+ git-dch -a --ignore-branch --no-full --no-meta --id-length=7
+ # replace first version (enclosed in brackets) with real version
+ sed -i "0,/(.*)/s//($VERSION)/" debian/changelog
+ # replace first UNRELEASED with $DISTRIBUTION
+ sed -i "0,/UNRELEASED/s//$DISTRIBUTION/" debian/changelog
+fi
# build debian package (just binary, no source package)
dpkg-buildpackage -us -uc -b