1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
#
# Remote build&test script.
# Author: Aleksandar Prokopec
#
SCRIPTNAME="..:: RemoteTest ::.."
DESC="This script pushes the current git repo to a remote bare repo. \
It then checks out the source tree in a workspace repo and starts the\
build and all the tests. It can also initialize the remote bare repo\
and the workspace repo. It assumes that the current repo refspec has\
been set for the remote bare repository - .git/config of the current\
repo must have a remote called <server> and the corresponding master\
branch. Git should, naturally, be installed on both systems.\
"
USAGE=" Usage: remotetest (--help|--init|--all|--incr|--clear) <user> <server> <bare-repo-path> <workspace-repo-path> [logfile]"
function title()
{
echo
echo $SCRIPTNAME
echo
}
function usage()
{
title
echo $DESC
echo
echo $USAGE
}
function error()
{
echo $1
echo "Failed."
exit 1
}
function success()
{
echo "Success!"
exit 0
}
function instruct()
{
usage
error
}
function help()
{
usage
echo
echo "Make sure you have git installed on both your computer and the server, as well as java and ant."
echo "Add your ssh key to the list of authorized keys on the server (see .ssh dir in your home). This is not required, but makes life easier, as you will have to answer fewer passwords."
echo "To initialize the remote repositories on a server 'server.url.com', see the following example:"
echo
echo "> tools/remotetest --init jack server.url.com ~jack/git-repos-dir/scala ~jack/tmp-build-dir/scala"
echo
echo "If you decide you no longer want this remote repository to be tracked (this also tries to delete remote repos on the server):"
echo
echo "> tools/remotetest --clear jack server.url.com ~jack/git-repos-dir/scala ~jack/tmp-build-dir/scala"
echo
echo "Once the initialization is successful, simply run: "
echo
echo "> tools/remotetest --all jack server.url.com ~jack/git-repos-dir/scala ~jack/tmp-build-dir/scala"
echo
echo "Optionally, build and test results will be saved into the logfile on the server (an additional, last argument). Be aware that problems arise should you push an ammended commit over a previously pushed commit - this has nothing to do with this script per se."
echo
echo " Example workflow:"
echo
echo " ------------------- "
echo " | | "
echo " V | "
echo " init ---> [ all | incr ] ---> clear "
echo
echo "Complete argument list:"
echo " --help prints this help"
echo " --init initializes remote repos"
echo " --clear deletes remote repos and removes the remote repo reference from local git repo"
echo " --all pushes the newest version, checks it out at the server, cleans all, builds and tests"
echo " --incr incremental does the same as --all, but does not clean the directory before testing"
}
if [ $# -lt 1 ]
then
instruct
fi
if [ $# -lt 5 ]
then
if [[ $1 = "--help" ]]
then
help
success
else
instruct
fi
fi
COMMAND=$1
USER=$2
LOCATION=$3
BAREREPO=$4
WORKREPO=$5
LOGFILE=$6
if [[ $COMMAND = "--help" ]]
then
help
success
fi
#
# Init
#
if [[ $COMMAND = "--init" ]]
then
echo "Initializing."
# init bare repo
ssh $USER@$LOCATION "mkdir $BAREREPO"
ssh $USER@$LOCATION "cd $BAREREPO; git init; git config --bool core.bare true"
if [ $? -ne 0 ]
then
error "Could not initialize bare repo."
fi
# add remote bare repo
git remote add $LOCATION $USER@$LOCATION:$BAREREPO
# push to bare repo
git push $LOCATION master
if [ $? -ne 0 ]
then
error "Could not push to bare repo."
fi
# init and checkout work repo
ssh $USER@$LOCATION "git clone $BAREREPO $WORKREPO"
if [ $? -ne 0 ]
then
error "Could not init working repo."
fi
success
fi
#
# Clear.
#
if [[ $COMMAND = "--clear" ]]
then
echo "Clearing remote and deleting remote repos."
git remote rm $LOCATION
ssh $USER@$LOCATION "rm -rf $BAREREPO"
ssh $USER@$LOCATION "cd $WORKREPO; ant all.clean; rm -rf $WORKREPO"
echo "Removed remote repo $LOCATION."
success
fi
#
# Test.
#
if [[ $COMMAND = "--all" || $COMMAND = "--incr" ]]
then
# proceed
echo "Starting remote build and testing."
else
error "Unrecognized command $COMMAND."
fi
# if it's not the init operation, proceed normally
# push to remote bare repo
git push $LOCATION master
if [ $? -ne 0 ]
then
error "Could not push to bare repo - push from local machine failed."
fi
# remotely checkout the repo
ssh $USER@$LOCATION "cd $WORKREPO; git pull origin master"
if [ $? -ne 0 ]
then
error "Could not remotely pull from bare repo to work repo."
fi
# clean the build dir if not incremental
if [[ $COMMAND = "--all" ]]
then
ssh $USER@$LOCATION "cd $WORKREPO; ant all.clean"
fi
# run the build and tests
SET_ANT_OPTS='export ANT_OPTS="-XX:MaxPermSize=192M -Xmx1536m"; echo $ANT_OPTS'
echo "Set ant options command: $SET_ANT_OPTS"
ssh $USER@$LOCATION "cd $WORKREPO; $SET_ANT_OPTS; ant nightly | tee -a $LOGFILE"
success
|