diff --git a/.github/scripts/functions.sh b/.github/scripts/functions.sh index 66e7e84c4..37217913e 100644 --- a/.github/scripts/functions.sh +++ b/.github/scripts/functions.sh @@ -1,144 +1,6 @@ #!/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 { - [[ -n "$TERM" ]] && tput setaf 1 - echo " ERROR: $1" - [[ -n "$TERM" ]] && tput sgr0 -} - -function print_ok { - [[ -n "$TERM" ]] && tput setaf 2 - echo " OK: $1" - [[ -n "$TERM" ]] && tput sgr0 - echo -} - -function print_message { - [[ -n "$TERM" ]] && tput setaf 3 - echo "-------- $1" - [[ -n "$TERM" ]] && tput sgr0 - echo -} - -function print_title { - stepnumber=$(($stepnumber + 1)) - echo - [[ -n "$TERM" ]] && tput setaf 5 - echo "$stepnumber $1" - [[ -n "$TERM" ]] && tput sgr0 - [[ -n "$TERM" ]] && tput setaf 5 - echo '==================' - [[ -n "$TERM" ]] && tput sgr0 -} - -function telegram_notify { - if [ ! -z $TELEGRAM_APIKEY ] && [ ! -z $TELEGRAM_CHATID ] ; then - set_branch_and_repo - - MESSAGE="$1%0ABranch: *$REFNAME* on $REPO%0ACommit: $COMMIT%0AJob: $JOB ($RUN_NUMBER) [Complete log here]($JOB_URL)" - 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 -} - - -function set_branch_and_repo { - if [ ! -z $REPO ]; then - # Already filled. - return; - fi - - if [ -z $TRAVIS_OS_NAME ]; then - #Run on github - if [ "$RUNNER_OS" == 'macOS' ]; then - export OS_NAME='osx' - elif [ "$RUNNER_OS" == 'Linux' ]; then - export OS_NAME='linux' - elif [ "$RUNNER_OS" == 'Windows' ]; then - export OS_NAME='windows' - fi - export REFNAME=$GITHUB_REF_NAME - export REFTYPE=$GITHUB_REF_TYPE - export REPO=$GITHUB_REPOSITORY - export COMMIT=$GITHUB_SHA - export JOB=$GITHUB_JOB - export JOB_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID - export RUN_NUMBER=$GITHUB_RUN_NUMBER - export CI_TYPE='github' - else - # Run on Travis - export OS_NAME=$TRAVIS_OS_NAME - if [ -z "$TRAVIS_TAG" ]; then - export REFTYPE='branch' - export REFNAME=$TRAVIS_BRANCH - else - export REFTYPE='tag' - export REFNAME=$TRAVIS_TAG - fi - export REPO=$TRAVIS_REPO_SLUG - export COMMIT=$TRAVIS_COMMIT - export JOB=$TRAVIS_JOB_NAME - export JOB_URL=$TRAVIS_JOB_WEB_URL - export RUN_NUMBER=$TRAVIS_BUILD_NUMBER - export CI_TYPE='travis' - fi - - if [ -z $REFNAME ]; then - print_error "Empty branch/tag, cancelling..." - exit 0 - fi - - if [ -z $REPO ]; then - print_error "Empty repo, cancelling..." - exit 0 - fi - - print_title "Build info:" - echo "OS_NAME: $OS_NAME" - echo "REFNAME: $REFNAME" - echo "REFTYPE: $REFTYPE" - echo "REPO: $REPO" - echo "COMMIT: $COMMIT" - echo "JOB: $JOB" - echo "JOB_URL: $JOB_URL" - echo "RUN_NUMBER: $RUN_NUMBER" - echo "CI_TYPE: $CI_TYPE" -} +source "./scripts/functions.sh" function get_behat_plugin_changes_diff { # Grab hashes from app repository diff --git a/.github/scripts/prepare.sh b/.github/scripts/merge.sh similarity index 71% rename from .github/scripts/prepare.sh rename to .github/scripts/merge.sh index 50fab6083..90842af2e 100755 --- a/.github/scripts/prepare.sh +++ b/.github/scripts/merge.sh @@ -6,17 +6,17 @@ if [ -z $GIT_TOKEN ] || [ $GITHUB_REPOSITORY != 'moodlemobile/moodleapp' ]; then exit 1 fi -print_title "Run prepare scripts" +print_title "Run merge scripts" git clone --depth 1 --single-branch --branch ionic5 https://$GIT_TOKEN@github.com/moodlemobile/apps-scripts.git ../scripts cp ../scripts/*.sh scripts/ -if [ ! -f scripts/prepare.sh ]; then - print_error "Prepare file not found" +if [ ! -f scripts/merge.sh ]; then + print_error "Merge file not found" exit 1 fi -print_title 'Prepare Build' -./scripts/prepare.sh +print_title 'Merge!' +./scripts/merge.sh if [ $? -ne 0 ]; then exit 1 diff --git a/.github/scripts/release.sh b/.github/scripts/release.sh new file mode 100755 index 000000000..0aa3416a5 --- /dev/null +++ b/.github/scripts/release.sh @@ -0,0 +1,23 @@ +#!/bin/bash +source "./.github/scripts/functions.sh" + +if [ -z $GIT_TOKEN ] ; then + print_error "Env vars not correctly defined" + exit 1 +fi + +print_title "Run release scripts" +git clone --depth 1 --single-branch --branch ionic5 https://$GIT_TOKEN@github.com/moodlemobile/apps-scripts.git ../scripts +cp ../scripts/*.sh scripts/ + +if [ ! -f scripts/release.sh ]; then + print_error "Release file not found" + exit 1 +fi + +print_title 'Create release tags' +./scripts/release.sh + +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/.github/workflows/prepare.yml b/.github/workflows/merge.yml similarity index 76% rename from .github/workflows/prepare.yml rename to .github/workflows/merge.yml index 5cd285e9b..6c32c0e28 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/merge.yml @@ -2,7 +2,7 @@ name: Prepare on: push: - branches: [ main, freemium-main, v*.x, freemium-v*.x ] + branches: [ main, v*.x ] jobs: prepare: @@ -17,4 +17,4 @@ jobs: - name: Prepare builds env: GIT_TOKEN: ${{ secrets.GIT_TOKEN }} - run: ./.github/scripts/prepare.sh + run: ./.github/scripts/merge.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..a6997291d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,18 @@ +name: Prepare + +on: workflow_dispatch + +jobs: + prepare: + if: github.repository == 'moodlehq/moodleapp' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + fetch-depth: 0 + - name: Create release tags + env: + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} + run: ./.github/scripts/release.sh diff --git a/scripts/functions.sh b/scripts/functions.sh index 0222ce43f..0edbb9d92 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -27,34 +27,34 @@ function print_success { } function print_error { - [[ -n "$TERM" ]] && tput setaf 1 + [[ -t 1 ]] && tput setaf 1 echo " ERROR: $1" - [[ -n "$TERM" ]] && tput sgr0 + [[ -t 1 ]] && tput sgr0 } function print_ok { - [[ -n "$TERM" ]] && tput setaf 2 + [[ -t 1 ]] && tput setaf 2 echo " OK: $1" - [[ -n "$TERM" ]] && tput sgr0 + [[ -t 1 ]] && tput sgr0 echo } function print_message { - [[ -n "$TERM" ]] && tput setaf 3 + [[ -t 1 ]] && tput setaf 3 echo "-------- $1" - [[ -n "$TERM" ]] && tput sgr0 + [[ -t 1 ]] && tput sgr0 echo } function print_title { stepnumber=$(($stepnumber + 1)) echo - [[ -n "$TERM" ]] && tput setaf 5 + [[ -t 1 ]] && tput setaf 5 echo "$stepnumber $1" - [[ -n "$TERM" ]] && tput sgr0 - [[ -n "$TERM" ]] && tput setaf 5 + [[ -t 1 ]] && tput sgr0 + [[ -t 1 ]] && tput setaf 5 echo '==================' - [[ -n "$TERM" ]] && tput sgr0 + [[ -t 1 ]] && tput sgr0 } function telegram_notify {