Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Simplify signing and APK generation #1770

Merged
merged 8 commits into from
Jul 2, 2019
Merged
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -41,13 +63,17 @@ 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
buildConfigField "String", "DEFAULT_BASE_URL", '"https://open-event-api-dev.herokuapp.com/v1/"'
resValue "string", "default_base_url", '"https://open-event-api-dev.herokuapp.com/v1/"'
}
}

dataBinding {
enabled true
}
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/prep-key.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 6 additions & 17 deletions scripts/update-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ git config --global user.email "[email protected]"
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:[email protected]/fossasia/open-event-orga-app apk > /dev/null
cd apk

Expand All @@ -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
Expand Down Expand Up @@ -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