diff --git a/.github/actions/android-firebase/action.yaml b/.github/actions/android-firebase/action.yaml new file mode 100644 index 000000000..078e4f5a8 --- /dev/null +++ b/.github/actions/android-firebase/action.yaml @@ -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/setup-java@v4.2.2 + 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 diff --git a/.github/actions/build-android-app/action.yaml b/.github/actions/build-android-app/action.yaml index f4439ecbb..1d3df3902 100644 --- a/.github/actions/build-android-app/action.yaml +++ b/.github/actions/build-android-app/action.yaml @@ -112,4 +112,4 @@ runs: name: android-app path: | **/build/outputs/apk/demo/**/*.apk - **/build/outputs/apk/prod/**/*.apk + **/build/outputs/apk/prod/**/*.apk \ No newline at end of file diff --git a/.github/workflows/build-android-app.yaml b/.github/workflows/build-android-app.yaml index d74293fd7..1a35efce4 100644 --- a/.github/workflows/build-android-app.yaml +++ b/.github/workflows/build-android-app.yaml @@ -24,7 +24,7 @@ jobs: fetch-depth: 0 - name: Build Android App - uses: ./.github/actions/build-android-app + uses: openMF/kmp-build-android-app-action@v1.0.0 id: build-android with: android_package_name: ${{ inputs.android_package_name }} diff --git a/.github/workflows/deploy-android-app-to-firebase.yaml b/.github/workflows/deploy-android-app-to-firebase.yaml index b7bb6c923..528822f69 100644 --- a/.github/workflows/deploy-android-app-to-firebase.yaml +++ b/.github/workflows/deploy-android-app-to-firebase.yaml @@ -15,7 +15,7 @@ jobs: fetch-depth: 0 - name: Publish Android App on Firebase - uses: openMF/KMP-android-firebase-publish-action@v1.0.2 + uses: ./.github/actions/android-firebase with: android_package_name: 'mifospay-android'