diff --git a/.travis.yml b/.travis.yml index 94ce485a0..4f753316a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,10 +16,11 @@ cache: - "${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/" - "$HOME/.gradle/caches/" - "$HOME/.gradle/wrapper/" +before_script: + - bash scripts/prep-key.sh script: - ./gradlew build - ./gradlew testPlayStoreDebugUnitTestCoverage after_success: - bash <(curl -s https://codecov.io/bash) - - bash scripts/prep-key.sh - bash scripts/update-apk.sh diff --git a/app/build.gradle b/app/build.gradle index edbf1b26e..61ba13c34 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,10 +4,13 @@ apply plugin: 'com.noveogroup.android.check' apply from: './jacoco.gradle' apply plugin: 'com.google.gms.oss.licenses.plugin' apply plugin: "net.ltgt.errorprone" +apply plugin: "com.github.b3er.local.properties" def app_name = System.getenv('app_name') ?: "Eventyay Organizer" def GOOGLE_PLACES_API_KEY = System.getenv('GOOGLE_PLACES_API_KEY') ?: "YOUR_API_KEY" +def LOCAL_KEY_PRESENT = project.hasProperty('SIGNING_KEY_FILE') && rootProject.file(SIGNING_KEY_FILE).exists() + android { lintOptions { warning 'InvalidPackage' @@ -33,6 +36,25 @@ android { GOOGLE_PLACES_API_KEY: GOOGLE_PLACES_API_KEY ] } + + signingConfigs { + if (TRAVIS_BUILD) { + release { + storeFile KEYSTORE_FILE + storePassword System.getenv("STORE_PASS") + keyAlias System.getenv("ALIAS") + keyPassword System.getenv("KEY_PASS") + } + } else if (LOCAL_KEY_PRESENT) { + release { + storeFile rootProject.file(SIGNING_KEY_FILE) + storePassword STORE_PASS + keyAlias ALIAS + keyPassword KEY_PASS + } + } + } + buildTypes { release { minifyEnabled true @@ -41,6 +63,9 @@ android { buildConfigField "String", "DEFAULT_BASE_URL", '"https://api.eventyay.com/v1/"' resValue "string", "default_base_url", '"https://api.eventyay.com/v1/"' + + if (LOCAL_KEY_PRESENT || TRAVIS_BUILD) + signingConfig signingConfigs.release } debug { testCoverageEnabled = true @@ -48,6 +73,7 @@ android { resValue "string", "default_base_url", '"https://open-event-api-dev.herokuapp.com/v1/"' } } + dataBinding { enabled true } diff --git a/build.gradle b/build.gradle index 5244e8697..61839692a 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ buildscript { classpath 'com.noveogroup.android:check:1.2.5' classpath "com.google.gms:oss-licenses:0.9.2" classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.8.1" + classpath "gradle.plugin.com.github.b3er.local.properties:local-properties-plugin:1.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -26,6 +27,11 @@ allprojects { google() jcenter() } + + ext { + KEYSTORE_FILE = rootProject.file('scripts/key.jks') + TRAVIS_BUILD = System.getenv("TRAVIS") == "true" && KEYSTORE_FILE.exists() + } } task clean(type: Delete) { diff --git a/scripts/prep-key.sh b/scripts/prep-key.sh index c9e84474a..97d9305f0 100755 --- a/scripts/prep-key.sh +++ b/scripts/prep-key.sh @@ -1,9 +1,10 @@ #!/bin/sh set -e -export DEPLOY_BRANCH=${DEPLOY_BRANCH:-master} +export DEPLOY_BRANCH=${DEPLOY_BRANCH:-development} +export PUBLISH_BRANCH=${PUBLISH_BRANCH:-master} -if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "fossasia/open-event-orga-app" -o "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then +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 decrypt key only for pushes to the master branch and not PRs. So, skip." exit 0 fi diff --git a/scripts/update-apk.sh b/scripts/update-apk.sh index 8dfbdd3e9..3151b2113 100755 --- a/scripts/update-apk.sh +++ b/scripts/update-apk.sh @@ -7,11 +7,13 @@ git config --global user.email "noreply+travis@fossasia.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-orga-app" ] || ! [ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" -o "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then +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://niranjan94:$GITHUB_API_KEY@github.com/fossasia/open-event-orga-app apk > /dev/null cd apk @@ -21,21 +23,8 @@ else /bin/rm -f eventyay-organizer-dev-*.apk fi -\cp -r ../app/build/outputs/apk/playStore/*/**.apk . -\cp -r ../app/build/outputs/apk/fdroid/*/**.apk . -\cp -r ../app/build/outputs/apk/playStore/debug/output.json playStore-debug-output.json -\cp -r ../app/build/outputs/apk/playStore/release/output.json playStore-release-output.json -\cp -r ../app/build/outputs/apk/fdroid/debug/output.json fdroid-debug-output.json -\cp -r ../app/build/outputs/apk/fdroid/release/output.json fdroid-release-output.json - -# Signing Apps - -if [ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then - echo "Push to master branch detected, signing the app..." - cp app-playStore-release-unsigned.apk app-playStore-release-unaligned.apk - jarsigner -verbose -tsa http://timestamp.comodoca.com/rfc3161 -sigalg SHA1withRSA -digestalg SHA1 -keystore ../scripts/key.jks -storepass $STORE_PASS -keypass $KEY_PASS app-playStore-release-unaligned.apk $ALIAS - ${ANDROID_HOME}/build-tools/27.0.3/zipalign -v -p 4 app-playStore-release-unaligned.apk app-playStore-release.apk -fi +find ../app/build/outputs -type f -name '*.apk' -exec cp -v {} . \; +find ../app/build/outputs -type f -name '*.aab' -exec cp -v {} . \; if [ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then for file in app*; do @@ -71,4 +60,4 @@ if [ "$TRAVIS_BRANCH" != "$PUBLISH_BRANCH" ]; then fi gem install fastlane -fastlane supply --apk eventyay-organizer-master-app-playStore-release.apk --track alpha --json_key ../scripts/fastlane.json --package_name $PACKAGE_NAME +fastlane supply --aab eventyay-organizer-master-app.aab --track alpha --json_key ../scripts/fastlane.json --package_name $PACKAGE_NAME