summaryrefslogtreecommitdiff
path: root/nightly.sh
blob: 4c926591a6ad05c87f7237acdfbed264baf88227 (plain)
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
#!/bin/bash


TITLE="master"
HOME="/home/ist"
LAZARDIR="$HOME/lazar"
LAZARGUI="$HOME/lazar-gui"
BRANCH="master"

. $HOME/.bashrc

GIT=`which git`
DATE=`date +%y%m%d`
separator="============================"

LOGDIR="$HOME/log"
COMID="$LOGDIR/id.log"
ERRLOG="$LOGDIR/$DATE-err.log"
LOG="$LOGDIR/$DATE.log"
MSG="$HOME/msg.log"
rm "$LOG" 2>/dev/null
rm "$ERRLOG" 2>/dev/null
rm "$MSG" 2>/dev/null

touch $COMID
touch $LOG
touch $ERRLOG
touch $MSG

if ! cd "$LAZARDIR"; then
  echo "lazar dir not found."
  exit 1
fi

# pull lazar code from github
if ! $GIT checkout $BRANCH; then
  echo "lazar checkout to $BRANCH failed."
  exit 1
fi

if ! $GIT pull; then
  echo "lazar pull failed."
  exit 1
fi

if ! cd $LAZARDIR/test; then
  echo "test dir not found."
  exit 1
fi


task_out=""
echo "https://github.com/opentox/lazar | branch: $BRANCH | latest commit:" >> $MSG
$GIT log|head -6 | tee -a $LOG $MSG
echo $separator >>$MSG


cd $LAZARDIR/test
tests=(*.rb)
exclude=(setup.rb all.rb default_environment.rb model-nanoparticle.rb nanomaterial-model-validation.rb validation-nanoparticle.rb)
for i in ${exclude[@]}; do
  # delete exclute from tests list
  tests=(${tests[@]//*$i*})
done

for t in ${tests[@]}; do
  echo $separator | tee -a $LOG $MSG
  echo " "$t|tr [a-z] [A-Z] | tee -a $LOG $MSG
  echo " "`date` | tee -a $LOG $MSG
  echo $separator | tee -a $LOG $MSG
  echo ruby $t | tee -a $LOG $MSG
  # whole test output to logfile only
  ruby $t >> $LOG
  # take last occurrence of regex to end of the file
  awk '/^Finished in/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' $LOG >> $MSG
  echo "" >> $LOG
done

cd $LAZARGUI/test
tests=(*.rb)
for t in ${tests[@]}; do
  echo $separator | tee -a $LOG $MSG
  echo " "$t|tr [a-z] [A-Z] | tee -a $LOG $MSG
  echo " "`date` | tee -a $LOG $MSG
  echo $separator | tee -a $LOG $MSG
  echo ruby $t | tee -a $LOG $MSG
  # whole test output to logfile only
  ruby $t >> $LOG
  # take last occurrence of regex to end of the file
  awk '/^Finished in/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' $LOG >> $MSG
  echo "" >> $LOG
done

# MAIL 
file="$HOME/scripts/recipients"
recipients=$(cat $file) 
if grep -q "Error:" $LOG; then ERRMSG=" ERROR (`grep -c ' Error:' $LOG`)"; else ERRMSG=" OK "; fi
if grep -q "Failure:" $LOG; then FAILMSG=" FAIL (`grep -c ' Failure:' $LOG`)"; else FAILMSG=""; fi

for p in ${recipients[@]}; do
  { printf "To: $p\nSubject: [lazar nightly test] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $MSG; } | msmtp -a default $p
done

# drop database
mongo development --eval "db.dropDatabase()"

rm $COMID
touch $COMID
$GIT log|head -1 >> $COMID
exit 0