Skip to content

Instantly share code, notes, and snippets.

@fkleon
Created November 20, 2013 01:35
Show Gist options
  • Save fkleon/7556054 to your computer and use it in GitHub Desktop.
Save fkleon/7556054 to your computer and use it in GitHub Desktop.
A couple of shell scripts to help with SVN management and project deployment. Tailored to a specific project, might not be of great general use.
#!/bin/bash
#########################################################
# A shell script to deploy a stable project version. #
# #
# For a detailed description, see the wiki. #
# #
# Version: #
# 1.0.1 #
# Author(s): #
# - Frederik Leonhardt #
#########################################################
VERSION=1.0.1
#################
# CONFIGURATION #########################################
#################
SVN_TRUNK_DIR=/home/jboss/serene-trunk # The path to the trunk
SVN_USER=leonhardt # The SVN user to use
#########################################################
echo "SVN Deploy Script (Production)"
echo "[version $VERSION]"
echo ""
# Checkout code
svn up $SVN_TRUNK_DIR --username $SVN_USER
# Install datamodel-lib
cd $SVN_TRUNK_DIR/mentorbike-datamodel-lib
mvn clean install
# Run maven tests
cd $SVN_TRUNK_DIR/serene-core-ejb
mvn test -P arq-jbossas-remote
rc=$? # contains exit code of last command
if [[ $rc != 0 ]] ; then
echo "---------------------------------------------------------"
echo "One or more tests failed to succeed. Deployment canceled."
echo "---------------------------------------------------------"
exit $rc
fi
# Build and deploy
cd $SVN_TRUNK_DIR/mentorbike-app
mvn clean package jboss-as:deploy
#!/bin/bash
#########################################################
# A shell script to manage test runs and svn operations.#
# #
# For a detailed description, see the wiki. #
# #
# Version: #
# 1.1.1 #
# Author(s): #
# - Frederik Leonhardt #
#########################################################
VERSION=1.1.1
#################
# CONFIGURATION #########################################
#################
JBOSS_PATH=/home/serene/jboss-eap-6.1.0.Final # The path to the JBoss instance
SVN_USER=leonhardt # The SVN user to use
SVN_TRUNK_URL=https://svnsrv/trunk # The URL to the trunk
SVN_DEV_URL=https://svnsrv/branches/serene-dev # The URL to the dev branch
SVN_DEV_DIR=/home/serene/serene-dev # The path to the dev branch
SVN_TRUNK_DIR=/home/serene/serene-trunk # The path to the trunk
TEST_LOG_DIR=/home/serene/testlogs # The path to store test logs
#########################################################
uptrunk(){
echo "Update trunk.."
svn up $SVN_TRUNK_DIR --username $SVN_USER
}
updev(){
echo "Update dev.."
svn up $SVN_DEV_DIR --username $SVN_USER
}
mergefromtrunk(){
echo "Merging from trunk to dev.."
cd $SVN_DEV_DIR
svn merge $SVN_TRUNK_URL
}
mergetotrunk(){
# TODO CI
echo "Merging dev into trunk.."
cd $SVN_TRUNK_DIR
svn merge --reintegrate $SVN_DEV_URL
}
citrunk() {
echo "Commit trunk.."
cd $SVN_TRUNK_DIR
svn ci -m "$1"
echo $1
}
cidev() {
echo "Commit dev.."
cd $SVN_DEV_DIR
svn ci -m "$1"
}
# Carries out a test run consisting of:
# - Update trunk
# - Update dev
# - Merge trunk into dev
# - Run unit tests
# - Deploy to container (if tests complete successfully)
run(){
# Checkout code
uptrunk
updev
# Merge from trunk
#mergefromtrunk
# Use 7.2.0 POM for tests
echo "Using JBoss 7.2.0 POM.."
cp $SVN_DEV_DIR/jee-jboss-deps/pom.xml $SVN_DEV_DIR/jee-jboss-deps/pom.backup
cp $SVN_DEV_DIR/jee-jboss-deps/pom_720 $SVN_DEV_DIR/jee-jboss-deps/pom.xml
# Run maven tests
echo "Testing dev code.."
cd $SVN_DEV_DIR/serene-core-ejb
mvn test -P arq-jbossas-remote
rc=$? # Contains exit code of maven tests
# Backup test logs
if [[ $rc != 0 ]] ; then
MSG="FAIL"
else
MSG="SUCCESS"
fi
DATE=`eval date +%Y_%m_%d-%H%M%S`
TEST_LOG_DEST=$TEST_LOG_DIR/$DATE-$MSG
echo "Exporting test logs to $TEST_LOG_DEST.."
mkdir $TEST_LOG_DEST
cp $SVN_DEV_DIR/serene-core-ejb/target/surefire-reports/* $TEST_LOG_DEST/
# Check exit code
if [[ $rc != 0 ]] ; then
# Restore POM
echo "Restoring JBoss 7.1.1 POM.."
cp $SVN_DEV_DIR/jee-jboss-deps/pom.backup $SVN_DEV_DIR/jee-jboss-deps/pom.xml
#cp $SVN_DEV_DIR/jee-jboss-deps/pom.xml $SVN_DEV_DIR/jee-jboss-deps/pom.xml
# Print error
echo "---------------------------------------------------------"
echo "One or more tests failed to succeed. Deployment canceled."
echo "---------------------------------------------------------"
# Finish execution
exit $rc
fi
# Build and deploy
echo "Deploying application.."
cd $SVN_DEV_DIR/mentorbike-app
mvn clean package jboss-as:deploy
# Restore 7.1.1 POM
echo "Restoring JBoss 7.1.1 POM.."
cp $SVN_DEV_DIR/jee-jboss-deps/pom_711 $SVN_DEV_DIR/jee-jboss-deps/pom.xml
}
case "$1" in
run)
run
;;
updev)
updev
;;
uptrunk)
uptrunk
;;
cidev)
cidev "$2"
;;
citrunk)
citrunk "$2"
;;
mergefromtrunk)
mergefromtrunk
;;
mergetotrunk)
mergetotrunk
;;
*)
echo "SVN Management Script (Dev)"
echo "[version $VERSION]"
echo ""
echo "Usage:"
echo " run - Test and deploy dev branch to container"
echo " updev - Update dev branch"
echo " uptrunk - Update trunk"
echo " cidev <msg> - Commit dev branch with given commit message"
echo " citrunk <msg> - Commit trunk with given commit message"
echo " mergefromtrunk- Merge from trunk into dev"
echo " mergetotrunk - Merge from dev to trunk"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment