Merge pull request #3586 from crazyserver/MOBILE-4286

MOBILE-4286 github: Split prepare into release and merge script
main
Dani Palou 2023-03-23 12:36:33 +01:00 committed by GitHub
commit e957d187d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 156 deletions

View File

@ -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

View File

@ -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

23
.github/scripts/release.sh vendored 100755
View File

@ -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

View File

@ -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

18
.github/workflows/release.yml vendored 100644
View File

@ -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

View File

@ -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 {