MOBILE-4286 github: Branch name changes

main
Pau Ferrer Ocaña 2023-03-16 11:52:28 +01:00
parent d2e34e3d87
commit 7f7f547d4d
12 changed files with 214 additions and 64 deletions

View File

@ -27,29 +27,41 @@ function print_success {
}
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
MESSAGE="Travis error: $1%0ABranch: $TRAVIS_BRANCH%0ARepo: $TRAVIS_REPO_SLUG"
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"
@ -64,6 +76,70 @@ function notify_on_error_exit {
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"
}
function get_behat_plugin_changes_diff {
# Grab hashes from app repository
currenthash=`git rev-parse HEAD`

View File

@ -1,14 +1,13 @@
#!/bin/bash
source "./.github/scripts/functions.sh"
BRANCH=${GITHUB_REF##*/}
if [ -z $GIT_TOKEN ] || [ -z $BRANCH ] || [ $GITHUB_REPOSITORY != 'moodlehq/moodleapp' ]; then
if [ -z $GIT_TOKEN ] || [ -z $GITHUB_REF_NAME ] || [ $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
git push -f mirror HEAD:$GITHUB_REF_NAME
notify_on_error_exit "MIRROR: Unsuccessful mirror, stopping..."
git push -f mirror --tags
notify_on_error_exit "MIRROR: Unsuccessful mirror tags, stopping..."

View File

@ -7,7 +7,6 @@ if [ -z $GIT_TOKEN ] || [ $GITHUB_REPOSITORY != 'moodlemobile/moodleapp' ]; then
fi
print_title "Run prepare scripts"
# TODO Change branch name.
git clone --depth 1 --single-branch --branch ionic5 https://$GIT_TOKEN@github.com/moodlemobile/apps-scripts.git ../scripts
cp ../scripts/*.sh scripts/

View File

@ -14,7 +14,7 @@ fi
# Clone plugin repository.
print_title "Cloning Behat plugin repository..."
git clone https://$GIT_TOKEN@github.com/$BEHAT_PLUGIN_GITHUB_REPOSITORY.git tmp/local_moodleappbehat -b integration
git clone https://$GIT_TOKEN@github.com/$BEHAT_PLUGIN_GITHUB_REPOSITORY.git tmp/local_moodleappbehat -b $GITHUB_REF_NAME
pluginversion=$(cat tmp/local_moodleappbehat/version.php | grep "\$plugin->version" | grep -o -E "[0-9]+")
# Auto-generate plugin.

View File

@ -16,9 +16,7 @@ on:
required: true
default: 'https://github.com/moodle/moodle'
pull_request:
branches:
- integration
- unscheduled
branches: [ main, v*.x ]
jobs:
behat:

View File

@ -2,7 +2,7 @@ name: Mirror
on:
push:
branches: [ master, main, unscheduled, integration, beta ]
branches: [ main, v*.x ]
jobs:
mirror:

View File

@ -2,7 +2,7 @@ name: Prepare
on:
push:
branches: [ master, main, unscheduled, integration, beta, freemium-master, freemium-main ]
branches: [ main, freemium-main, v*.x, freemium-v*.x ]
jobs:
prepare:

View File

@ -7,7 +7,6 @@ if [ -z $GIT_TOKEN ]; then
fi
print_title "Run scripts"
# TODO Change branch name.
git clone --depth 1 --single-branch --branch ionic5 https://$GIT_TOKEN@github.com/moodlemobile/apps-scripts.git ../scripts
cp ../scripts/*.sh scripts/

View File

@ -27,29 +27,41 @@ function print_success {
}
function print_error {
tput setaf 1; echo " ERROR: $1"; tput sgr0
[[ -n "$TERM" ]] && tput setaf 1
echo " ERROR: $1"
[[ -n "$TERM" ]] && tput sgr0
}
function print_ok {
tput setaf 2; echo " OK: $1"; tput sgr0
[[ -n "$TERM" ]] && tput setaf 2
echo " OK: $1"
[[ -n "$TERM" ]] && tput sgr0
echo
}
function print_message {
tput setaf 3; echo "-------- $1"; tput sgr0
[[ -n "$TERM" ]] && tput setaf 3
echo "-------- $1"
[[ -n "$TERM" ]] && tput sgr0
echo
}
function print_title {
stepnumber=$(($stepnumber + 1))
echo
tput setaf 5; echo "$stepnumber $1"; tput sgr0
tput setaf 5; echo '=================='; tput sgr0
[[ -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
MESSAGE="Travis error: $1%0ABranch: $TRAVIS_BRANCH%0ARepo: $TRAVIS_REPO_SLUG"
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"
@ -63,3 +75,67 @@ function notify_on_error_exit {
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"
}

View File

@ -10,58 +10,66 @@ DEFAULT_LASTVERSION='4.1' # Update it every version.
# Checks if AWS is available and configured.
function check_aws {
AWS_SERVICE=1
if [ ! -z $AWS_SERVICE ]; then
return
fi
export AWS_SERVICE=1
aws --version &> /dev/null
if [ $? -ne 0 ]; then
AWS_SERVICE=0
export AWS_SERVICE=0
echo 'AWS not installed. Check https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html for more info.'
return
fi
# In order to login to AWS, use credentials file or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY vars.
if [ ! -f ~/.aws/credentials ] && ([ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]); then
AWS_SERVICE=0
lastversion=$DEFAULT_LASTVERSION
export AWS_SERVICE=0
echo 'AWS Cannot authenticate. Use aws configure or set the proper env vars.'
return
fi
}
# Get last version of Moodle to fetch latest languages.
function get_last_version {
if [ ! -z "${lastversion}" ]; then
return
fi
function list_aws_files {
local folder="$1"
check_aws
if [ $AWS_SERVICE -eq 0 ]; then
lastversion=$DEFAULT_LASTVERSION
echo "Using default version $lastversion"
if [ $AWS_SERVICE -eq 1 ]; then
export AWS_FOLDERS=`aws s3 ls s3://$BUCKET/$1`
else
export AWS_FOLDERS=[]
fi
}
# Get last version of Moodle to fetch latest languages.
function get_lang_version {
if [ ! -z "${LANGVERSION}" ]; then
return
fi
list=`aws s3 ls s3://$BUCKET/`
if [ $? -ne 0 ]; then
AWS_SERVICE=0
lastversion=$DEFAULT_LASTVERSION
echo "AWS Cannot authenticate. Using default version $lastversion"
APP_VERSION=`jq -r '.versionname' ../moodle.config.json| cut -d. -f1-2`
if [ ! -z $APP_VERSION ]; then
export LANGVERSION=$APP_VERSION
echo "Using app version $LANGVERSION"
return
fi
lastversion=''
for folder in $list; do
list_aws_files ''
LANGVERSION=''
for folder in $AWS_FOLDERS; do
if [ $folder != 'PRE' ]; then
lastversion=${folder/\//}
LANGVERSION=${folder/\//}
fi
done
if [ ! -z "${lastversion}" ]; then
echo "Last version $lastversion detected"
if [ ! -z "${LANGVERSION}" ]; then
echo "Using last version $LANGVERSION detected"
return
fi
lastversion=$DEFAULT_LASTVERSION
LANGVERSION=$DEFAULT_LASTVERSION
echo "Using default version $LANGVERSION"
}
# Create langfolder
@ -71,21 +79,23 @@ function create_langfolder {
fi
}
# Get all language list from AWS.
function get_all_languages_aws {
langsfiles=`aws s3 ls s3://$BUCKET/$lastversion/`
# Get language list from the installed ones (will not discover new translations).
function get_language_folders {
list_aws_files "$LANGVERSION/"
langs=""
for file in $langsfiles; do
for file in $AWS_FOLDERS; do
if [[ "$file" == *.zip ]]; then
file=${file/\.zip/}
langs+="$file "
fi
done
}
if [ -z "${LANGVERSION}" ]; then
# Get language list from the installed ones (will not discover new translations).
function get_installed_languages {
echo "Fallback language list will only get current installation languages"
langs=`jq -r '.languages | keys[]' ../moodle.config.json`
fi
}
# Entry function to get a language file.
@ -93,7 +103,7 @@ function get_language {
lang=$1
lang=${lang/-/_}
get_last_version
get_lang_version
create_langfolder
@ -101,7 +111,7 @@ function get_language {
pushd $LANGPACKSFOLDER > /dev/null
curl -s $MOODLEORG_URL/$lastversion/$lang.zip --output $lang.zip > /dev/null
curl -s $MOODLEORG_URL/$LANGVERSION/$lang.zip --output $lang.zip > /dev/null
size=$(du -k "$lang.zip" | cut -f 1)
if [ ! -n $lang.zip ] || [ $size -le 1 ]; then
echo "Wrong language name or corrupt file for $lang"
@ -115,7 +125,7 @@ function get_language {
unzip -o -u $lang.zip > /dev/null
# This is the AWS version to get the language but right now it's slower.
# aws s3 cp s3://$BUCKET/$lastversion/$lang.zip . > /dev/null
# aws s3 cp s3://$BUCKET/$LANGVERSION/$lang.zip . > /dev/null
rm $lang.zip
popd > /dev/null
@ -128,7 +138,7 @@ function get_languages {
suffix=''
fi
get_last_version
get_lang_version
if [ -d $LANGPACKSFOLDER ]; then
lastupdate=`date -r $LANGPACKSFOLDER +%s`
@ -142,14 +152,7 @@ function get_languages {
create_langfolder
fi
if [ $AWS_SERVICE -eq 1 ]; then
get_all_languages_aws
suffix=''
else
echo "Fallback language list will only get current installation languages"
get_installed_languages
fi
get_language_folders
for lang in $langs; do
get_language "$lang"

View File

@ -14,7 +14,7 @@ print_title 'Generating language from code...'
npx gulp lang
print_title 'Getting local mobile langs'
git clone --branch master --depth 1 https://github.com/moodlehq/moodle-local_moodlemobileapp.git ../../moodle-local_moodlemobileapp
git clone --depth 1 https://github.com/moodlehq/moodle-local_moodlemobileapp.git ../../moodle-local_moodlemobileapp
if [ -z $forceLang ]; then
get_languages

View File

@ -52,7 +52,7 @@ export class CoreSettingsLicensesPage implements OnInit {
constructor() {
this.appLicenseVersion = CoreConstants.CONFIG.versionname.indexOf('-') > 0
? 'integration'
? 'main'
: 'v' + CoreConstants.CONFIG.versionname;
this.licensesUrl = 'https://raw.githubusercontent.com/moodlehq/moodleapp/' + this.appLicenseVersion + '/licenses.json';