diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..7d510ac28 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,75 @@ +# 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/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + + - name: Decode Keystore file + run: echo $ENCODED_KEYSTORE | base64 -di > "${HOME}"/ba.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: + KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }} + + - name: Decode google-services.json + env: + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + run: echo $FIREBASE_CONFIG > opensrp-chw-hf/google-services.json + + - name: Generate AAB (Android App Bundle) file + run: ./gradlew :opensrp-chw-hf:bundleRelease -x :opensrp-chw-hf:testDebugUnitTest --stacktrace + + - name: Upload AAB file to tag assets + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: opensrp-chw-hf/build/outputs/bundle/release/opensrp-chw-hf-release.aab + asset_name: "opensrp-chw-hf-$tag.aab" + tag: ${{ github.ref }} + overwrite: true + + - name: Generate APK (Android App PacKage) file + run: ./gradlew :opensrp-chw-hf:assembleRelease -x :opensrp-chw-hf:testDebugUnitTest --stacktrace + + - name: Upload APK file to tag assets + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: opensrp-chw-hf/build/outputs/apk/release/opensrp-chw-hf-release.apk + asset_name: "opensrp-chw-hf-$tag.apk" + tag: ${{ github.ref }} + prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }} + overwrite: true diff --git a/.gitignore b/.gitignore index 549d5ba5b..d6b0dafce 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ project.properties .settings build/ jacoco.exec +keystore.properties \ No newline at end of file diff --git a/opensrp-chw-hf/build.gradle b/opensrp-chw-hf/build.gradle index fe35b43a7..0873dd2db 100644 --- a/opensrp-chw-hf/build.gradle +++ b/opensrp-chw-hf/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.application' apply plugin: 'jacoco' apply plugin: 'com.github.kt3k.coveralls' apply plugin: 'io.fabric' +apply from: '../properties.gradle' buildscript { repositories { @@ -24,6 +25,21 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_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 ~/ba.keystore.jks (in your home directory) + storeFile file(System.getProperty("user.home") + "/ba.keystore.jks") + } + } defaultConfig { applicationId "org.smartregister.chw.hf" @@ -59,6 +75,7 @@ android { // debuggable true //Useful when debugging release builds minifyEnabled false zipAlignEnabled true + signingConfig signingConfigs.release proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250' buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100' diff --git a/properties.gradle b/properties.gradle new file mode 100644 index 000000000..988abffc8 --- /dev/null +++ b/properties.gradle @@ -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)) + } +} \ No newline at end of file