diff --git a/scripts/functions.sh b/scripts/functions.sh index 5f9513299..c875be20f 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -48,4 +48,21 @@ function print_title { echo tput setaf 5; echo "$stepnumber $1"; tput sgr0 tput setaf 5; echo '=================='; tput sgr0 -} \ No newline at end of file +} + +function telegram_notify { + if [ ! -z $TELEGRAM_APIKEY ] && [ ! -z $TELEGRAM_CHATID ] ; then + MESSAGE="Travis error: $1%0ABranch: $TRAVIS_BRANCH%0ARepo: $TRAVIS_REPO_SLUG" + URL="https://api.telegram.org/bot$TELEGRAM_APIKEY/sendMessage" + + curl -s -X POST $URL -d chat_id=$TELEGRAM_CHATID -d text="$MESSAGE" + fi +} + +function notify_on_error_exit { + if [ $? -ne 0 ]; then + print_error "$1" + telegram_notify "$1" + exit 1 + fi +} diff --git a/scripts/mirror.sh b/scripts/mirror.sh index 5ff8468c8..32e4efa4a 100755 --- a/scripts/mirror.sh +++ b/scripts/mirror.sh @@ -63,18 +63,18 @@ if [ "$TRAVIS_BRANCH" == 'master' ]; then git commit -m 'Update licenses [ci skip]' git push origin HEAD:$TRAVIS_BRANCH - check_success_exit "Unsuccessful push, stopping..." + notify_on_error_exit "MIRROR: Unsuccessful push, stopping..." fi if [ "$TRAVIS_BRANCH" == 'integration' ] || [ "$TRAVIS_BRANCH" == 'master' ] || [ "$TRAVIS_BRANCH" == 'desktop' ] ; then print_title "Mirror repository" git remote add mirror https://$GIT_TOKEN@github.com/$GIT_ORG_PRIVATE/moodleapp.git git fetch -q --unshallow mirror - check_success_exit "Unsuccessful fetch of mirror, stopping..." + notify_on_error_exit "MIRROR: Unsuccessful fetch of mirror, stopping..." git fetch -q origin --depth=100 - check_success_exit "Unsuccessful fetch of origin, stopping..." + notify_on_error_exit "MIRROR: Unsuccessful fetch of origin, stopping..." git push -f mirror HEAD:$TRAVIS_BRANCH - check_success_exit "Unsuccessful mirror, stopping..." + notify_on_error_exit "MIRROR: Unsuccessful mirror, stopping..." git push -f mirror --tags - check_success_exit "Unsuccessful mirror tags, stopping..." + notify_on_error_exit "MIRROR: Unsuccessful mirror tags, stopping..." fi diff --git a/scripts/test_e2e.sh b/scripts/test_e2e.sh index 87174db70..cab0b094e 100755 --- a/scripts/test_e2e.sh +++ b/scripts/test_e2e.sh @@ -1,5 +1,7 @@ #!/bin/bash +source "scripts/functions.sh" + # Prepare variables basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )" dockerscripts="$HOME/moodle-docker/bin/" @@ -12,7 +14,7 @@ export MOODLE_DOCKER_PHP_VERSION=7.3 export MOODLE_DOCKER_APP_PATH=$basedir # Prepare dependencies -echo "Preparing dependencies" +print_title "Preparing dependencies" git clone --branch master --depth 1 git://github.com/moodle/moodle $HOME/moodle git clone --branch master --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $HOME/moodle/local/moodlemobileapp # git clone --branch master --depth 1 git://github.com/moodlehq/moodle-docker $HOME/moodle-docker @@ -29,12 +31,12 @@ cd - cp $HOME/moodle-docker/config.docker-template.php $HOME/moodle/config.php # Build app -echo "Building app" +print_title "Building app" npm install npm run setup # Start containers -echo "Starting containers" +print_title "Starting containers" $dockercompose pull $dockercompose up -d $dockerscripts/moodle-docker-wait-for-db @@ -44,9 +46,10 @@ $dockercompose exec -T webserver php admin/tool/behat/cli/init.php # Run tests for tags in "$@" do - echo "Running e2e tests ($tags)" + print_title "Running e2e tests ($tags)" $dockercompose exec -T webserver php admin/tool/behat/cli/run.php --tags="$tags" + notify_on_error_exit "e2e failed on $tags" done # Clean up