diff --git a/utils/test_repo.sh b/utils/test_repo.sh index 4765d64..2ef40c9 100755 --- a/utils/test_repo.sh +++ b/utils/test_repo.sh @@ -1,100 +1,112 @@ #!/bin/bash -e MAIL_BOT='admin+bot@c4science.ch' MAIL_MONIT='jean-baptiste.aubort@epfl.ch' TMPDIR=$(mktemp -d) LOGFILE='/tmp/test_repo.log' REPO_GIT='ssh://git@c4science.ch/diffusion/PHMONITGIT/monitoring-git.git' REPO_SVN='svn+ssh://git@c4science.ch/diffusion/PHMONITSVN/' REPO_HG='ssh://git@c4science.ch/diffusion/PHMONITHG/monitoring-hg/' +monit() { + name=$1 + cmd=$2 + + echo -n "$name " + _duration=$(echo "$(date +%s)+$(date +%3N)/1000" | bc -l) + $cmd 1> /dev/null || error $name + _exit=$? + _time=$(echo "$(date +%s)-$_duration + $(date +%3N)/1000" | bc -l) + echo "duration=$_time,exitcode=$_exit" +} + error() { cat $LOGFILE | mail -s "Error $1" $MAIL_MONIT } prepare() { git config --global user.name 'c4science bot' git config --global user.email $MAIL_BOT echo -e "[ui]\nusername = scitas-bot <$MAIL_BOT>" > ~/.hgrc } clean() { cd rm -fr $TMPDIR } # # GIT # test_clone_git() { git clone $REPO_GIT $TMPDIR } test_push_git() { cd $TMPDIR echo test >> README.md git add README.md git commit -m "Testing GIT..." git push origin master } test_lfs_git() { FILE=$(mktemp --suffix .lfs -p $TMPDIR) cd $TMPDIR cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1 > $FILE git lfs track $(basename $FILE) git add $FILE git commit -am "Testing GIT LFS..." git push origin master } # # SVN # test_checkout_svn() { svn checkout $REPO_SVN $TMPDIR } test_commit_svn() { cd $TMPDIR echo test >> README.md svn commit -m "Testing SVN..." } # # Mercurial # test_clone_hg() { hg clone $REPO_HG $TMPDIR } test_push_hg() { cd $TMPDIR echo test >> README.md hg commit -m "Testing Mercurial..." hg push } exec 2> $LOGFILE date >> $LOGFILE prepare -test_clone_git || error "git clone" -test_push_git || error "git push" -test_lfs_git || error "git lfs" +monit 'git_clone' test_clone_git +monit 'git_push' test_push_git +monit 'git_lfs' test_lfs_git clean -test_checkout_svn || error "svn checkout" -test_commit_svn || error "svn commit" +monit 'svn_checkout' test_checkout_svn +monit 'svn_commit' test_commit_svn clean -test_clone_hg || error "hg clone" -test_push_hg || error "hg push" +monit 'hg_clone' test_clone_hg +monit 'hg_push' test_push_hg clean