1010VERSION=" 0.6.0"
1111CONFIG=./deploy.conf
1212LOG=/tmp/pm2-deploy-${USER:- default} .log
13- TEST=1
1413FORCE=0
1514REF=
1615ENV=
@@ -33,7 +32,6 @@ usage() {
3332
3433 -C, --chdir <path> change the working directory to <path>
3534 -c, --config <path> set config path. defaults to ./deploy.conf
36- -T, --no-tests ignore test hook
3735 -V, --version output program version
3836 -h, --help output help information
3937 -f, --force skip local change checking
@@ -236,6 +234,7 @@ setup() {
236234deploy () {
237235 local ref=$1
238236 local branch=$2
237+
239238 if test -z " $branch " ; then
240239 branch=${ref#*/ }
241240 fi
@@ -244,59 +243,52 @@ deploy() {
244243
245244 log " deploying ${ref} "
246245
247- # PR #50
246+ # 1- Execute local commands
248247 log executing pre-deploy-local
249248 local pdl=` config_get pre-deploy-local`
250249 runLocal $pdl || abort pre-deploy-local hook failed
251250
251+ # 2- Execute pre deploy commands on remote server
252252 hook pre-deploy || abort pre-deploy hook failed
253253
254- if run " cd $path /source && git cat-file -t $branch " > /dev/null; then
255- log fast forward $branch
256- run " cd $path /source && git checkout $branch && git pull origin $branch "
257- test $? -eq 0 || abort git pull failed
258- else
259- # fetch source
260- log fetching updates
261-
262- if test " $fetch " ! = " fast" ; then
254+ # 3- Fetch updates
255+ log fetching updates
256+ if test " $fetch " ! = " fast" ; then
263257 log " full fetch"
264258 run " cd $path /source && git fetch --all --tags"
265- else
259+ else
266260 log " fast fetch"
267261 run " cd $path /source && git fetch --depth=5 --all --tags"
268- fi
269-
270- test $? -eq 0 || abort fetch failed
271-
272- # checkout ref to branch
273- log checkout $ref to $branch
274- run " cd $path /source && git checkout $ref -b $branch "
275- test $? -eq 0 || abort git checkout failed
276262 fi
263+ test $? -eq 0 || abort fetch failed
264+
265+ # 4- If no reference retrieve shorthand name for the remote repo
266+ if test -z " $ref " ; then
267+ log fetching latest tag
268+ ref=` run " cd $path /source && git for-each-ref \
269+ --sort=-*authordate \
270+ --format='%(refname)' \
271+ --count=1 | cut -d '/' -f 3" `
272+ test $? -eq 0 || abort failed to determine latest tag
273+ fi
274+
275+ # 5- Reset to ref
276+ log resetting HEAD to $ref
277+ run " cd $path /source && git reset --hard $ref "
278+ test $? -eq 0 || abort git reset failed
277279
278- # link current
280+ # 6- Link current
279281 run " ln -sfn $path /source $path /current"
280282 test $? -eq 0 || abort symlink failed
281283
282284 # deploy log
283285 run " cd $path /source && \
284- echo \` git rev-parse --short HEAD\` \
286+ echo \` git rev-parse HEAD\` \
285287 >> $path /.deploys"
286288 test $? -eq 0 || abort deploy log append failed
287289
288290 hook post-deploy || abort post-deploy hook failed
289291
290- if test $TEST -eq 1; then
291- hook test
292- if test $? -ne 0; then
293- log tests failed, reverting deploy
294- quickly_revert_to 1 && log " revert complete" && exit
295- fi
296- else
297- log ignoring tests
298- fi
299-
300292 # done
301293 log successfully deployed $ref
302294}
@@ -330,17 +322,6 @@ list_deploys() {
330322 run " tac $path /.deploys | awk '{printf \" %d\t%s\n\" , NR-1, \$ 0}'"
331323}
332324
333- #
334- # Revert to the <n>th last deployment, ignoring tests.
335- #
336-
337- quickly_revert_to () {
338- local n=$1
339- log " quickly reverting $n deploy(s)"
340- local commit=` nth_deploy_commit $(( n + 1 )) `
341- TEST=0 deploy " $commit "
342- }
343-
344325#
345326# Revert to the <n>th last deployment.
346327#
@@ -375,7 +356,6 @@ while test $# -ne 0; do
375356 -h|--help) usage; exit ;;
376357 -V|--version) version; exit ;;
377358 -C|--chdir) log cd $1 ; cd $1 ; shift ;;
378- -T|--no-tests) TEST=0 ;;
379359 -F|--force) FORCE=1 ;;
380360 run|exec) run " cd ` config_get path` /current && $@ " ; exit ;;
381361 console) console; exit ;;
391371
392372check_for_local_changes
393373
374+ echo
394375# deploy
395376deploy " ${REF:- `config_get ref`} " " ${BRANCH} "
0 commit comments