Skip to content

Instantly share code, notes, and snippets.

@mgoellnitz
Last active January 13, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgoellnitz/6309b46960358ba8658915b6a1403b68 to your computer and use it in GitHub Desktop.
Save mgoellnitz/6309b46960358ba8658915b6a1403b68 to your computer and use it in GitHub Desktop.
Trigger DXP builds from e.g. cron if the last commit is not equal to the one stored previously
#!/bin/bash
#
# Build workspace if last commit is not equal to the one stored previously.
#
# Optionally uses scp to copy resulting maven artifacts to a remote repository.
#
# $1 - workspace directory - default ~/coremedia9
# $2 - WebDAV/HTTP publishing target - default none
# $3 - WebDAV/HTTP publishing username - default none
# $4 - WebDAV/HTTP publishing password - default none
#
# Requires davix to be installed for publishing
#
# Copyright (c) 2017-2018, Martin Goellnitz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
WORKSPACE=${1:-~/coremedia9}
TARGET=${2}
USERNAME=${3}
PASSWORD=${4}
LOG=/var/log/cms-build.log
if [ ! -w $LOG ] ; then
LOG=/tmp/cms-build.log
fi
source /etc/profile
BUILDING=`grep 'Building' $LOG`
if [ ! -z "$BUILDING" ] ; then
echo "Check for running build" >>$LOG
BUILDING=`grep 'Build done' $LOG`
if [ -z "$BUILDING" ] ; then
echo "Build in progress" >>$LOG
exit
fi
fi
cd $WORKSPACE
echo -n "Syncing with GIT upstream " >> $LOG
date >> $LOG
git stash >> $LOG
git fetch >> $LOG
git rebase >> $LOG
git stash apply >> $LOG 2>&1
git stash clear >> $LOG 2>&1
NOW=`date +%s`
LASTREBASE=`cat /tmp/lastworkspacecommit`
LASTCOMMIT=`git log -n1 --format="%h"`
if [ "$LASTCOMMIT" != "$LASTREBASE" ] ; then
echo -n "Building workspace. " > $LOG
date >> $LOG
echo $LASTCOMMIT > /tmp/lastworkspacecommit
export MAVEN_OPTS="-Xms1024m -Xmx4096m -Dorg.slf4j.simpleLogger.defaultLogLevel=warn"
mvn clean -DskipTests=true -Dcoremedia.enforcer.skip=true -Denforcer.skip=true -Dmdep.analyze.skip=true >> $LOG
mvn install -DskipTests=true -Dcoremedia.enforcer.skip=true -Denforcer.skip=true -Dmdep.analyze.skip=true >> $LOG
echo -n "Build done. " >> $LOG
date >> $LOG
if [ ! -z "$TARGET" ] ; then
echo "Copying maven artifacts to $TARGET. " >> $LOG
if [ -f deployment/chef/target/deployment-archive.zip ] ; then
mv deployment/chef/target/deployment-archive.zip deployment/chef/target/deployment-archive.copying
fi
davix-rm --userlogin "$USERNAME" --userpass="$PASSWORD" $TARGET/com 2>&1 >> $LOG
davix-put -r 4 --userlogin "$USERNAME" --userpass="$PASSWORD" deployment/chef/target/maven-repo/com $TARGET/com 2>&1 >> $LOG
# scp -r deployment/chef/target/maven-repo/* $TARGET >> $LOG
echo -n "Copying done. " >> $LOG
date >> $LOG
if [ -f deployment/chef/target/deployment-archive.copying ] ; then
mv deployment/chef/target/deployment-archive.copying deployment/chef/target/deployment-archive.zip
fi
fi
else
echo "Last unchanged commit was $LASTCOMMIT" >> $LOG
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment