Skip to content

Instantly share code, notes, and snippets.

@dnsang
Created June 8, 2016 10:59
Show Gist options
  • Save dnsang/49250f95a8b025c218535f9ea3bcd961 to your computer and use it in GitHub Desktop.
Save dnsang/49250f95a8b025c218535f9ea3bcd961 to your computer and use it in GitHub Desktop.
To pull & build sbt or mvn from list of projects on order
#!/bin/bash
# written by sangdn 6/6/2016
# to reduce stupid-time when up-to-date dependency projects
# config:
# set sbt_exclude/mvn_exclude to exclude build mode
# set mvn = PATH[param], PaTH[param]
# set mvn_options = option to build with maven command
# eg:
# sbt_exclude=clean
# sbt=PATH[clean,compile,publishLocal]
# It will execute: cd PATH; sbt compile publishLocal
sbt_exclude=clean
sbt_builds="DDF:adatao[clean,compile,publishLocal];ddf-jdbc:adatao[clean,compile,publishLocal];pAnalytics"
mvn_options="-DskipTests"
mvn_exclude=clean
mvn_builds="DDF:adatao[clean,compile,package],ddf-jdbc:adatao[clean,compile,package],pAnalytics"
current_dir=$(pwd)
function get_path(){
pattern="([/.~a-zA-Z0-9_-]+)"
if [[ $1 =~ $pattern ]]; then
echo ${BASH_REMATCH[1]}
else
echo "Path Not Found !!!! Exit"
exit
fi
}
function get_branch_name(){
pattern=":([a-zA-Z0-9_-]+)"
if [[ $1 =~ $pattern ]]; then
echo ${BASH_REMATCH[1]}
else
echo "master"
fi
}
function get_build_command(){
pattern="\[([a-zA-Z0-9_,]+)\]"
exclude_cmd=$2
if [[ $1 =~ $pattern ]]; then
cmds=${BASH_REMATCH[1]}
#cmds=$(sed 's/,/ /g' <<< $cmd)
IFS=', ' read -r -a array <<< "$cmds"
cmds=""
for cmd in "${array[@]}"
do
if [[ ${exclude_cmd} != *"$cmd"* ]]; then
cmds="$cmds $cmd"
fi
done
else
cmds="compile"
fi
echo $cmds
}
function execute(){
engine=$1
builds=$2
exclude=$3
options=$4
IFS='; ' read -r -a array <<< "$builds"
for build in "${array[@]}"
do
echo
echo "# PROCESSING "$build
path=$(get_path $build)
branch=$(get_branch_name $build)
cmd=$(get_build_command $build $exclude)
cd $current_dir
cd $path
previous_branch=$(git branch | sed -n '/\* /s///p')
git checkout $branch
git pull
$engine $cmd $options
git checkout $previous_branch
done
}
arg1=$1
if [ ! -z arg1 ]; then
if [[ ${arg1} != *"sbt"* ]]; then
#disable sbt build
sbt_builds=""
fi
if [[ ${arg1} != *"mvn"* ]]; then
#disable mvn build
mvn_builds=""
fi
fi
echo " #### Execute SBT Build ###"
if [ -z $sbt_builds ]; then
echo "SBT Build Not Found"
else
execute "sbt" "$sbt_builds" "$sbt_exclude"
fi
echo " #### Execute Maven Build ###"
if [ -z $mvn_builds ]; then
echo "Maven Build Not Found"
else
execute "mvn" "$mvn_builds" "$mvn_exclude" "$mvn_options"
fi
echo "#### END ####"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment