Skip to content

Commit

Permalink
Automatically publish builds to play store's alpha channel (#82)
Browse files Browse the repository at this point in the history
For commits to master with a tag, use a free library called fastlane to kick off gradle and upload the output to the Play Store.
  • Loading branch information
kennsippell authored Jun 19, 2019
1 parent e0da38d commit 70e501c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
# IntelliJ IDEA files
/.idea/
*.iml

secrets.tar.gz
medic-official.keystore
playstore-secret.json

fastlane/*
!fastlane/Fastfile
48 changes: 44 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,53 @@ android:
- android-26
env:
- GRADLE_OPTS="-XX:MaxPermSize=2048M"
stages:
- name: test
- name: deploy
if: tag IS present
jobs:
include:
- script: make test
- script: make travis
if: tag IS present
- stage: test
script: make test

- stage: deploy
# flavors sorted alphabetically with three per job
script:
- fastlane deploy flavor:unbranded
- fastlane deploy flavor:medicmobiledemo
- fastlane deploy flavor:bracuganda
- script:
- fastlane deploy flavor:cic_guatemala
- fastlane deploy flavor:ebpp_indonesia
- fastlane deploy flavor:hope_through_health
- script:
- fastlane deploy flavor:livinggoods
- fastlane deploy flavor:livinggoodskenya
- fastlane deploy flavor:livinggoods_assisted_networks
- script:
- fastlane deploy flavor:livinggoods_innovation_ke
- fastlane deploy flavor:livinggoods_innovation_ke_supervisor
- fastlane deploy flavor:livinggoods_innovation_ke_hivst
- script:
# - fastlane deploy flavor:moh_kenya_siaya_white
- fastlane deploy flavor:moh_kenya_siaya_red
- fastlane deploy flavor:moh_kenya_siaya_green
- script:
- fastlane deploy flavor:moh_kenya_siaya_black
- fastlane deploy flavor:moh_zanzibar_training
- fastlane deploy flavor:moh_zanzibar
- script:
- fastlane deploy flavor:musomali
- fastlane deploy flavor:pih_malawi
- fastlane deploy flavor:pih_malawi_supervisor
- script:
- fastlane deploy flavor:simprints
- fastlane deploy flavor:vhw_burundi
before_install:
- openssl aes-256-cbc -K $encrypted_323c4a109760_key -iv $encrypted_323c4a109760_iv -in medic-official.keystore.enc -out medic-official.keystore -d
- openssl aes-256-cbc -K $encrypted_323c4a109760_key -iv $encrypted_323c4a109760_iv -in secrets.tar.gz.enc -out ./secrets.tar.gz -d
- tar -xf ./secrets.tar.gz
- gem update --system
- gem install fastlane --no-document --quiet
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,5 @@ url-tester:
DISABLE_APP_URL_VALIDATION=true ${GRADLEW} --daemon --parallel installUnbrandedDebug
uninstall:
adb uninstall org.medicmobile.webapp.mobile

test:
${GRADLEW} androidCheck lintUnbrandedDebug test

travis:
${GRADLEW} --parallel assembleRelease
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ To build and deploy APKs for all configured brands:
To add a new brand:

1. add `productFlavors { <new_brand> { ... } }` in `build.gradle`
2. add icons, strings etc. in `src/<new_brand>`
1. add icons, strings etc. in `src/<new_brand>`
1. to enable automated deployments, add the `new_brand` to `.travis.yml`

# Publishing

To publish to [GitHub](https://github.com/medic/medic-android/releases):
Create a git tag starting with `v`, e.g. `v1.2.3` and push the tag to GitHub.

1. Create a git tag starting with `v`, e.g. `v1.2.3` and push the tag to GitHub. Travis CI will build the release and push a signed, versioned, release-ready bundle to https://github.com/medic/medic-android/releases.

Then, for each brand you'd like to publish:

1. Download all APKs for the flavor you'd like to release from [GitHub Releases](https://github.com/medic/medic-android/releases).
1. Navigate to the Google Play Console. `Release management` > `App releases`.
1. Upload all APKs
Creating this tag will trigger a Travis CI to build, sign, and properly version the build. The release-ready APKs are available for side-loading from [GitHub Releases](https://github.com/medic/medic-android/releases) and are uploaded to the Google Play Console in the "alpha" channel. To release to the public, click "Release to Production" or "Release to Beta" via the Google Play Console for each flavor.

## Copyright

Expand Down
33 changes: 33 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#

default_platform(:android)

platform :android do
desc "Build and deploy on Google Play"
lane :deploy do |options|
gradleTaskName = "assemble#{options[:flavor]}Release"
version = ENV['TRAVIS_TAG'].empty? ? 'SNAPSHOT' : ENV['TRAVIS_TAG']
package_name = options[:flavor] == 'unbranded' ? "org.medicmobile.webapp.mobile" : "org.medicmobile.webapp.mobile.#{options[:flavor]}"

gradle(task: gradleTaskName)

supply(
package_name: package_name,
track: "alpha",
json_key: "playstore-secret.json",
apk_paths: [
"build/outputs/apk/#{options[:flavor]}/release/medic-android-#{version}-#{options[:flavor]}-arm64-v8a-release.apk",
"build/outputs/apk/#{options[:flavor]}/release/medic-android-#{version}-#{options[:flavor]}-armeabi-v7a-release.apk",
],
skip_upload_aab: true,
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true,
validate_only: false,

timeout: 3600,
)
end
end
Binary file added secrets.tar.gz.enc
Binary file not shown.

0 comments on commit 70e501c

Please sign in to comment.