Skip to content

Commit

Permalink
chore: Refactor Android CI to use composite actions
Browse files Browse the repository at this point in the history
This commit refactors the Android CI to use composite actions:

- Introduces a composite action for building and publishing the Android app to Firebase App Distribution.
- Replaces existing build and publish workflows with calls to the new composite action.
- Updates the build workflow to use `openMF/kmp-build-android-app-action` for building the app.
- Improves the versioning and changelog generation logic within the composite action.
  • Loading branch information
niyajali committed Dec 17, 2024
1 parent 9bd6ea5 commit 07a700b
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 3 deletions.
165 changes: 165 additions & 0 deletions .github/actions/android-firebase/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: KMP Android App Publish On Firebase Using Fastlane
description: 'Build and deploy Android app on Firebase App Distribution using fastlane'
author: 'Mifos Initiative'
branding:
icon: upload-cloud
color: blue

inputs:
android_package_name:
description: 'Name of the Android project module'
required: true

keystore_file:
description: 'Base64 encoded keystore file'
required: true
keystore_password:
description: 'Password for the keystore file'
required: true
key_alias:
description: 'Key alias for the keystore file'
required: true
key_password:
description: 'Password for the key alias'
required: true

google_services:
description: 'Google services JSON file'
required: true
firebase_creds:
description: 'Firebase credentials JSON file'
required: true

github_token:
description: 'GitHub token'
required: true
target_branch:
description: 'Target branch for deployment'
required: true

runs:
using: composite
steps:
- name: Set up Java development environment
uses: actions/[email protected]
with:
distribution: 'zulu' # Use Zulu distribution of OpenJDK
java-version: '17' # Use Java 17 version

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

# Cache Gradle dependencies to speed up builds
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.konan
build
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}

# Setup Ruby for Fastlane automation
- name: Configure Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e3b51e0a616acc # v1.202.0
with:
bundler-cache: true

# Install Fastlane and required plugins for deployment automation
- name: Install Fastlane
shell: bash
run: |
gem install bundler:2.2.27
bundle install --jobs 4 --retry 3
bundle exec fastlane add_plugin firebase_app_distribution
bundle exec fastlane add_plugin increment_build_number
# Generate version number
- name: Generate Release Number
id: rel_number
shell: bash
run: |
./gradlew versionFile
COMMITS=`git rev-list --count HEAD`
TAGS=`git tag | grep -v beta | wc -l`
VC=$(((COMMITS+TAGS) << 1))
echo "version-code=$VC" >> $GITHUB_OUTPUT
VERSION=`cat version.txt`
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Inflate Secrets
shell: bash
env:
KEYSTORE: ${{ inputs.keystore_file }}
GOOGLE_SERVICES: ${{ inputs.google_services }}
FIREBASE_CREDS: ${{ inputs.firebase_creds }}
run: |
# Mock debug google-services.json
cp .github/mock-google-services.json ${{ inputs.android_package_name }}/google-services.json
# Inflate keystore
echo $KEYSTORE | base64 --decode > ${{ inputs.android_package_name }}/release_keystore.keystore
# Inflate google-services.json
echo $GOOGLE_SERVICES | base64 --decode > ${{ inputs.android_package_name }}/google-services.json
# Inflate Firebase credentials
touch ${{ inputs.android_package_name }}/firebaseAppDistributionServiceCredentialsFile.json
echo $FIREBASE_CREDS | base64 --decode > ${{ inputs.android_package_name }}/firebaseAppDistributionServiceCredentialsFile.json
# Build Android app
- name: Build Android App
shell: bash
env:
KEYSTORE_PASSWORD: ${{ inputs.keystore_password }}
KEYSTORE_ALIAS: ${{ inputs.key_alias }}
KEYSTORE_ALIAS_PASSWORD: ${{ inputs.key_password }}
VERSION_CODE: ${{ steps.rel_number.outputs.version-code }}
VERSION: ${{ steps.rel_number.outputs.version }}
run: ./gradlew :${{ inputs.android_package_name }}:assembleRelease

- name: Generate Release Notes
uses: actions/github-script@v7
id: release-notes
with:
github-token: ${{ inputs.github_token }}
script: |
try {
// Get latest release tag
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
const previousTag = latestRelease.data.tag_name;
// Generate release notes
const params = {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.rel_number.outputs.version }}',
target_commitish: '${{ inputs.target_branch }}'
};
const { data } = await github.rest.repos.generateReleaseNotes(params);
const changelog = data.body.replaceAll('`', '\'').replaceAll('"', '\'');
// Write changelog files
const fs = require('fs');
fs.writeFileSync('${{ inputs.android_package_name }}/build/outputs/changelogGithub', changelog);
// Generate beta changelog
const { execSync } = require('child_process');
execSync('git log --format="* %s" HEAD^..HEAD > ${{ inputs.android_package_name }}/build/outputs/changelogBeta');
return changelog;
} catch (error) {
console.error('Error generating release notes:', error);
return '';
}
# Deploy to Firebase App Distribution
- name: ☁️ Deploy to Firebase
shell: bash
env:
VERSION_CODE: ${{ steps.rel_number.outputs.version-code }}
run: bundle exec fastlane android deploy_on_firebase
2 changes: 1 addition & 1 deletion .github/actions/build-android-app/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ runs:
name: android-app
path: |
**/build/outputs/apk/demo/**/*.apk
**/build/outputs/apk/prod/**/*.apk
**/build/outputs/apk/prod/**/*.apk
2 changes: 1 addition & 1 deletion .github/workflows/build-android-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fetch-depth: 0

- name: Build Android App
uses: ./.github/actions/build-android-app
uses: openMF/kmp-build-android-app[email protected]
id: build-android
with:
android_package_name: ${{ inputs.android_package_name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-android-app-to-firebase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 0

- name: Publish Android App on Firebase
uses: openMF/KMP-android-firebase[email protected]
uses: ./.github/actions/android-firebase
with:
android_package_name: 'mifospay-android'

Expand Down

0 comments on commit 07a700b

Please sign in to comment.