From 432201c4e528bd4872ddf2d28fa814302768fe62 Mon Sep 17 00:00:00 2001 From: stealthanthrax Date: Sun, 27 Dec 2020 04:23:14 +0530 Subject: [PATCH] Add a system of automated deploys --- .travis.yml | 29 +++++++++++++++++ scripts/update_apk.sh | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 .travis.yml create mode 100755 scripts/update_apk.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..7bfa0a78c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +language: android +dist: trusty +sudo: false +jdk: + - oraclejdk8 +android: + components: + - tools + - android-28 + - build-tools-28.0.3 + - platform-tools +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock +cache: + directories: + - "${TRAVIS_BUILD_DIR}/gradle/caches/" + - "${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/" + - "$HOME/.gradle/caches/" + - "$HOME/.gradle/wrapper/" +script: + # - ./gradlew spotlessCheck + - ./gradlew build +after_success: + - bash scripts/update-apk.sh + +branches: + only: + - master + - development diff --git a/scripts/update_apk.sh b/scripts/update_apk.sh new file mode 100755 index 000000000..fca7413c4 --- /dev/null +++ b/scripts/update_apk.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -e + +git config --global user.name "Travis CI" +git config --global user.email "noreply+travis@robotutor.org" + +export DEPLOY_BRANCH=${DEPLOY_BRANCH:-development} +export PUBLISH_BRANCH=${PUBLISH_BRANCH:-master} + +if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "fossasia/open-event-organizer-android" ] || ! [ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" -o "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then + echo "We upload apk only for changes in development or master, and not PRs. So, let's skip this shall we ? :)" + exit 0 +fi + +./gradlew bundlePlayStoreRelease + +git clone --quiet --branch=apk https://robotutor:$GITHUB_API_KEY@github.com/RoboTutorLLC/RoboTutor_2020 apk > /dev/null +cd apk + +if [ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then + /bin/rm -f * +else + /bin/rm -f eventyay-organizer-dev-* +fi + +find ../app/build/outputs -type f -name '*.apk' -exec cp -v {} . \; +find ../app/build/outputs -type f -name '*.aab' -exec cp -v {} . \; + +for file in app*; do + + if [ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then + if [[ ${file} =~ ".aab" ]]; then + mv $file eventyay-organizer-master-${file} + else + mv $file eventyay-organizer-master-${file:4} + fi + + elif [ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" ]; then + if [[ ${file} =~ ".aab" ]]; then + mv $file eventyay-organizer-dev-${file} + else + mv $file eventyay-organizer-dev-${file:4} + fi + + fi + +done + +# Create a new branch that will contains only latest apk +git checkout --orphan temporary + +# Add generated APK +git add --all . +git commit -am "[Auto] Update Test Apk ($(date +%Y-%m-%d.%H:%M:%S))" + +# Delete current apk branch +git branch -D apk +# Rename current branch to apk +git branch -m apk + +# Force push to origin since histories are unrelated +git push origin apk --force --quiet > /dev/null + +# Publish App to Play Store +# if [ "$TRAVIS_BRANCH" != "$PUBLISH_BRANCH" ]; then +# echo "We publish apk only for changes in master branch. So, let's skip this shall we ? :)" +# exit 0 +# fi + +# cd .. +# gem install fastlane +# fastlane supply --aab ./apk/eventyay-organizer-master-app-playStore-release.aab --skip_upload_apk true --track alpha --json_key ./scripts/fastlane.json --package_name $PACKAGE_NAME +