From 454476141731a69fb4854cd537912dd59d04e03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 25 Feb 2021 12:02:08 +0100 Subject: [PATCH] MOBILE-3708 github: Add mirroring action --- .github/scripts/functions.sh | 65 +++++++++++++++++++++++++++++++++++ .github/scripts/mirror.sh | 14 ++++++++ .github/workflows/mirror.yml | 20 +++++++++++ .github/workflows/testing.yml | 2 +- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 .github/scripts/functions.sh create mode 100755 .github/scripts/mirror.sh create mode 100644 .github/workflows/mirror.yml diff --git a/.github/scripts/functions.sh b/.github/scripts/functions.sh new file mode 100644 index 000000000..f36fba1fc --- /dev/null +++ b/.github/scripts/functions.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +function check_success_exit { + if [ $? -ne 0 ]; then + print_error "$1" + exit 1 + elif [ "$#" -gt 1 ]; then + print_ok "$2" + fi +} + +function check_success { + if [ $? -ne 0 ]; then + print_error "$1" + elif [ "$#" -gt 1 ]; then + print_ok "$2" + fi +} + +function print_success { + if [ $? -ne 0 ]; then + print_message "$1" + $3=0 + else + print_ok "$2" + fi +} + +function print_error { + echo " ERROR: $1" +} + +function print_ok { + echo " OK: $1" + echo +} + +function print_message { + echo "-------- $1" + echo +} + +function print_title { + stepnumber=$(($stepnumber + 1)) + echo + echo "$stepnumber $1" + echo '==================' +} + +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/.github/scripts/mirror.sh b/.github/scripts/mirror.sh new file mode 100755 index 000000000..da245c76d --- /dev/null +++ b/.github/scripts/mirror.sh @@ -0,0 +1,14 @@ +#!/bin/bash +source "/.github/scripts/functions.sh" +BRANCH=${GITHUB_REF##*/} + +if [ -z $GIT_TOKEN ] || [ -z $BRANCH ] || [ $GITHUB_REPOSITORY != 'moodlehq/moodleapp' ]; then + print_error "Env vars not correctly defined" + exit 1 +fi + +git remote add mirror https://$GIT_TOKEN@github.com/moodlemobile/moodleapp.git +git push -f mirror HEAD:$BRANCH +notify_on_error_exit "MIRROR: Unsuccessful mirror, stopping..." +git push -f mirror --tags +notify_on_error_exit "MIRROR: Unsuccessful mirror tags, stopping..." diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 000000000..266221e6c --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,20 @@ +name: Mirror + +on: + push: + branches: [ master, integration, ionic5 ] + +jobs: + mirror: + if: github.repository == 'moodlehq/moodleapp' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + fetch-depth: 0 + - name: Mirror the branch and tags + env: + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} + run: ./.github/scripts/mirror.sh diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 73abf1fe4..1f2840aca 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -3,7 +3,7 @@ name: Testing on: [push, pull_request] jobs: - build: + test: runs-on: ubuntu-latest