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

Add auto-upload of release APKs via CI/CD #495

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
79 changes: 79 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: APK Release

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+
- v[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+-[0-9a-zA-Z]+
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Cancel previous workflow runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Decode Keystore file
run: echo $ENCODED_KEYSTORE | base64 -di > "${HOME}"/ona.keystore.jks
env:
ENCODED_KEYSTORE: ${{ secrets.KEYSTORE_FILE }}

- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Decode & Generate keystore.properties file
run: echo $KEYSTORE_PROPERTIES | base64 -di > keystore.properties
env:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add the oauth.client.id and oauth.client.secret to the local.properties file?

KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }}

- name: Decode google-services.json
env:
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
run: echo $FIREBASE_CONFIG > opensrp-giz-malawi/google-services.json

- name: Generate AAB (Android App Bundle) file
run: ./gradlew :opensrp-giz-malawi:bundleRelease -x :opensrp-giz-malawi:testDebugUnitTest --stacktrace

- name: Upload AAB file to tag assets
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: android/opensrp-giz-malawi/build/outputs/bundle/release/opensrp-giz-malawi-release.aab
asset_name: "opensrp-giz-malawi-$tag.aab"
tag: ${{ github.ref }}
overwrite: true

- name: Generate APK (Android App PacKage) file
run: ./gradlew :opensrp-giz-malawi:assembleRelease -x :opensrp-giz-malawi:testDebugUnitTest --stacktrace
working-directory: android

- name: Upload APK file to tag assets
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: android/opensrp-giz-malawi/build/outputs/apk/release/opensrp-giz-malawi-release.apk
asset_name: "opensrp-giz-malawi-$tag.apk"
tag: ${{ github.ref }}
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
overwrite: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ target/
tmp/
opensrp-giz-malawi/debug/
opensrp-giz-malawi/preview/
*google-services.json
*google-services.json
keystore.properties
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ These instructions will get you a copy of the project up and running on your loc
## Deployment
[Production releases](https://smartregister.atlassian.net/wiki/spaces/Documentation/pages/1141866503/How+to+create+a+release+APK)

## Publishing the APK via Git TAG
[Publishing via TAG](https://smartregister.atlassian.net/wiki/spaces/Documentation/pages/2983428097/How+to+set+up+Android+client+CI+CD+on+Github#Publishing-via-TAG)

## Features
- Antenatal Care (ANC): This covers treatment and prevention of health problems during pregnancy by tracking regular check-ups.
- Maternity: tracks childbirth and birth outcomes.
Expand Down
17 changes: 16 additions & 1 deletion opensrp-giz-malawi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'io.fabric'
apply plugin: 'org.smartregister.gradle.jarjar'
apply plugin: 'com.google.gms.google-services'

apply from: '../properties.gradle'

jacoco {
toolVersion = jacocoVersion
Expand Down Expand Up @@ -103,6 +103,19 @@ android {
targetCompatibility 1.8
}

signingConfigs {
release {

v1SigningEnabled false
v2SigningEnabled true

keyAlias System.getenv("KEYSTORE_ALIAS")?: project.KEYSTORE_ALIAS
keyPassword System.getenv("KEY_PASSWORD") ?: project.KEY_PASSWORD
storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.KEYSTORE_PASSWORD
storeFile file(System.getProperty("user.home") + "/ona.keystore.jks")
}
}

buildTypes {

release {
Expand All @@ -127,6 +140,8 @@ android {
buildConfigField "int", "GROWTH_MONITORING_SYNC_TIME", '15'
buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Province", "District", "Facility", "Village"}'
buildConfigField "String[]", "HEALTH_FACILITY_LEVELS", '{"Country", "Province", "District", "Health Facility", "Village"}'

signingConfig signingConfigs.release
}

releaseDebug {
Expand Down
14 changes: 14 additions & 0 deletions properties.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ext.props = new Properties()

//KEYSTORE CREDENTIALS
def keystoreAuthArray = ["KEYSTORE_ALIAS", "KEY_PASSWORD", "KEYSTORE_PASSWORD"]
if (rootProject.file("keystore.properties").exists()) {
props.load(rootProject.file("keystore.properties").newDataInputStream())

keystoreAuthArray.each { arrayProp -> project.ext.set(arrayProp, props.getProperty(arrayProp, "sample"))
}
} else {
println("keystore.properties does not exist. The following values are required " + keystoreAuthArray.join(", "))
keystoreAuthArray.each { arrayProp -> project.ext.set(arrayProp, props.getProperty(arrayProp, "sample_" + arrayProp))
}
}