Author: maven-release Date: 2014-05-19 14:15:00 +0200 (Mon, 19 May 2014) New Revision: 69 Url: http://forge.codelutin.com/projects/adminsys/repository/revisions/69 Log: refs #5074 (ajout script deploy-to-demo-from-GIT.sh) Added: scripts/maven-release/deploy-to-demo-from-GIT.sh Added: scripts/maven-release/deploy-to-demo-from-GIT.sh =================================================================== --- scripts/maven-release/deploy-to-demo-from-GIT.sh (rev 0) +++ scripts/maven-release/deploy-to-demo-from-GIT.sh 2014-05-19 12:15:00 UTC (rev 69) @@ -0,0 +1,237 @@ +#!/bin/sh +# script to update rev using the pom version + the svn revision + +OLD_PATH=$(pwd) +APPLICATION_NAME=$(basename $OLD_PATH) + +DEPLOY_TYPES=$(find * -maxdepth 0 -type d -printf " %p") + +export JAVA_HOME=/opt/jdk +export JDK_HOME=$JAVA_HOME +export M2_HOME=/opt/maven + +bye_bye() { + cd $OLD_PATH + exit $1 +} + +print_usage_and_exit() { + echo "-----------------------------------------------------------------------------------" + echo "usage $(basename $0) [-h] [-b] [-d] [-k] [-m extraBuildParameters] [-r gitRevision] deployType" + echo " -h show usage and exit" + echo " -b for batch mode (no question asked)" + echo " -d for dryRun mode (nothing is deployed)" + echo " -k to keep incoming project version (do not transform version using the git revision)" + echo " -m extraBuildParameters (add extra parameters to maven build)" + echo " -r svnRevision (update svn to a specific revision, by default use HEAD)" + echo " deployType type of deploy to do (must be one amoung [$DEPLOY_TYPES])" + echo "" + echo "example: $(basename $0) -b -m\"-DperformRelease -Preporting\" -r101010 latest" + echo "-----------------------------------------------------------------------------------" + + bye_bye $1 +} + +test_ok_or_bye_bye() { + if [ $1 -eq 1 ]; then + echo "KO" + echo "$2 (see at $LOG_FILE)" + bye_bye 1 + else + echo "OK" + fi +} +echo -n "0/4 Check options and prepare git..." + +MAVEN_BUILD="clean install -Pcollect-deploy-files" +SVN_REV="HEAD" +KEEP_VERSION=0 # 0 when transform version using svn revision, 1 keep incoming version +BATCH_MODE=0 # 0 when interactive, 1 when batch mode +DRY_RUN=0 # 0 when execute, 1 when dry run +while getopts ":m:r:hbdk" opt; do + case $opt in + h) + echo "OK" + print_usage_and_exit 0 + ;; + b) + BATCH_MODE=1 + ;; + d) + DRY_RUN=1 + ;; + k) + KEEP_VERSION=1 + ;; + m) + MAVEN_BUILD="$MAVEN_BUILD $OPTARG" + ;; + r) + SVN_REV="$OPTARG" + ;; + \?) + echo "KO" + echo "Invalid option: -$OPTARG" >&2 + print_usage_and_exit 1 + ;; + :) + echo "KO" + echo "Option -$OPTARG requires an argument." >&2 + print_usage_and_exit 1 + ;; + esac + shift $((OPTIND-1)) +done + +# must have a last mandatory parameter +if [ ! $# -eq 1 ]; then + echo "KO" + echo "Mandatory deploy type not given" + print_usage_and_exit 1 +fi +DEPLOY_TYPE="$1" + +# check deploy type exist +if [ ! -d $DEPLOY_TYPE ]; then + echo "KO" + echo "Could not find deploy type $DEPLOY_TYPES (available: $DEPLOY_TYPES)" + bye_bye 1 +fi + +# check deploy structure +cd $DEPLOY_TYPE +if [ ! -f deploy ]; then + echo "KO" + echo "Could not find $DEPLOY_TYPE/deploy file" + bye_bye 1 +fi +if [ ! -f config ]; then + echo "KO" + echo "Could not find $DEPLOY_TYPE/config file" + bye_bye 1 +fi +if [ ! -d svn ]; then + echo "Could not find $DEPLOY_TYPE/svn directory" + bye_bye 1 +fi + +cd git + +# revert git +git checkout . > /dev/null +git clean -f > /dev/null + +# update git +git pull > /dev/null + +# get subversion revision +REV=`git log -n 1 --pretty=format:"%H"` + +# get project version +VERSION=`xmlstarlet sel -N "p=http://maven.apache.org/POM/4.0.0" -t -v "/p:project/p:version" pom.xml` + +# get new version +if [ $KEEP_VERSION -eq 1 ]; then + NEW_VERSION=$VERSION +else + NEW_VERSION=`${M2_HOME}/bin/mvn -N helper:transform-project-version -Dhelper.newVersionPattern="#V-rev#R" -Dhelper.revision=$REV -DhelperPluginVersion=2.0 -Dhelper.versionKey=deployKey help:evaluate -Dexpression=deployKey | grep -v "\[" | grep "-rev" | grep -v "Download"` +fi + +echo "OK" +echo "----------------------------------------------------------" +echo "--- Deploy summary ---------------------------------------" +echo "----------------------------------------------------------" +echo "- application = $APPLICATION_NAME" +echo "- deployType = $DEPLOY_TYPE" +if [ $BATCH_MODE -eq 1 ]; then + echo "- batchMode = ON" +fi +if [ $DRY_RUN -eq 1 ]; then + echo "- dryRun = ON" +fi +if [ $KEEP_VERSION -eq 1 ]; then + echo "- keepVersion = ON" +fi +echo "- revision detected = $REV" +echo "- version detected = $VERSION" +echo "- new version = $NEW_VERSION" +echo "- build parameters = $MAVEN_BUILD" +echo "----------------------------------------------------------" + +if [ $BATCH_MODE -eq 0 ]; then + # ask user to confirm + echo -n "Accept the change ? [Y/n]" + read r + if [ ! -z "$r" -o "$r" = "Y" ]; then + echo "User cancel operation" + bye_bye 1 + fi +fi + +# log file +LOG_FILE=/tmp/deploy-to-demo-$APPLICATION_NAME-$DEPLOY_TYPE.log + +# change version in pom.xml +echo -n "1/4 Change to version $NEW_VERSION..." +if [ $KEEP_VERSION -eq 1 ]; then + echo "OK (keep version, skip this step)" +else + ${M2_HOME}/bin/mvn versions:set -DnewVersion=$NEW_VERSION > $LOG_FILE + test_ok_or_bye_bye $? "Error while executing '${M2_HOME}/bin/mvn versions:set -DnewVersion=$NEW_VERSION'" +fi + +# build application +echo -n "2/4 Build application..." +${M2_HOME}/bin/mvn $MAVEN_BUILD > $LOG_FILE +test_ok_or_bye_bye $? "Error while executing '${M2_HOME}/bin/mvn $MAVEN_BUILD'" + +cd .. + +echo -n "3/4 Deploy to demo..." + +if [ $DRY_RUN -eq 1 ]; then + echo "OK (dry run, skip this step)" +else + + # build the curl deploy options + DEPLOY_ARGS="-s " + for i in $(cat deploy); do + DEPLOY_ARGS="$DEPLOY_ARGS -F \"$i\""; + done + for i in $(cat svn/target/collect-deploy-files.txt); do + DEPLOY_ARGS="$DEPLOY_ARGS -F \"APP_WAR=@$i\"" + continue + done + + # Create a file to execute the curl command (pb with @ in bash execution...) + DEPLOY_ARGS="$DEPLOY_ARGS http://demo-ng.codelutin.com/deploy.cgi" + DEPLOY_COMMAND=/tmp/deploy-to-demo-curl-$APPLICATION_NAME.sh + cat << EOF > $DEPLOY_COMMAND + curl $DEPLOY_ARGS +EOF + + chmod +x $DEPLOY_COMMAND + + # execute the curl command + cat $DEPLOY_COMMAND > $LOG_FILE + . $DEPLOY_COMMAND >> $LOG_FILE + + # check there is a Deploy success in response" + if [ $? -eq 0 ]; then + grep "Deploy success" $LOG_FILE > /dev/null + fi + test_ok_or_bye_bye $? "Could not deploy to demo" +fi + +# revert any change +echo -n "4/4 Revert local modifications and clean target..." + +cd git +git checkout . > /dev/null +git clean -f > /dev/null +${M2_HOME}/bin/mvn clean > /dev/null +cd .. + +echo "OK" + +bye_bye 0 Property changes on: scripts/maven-release/deploy-to-demo-from-GIT.sh ___________________________________________________________________ Added: svn:executable + *