Skip to content

Commit

Permalink
Enable Travis CI to auto-deploy APKs
Browse files Browse the repository at this point in the history
The resulting APK of a CI build is now automatically uploaded to GitHub
for tagged revisions. They are signed with the same key that is used in
the Google Play Store. All secrets are encrypted and only visible to
Travis CI.
  • Loading branch information
saemy committed Nov 8, 2017
1 parent 6ab9806 commit 8491abc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
46 changes: 40 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
language: android

env:
global:
# ORG_GRADLE_PROJECT_keystorePassword.
- secure: "TGGsl0Jdc6cKt0dHarl6/YobzOZTxtxGCSZiwDPZn2Qe2IAUb8JssvTviOkCtbXQesdjcHuvpVlG70Yz0sISxTanwJI6yRMmqAOm6mfr1bVvcaeFIXXEm1s8q8rQfHxOv0BTMxLQ2MdYkz6MteTOcn722e0NEs+lh73aSbCi0Os="

# ORG_GRADLE_PROJECT_keystoreKeyPassword.
- secure: "KbIFt5KMY6sMLsMtYQDbHUX8MtYQSY+6Lj9qc+jJdTAukc2qAtJLNyXKKQlG5pyoSN/F/hVBJKbmDDz2AY6ifMZkOpzVVKlN8E2MPG1BCln0BwMJactL1kLb+287oFg6tXDc6YoxImeKlpFMucy2RjeWwtZptmbsUiXT2UwhPn8="

android:
components:
# Specify the components that are needed to build the project.
Expand All @@ -16,14 +25,39 @@ android:
- extra-google-m2repository
- extra-android-m2repository

before_script:
# Decrypts the keystore (if this is not a PR build).
- 'if [ ${TRAVIS_SECURE_ENV_VARS} = "true" ]; then
openssl aes-256-cbc -d
-K $encrypted_d213628fe2b0_key -iv $encrypted_d213628fe2b0_iv
-in keystores/warmshowers.jks.enc -out "$HOME/warmshowers.jks" &&
export ORG_GRADLE_PROJECT_keystoreFile="$HOME/warmshowers.jks";
fi'

# Sets the (public) keystore settings.
- export ORG_GRADLE_PROJECT_keystoreKeyAlias="wsandroid"

before_cache:
# Clean up the cache.
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fR $HOME/.gradle/caches/*/plugin-resolution/
# Cleans up the cache.
- rm -f "$HOME/.gradle/caches/modules-2/modules-2.lock"
- rm -fR "$HOME/.gradle/caches/*/plugin-resolution/"
- rm -f "$HOME/warmshowers.jks"

cache:
directories:
- $HOME/.android/build-cache
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- "$HOME/.android/build-cache"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"

before_deploy:
- mv app/build/outputs/apk/app-release.apk wsandroid-$TRAVIS_TAG.apk

deploy:
# Deploys the release APK for tagged revisions to GitHub.
provider: releases
api_key:
secure: "dIzw4tJxXLPlA7wDdcgwLop6qcAU9lPTD4Z322APx6430Pevx93o6u8H6vnNMPytbpL4kpsxQjsqe+gz3DLB5vSUmftn0UF5GrjJTxNCeSj0wxW5kgeb2iuw4UsjpoI1FOroN0FxOg+CJUoD27MRwjjl4S9NnEVYmbcj9+8O8f4="
file: "wsandroid-$TRAVIS_TAG.apk"
skip_cleanup: true
on:
tags: true
19 changes: 6 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ dependencies {
testCompile 'org.json:json:20170516'
}


def propertiesFile = rootProject.file("local.properties")
def properties = new Properties()
if (propertiesFile.canRead()) {
properties.load(new FileInputStream(propertiesFile))
}

android {
buildToolsVersion "26.0.0"

Expand All @@ -57,14 +50,14 @@ android {
}

release {
if (properties['keystoreFile']) {
if (keystoreFile) {
doSignRelease = true

// Set these values in local.properties
storeFile file(properties['keystoreFile'])
storePassword properties['keystorePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
// Set these values in local.properties.
storeFile file(keystoreFile)
storePassword keystorePassword
keyAlias keystoreKeyAlias
keyPassword keystoreKeyPassword
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ ext {
isPreDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
}

// Loads the local properties.
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.canRead()) {
def localProperties = new Properties()
localProperties.load(new FileInputStream(localPropertiesFile))
localProperties.stringPropertyNames().each {
project.ext[it] = localProperties[it]
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Binary file added keystores/warmshowers.jks.enc
Binary file not shown.

0 comments on commit 8491abc

Please sign in to comment.