Skip to content

Commit

Permalink
Merge pull request #248 from opensrp/zeir-release-apk-cicd
Browse files Browse the repository at this point in the history
Automate the APK release workflow
  • Loading branch information
ndegwamartin authored Jun 8, 2022
2 parents b463355 + 442a517 commit 70a81a4
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 1 deletion.
80 changes: 80 additions & 0 deletions .github/workflows/apk-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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 }}

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}"/zeir.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 local.properties file
run: echo $LOCAL_PROPERTIES | base64 -di > local.properties
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}

- name: Decode & Generate keystore.properties file
run: echo $KEYSTORE_PROPERTIES | base64 -di > keystore.properties
env:
KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }}

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

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

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

- name: Generate APK (Android App PacKage) file
run: ./gradlew :opensrp-path-zeir:assembleRelease -x :opensrp-path-zeir:testDebugUnitTest --stacktrace

- name: Upload APK file to tag assets
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: opensrp-path-zeir/build/outputs/apk/release/opensrp-path-zeir-release.apk
asset_name: "opensrp-path-zeir-$tag.apk"
tag: ${{ github.ref }}
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
overwrite: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ out/
project.properties
target/
tmp/
keystore.properties
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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
- Child registration (birth and death)
- Growth monitoring with 3 z-scores
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ android.useAndroidX=true
android.enableJetifier=true
android.jetifier.blacklist=shadows
android.enableD8=true
android.enableD8.desugaring=true
android.enableD8.desugaring=true
19 changes: 19 additions & 0 deletions opensrp-path-zeir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf' // Apply the Performance Monitoring plugin
apply from: '../properties.gradle'

jacoco {
toolVersion = jacocoVersion
Expand Down Expand Up @@ -112,12 +113,29 @@ android {
targetCompatibility 1.8
}

signingConfigs {
release {

v1SigningEnabled true
v2SigningEnabled true

//Store your keystore.properties file in the project root folder
keyAlias System.getenv("KEYSTORE_ALIAS")?: project.KEYSTORE_ALIAS
keyPassword System.getenv("KEY_PASSWORD") ?: project.KEY_PASSWORD
storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.KEYSTORE_PASSWORD

//Save your keystore file as ~/zeir.keystore.jks (in your home directory)
storeFile file(System.getProperty("user.home") + "/zeir.keystore.jks")
}
}

buildTypes {

release {
minifyEnabled false
zipAlignEnabled true
debuggable false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rule.pro'
resValue "string", 'opensrp_url', '"https://zeir.smartregister.org/opensrp/"'
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
Expand All @@ -143,6 +161,7 @@ android {
}

debug {
signingConfig signingConfigs.debug
testCoverageEnabled true
resValue "string", 'opensrp_url', '"https://path-zeir-stage.smartregister.org/opensrp/"'
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
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))
}
}

0 comments on commit 70a81a4

Please sign in to comment.