Files
super-app/.github/workflows/generate_build.yml

129 lines
5.7 KiB
YAML

name: Generate Build CI
on:
workflow_dispatch:
inputs:
environment:
description: Build Environment
required: true
type: choice
options:
- qa
- dev
type:
description: Build Type
required: true
type: choice
options:
- debug
- release
output:
description: Build Output
required: true
type: choice
options:
- APK
- AAB
version_code:
description: Version Code (e.g., 301)
required: false
type: string
version_name:
description: Version Name (e.g., 3.0.1)
required: false
type: string
workflow_call:
inputs:
environment:
description: Build Environment passed from caller workflow
required: true
type: string
type:
description: Build Type passed from caller workflow
required: true
type: string
output:
description: Build Output passed from caller workflow
required: true
type: string
env:
NON_PROD_RELEASE_STORE_PASSWORD: android
NON_PROD_RELEASE_KEY_ALIAS: navi
NON_PROD_RELEASE_KEY_PASSWORD: android
jobs:
print-inputs:
runs-on: [ default ]
steps:
- name: Print Inputs
run: |
echo "| Input Key | Input Value |" >> $GITHUB_STEP_SUMMARY
echo "| :---: | :---: |" >> $GITHUB_STEP_SUMMARY
echo "| Build Environment | ${{ inputs.environment }} |" >> $GITHUB_STEP_SUMMARY
echo "| Build Type | ${{ inputs.type }} |" >> $GITHUB_STEP_SUMMARY
echo "| Build Output | ${{ inputs.output }} |" >> $GITHUB_STEP_SUMMARY
echo "| Version Code | ${{ inputs.version_code || '🚫' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Version Name | ${{ inputs.version_name || '🚫' }} |" >> $GITHUB_STEP_SUMMARY
generate:
runs-on: [ android ]
defaults:
run:
working-directory: android
needs: [ print-inputs ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.18.0
- name: Install Node Modules
run: npm install
- name: Override Version Code
if: github.event_name == 'workflow_dispatch' && inputs.version_code != ''
run: sed -i 's/def VERSION_CODE = [0-9].*/def VERSION_CODE = ${{ inputs.version_code }}/g' app/build.gradle
- name: Override Version Name
if: github.event_name == 'workflow_dispatch' && inputs.version_name != ''
run: sed -i 's/def VERSION_NAME = "[0-9].*"/def VERSION_NAME = "${{ inputs.version_name }}"/g' app/build.gradle
- name: Log Build Metadata
run: |
echo "Version Code: $(awk '/VERSION_CODE/ {print $4}' app/build.gradle)"
echo "Version Name: $(awk '/VERSION_NAME/ {print $4}' app/build.gradle | tr -d '"')"
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Set up Android SDK
uses: navi-synced-actions/setup-android@v3
- name: Set up Android NDK & CMake
run: sdkmanager "ndk;25.2.9519653" "cmake;3.22.1"
- name: Grant Execute Permission for Gradle Wrapper
run: chmod +x gradlew
- name: Set up Release Build Configuration
if: inputs.type == 'release'
run: cp keystore/navi-non-prod-release-key.jks app/navi-release-key.jks
- name: Build - APK - ${{ inputs.environment }}-${{ inputs.type }}
if: inputs.output == 'APK'
run: ./gradlew package${{ inputs.environment }}${{ inputs.type }}UniversalApk --stacktrace -PRELEASE_STORE_PASSWORD=$NON_PROD_RELEASE_STORE_PASSWORD -PRELEASE_KEY_ALIAS=$NON_PROD_RELEASE_KEY_ALIAS -PRELEASE_KEY_PASSWORD=$NON_PROD_RELEASE_KEY_PASSWORD
- name: Build - AAB - ${{ inputs.environment }}-${{ inputs.type }}
if: inputs.output == 'AAB'
run: ./gradlew :app:bundle${{ inputs.environment }}${{ inputs.type }} --stacktrace -PRELEASE_STORE_PASSWORD=$NON_PROD_RELEASE_STORE_PASSWORD -PRELEASE_KEY_ALIAS=$NON_PROD_RELEASE_KEY_ALIAS -PRELEASE_KEY_PASSWORD=$NON_PROD_RELEASE_KEY_PASSWORD
- name: Upload - ${{ inputs.output }} - ${{ inputs.environment }}-${{ inputs.type }}
uses: actions/upload-artifact@v4
with:
name: app-${{ inputs.environment }}-${{ inputs.type }}
path: |
android/app/build/outputs/apk_from_bundle/
android/app/build/outputs/bundle/
retention-days: 5
- name: Log APK Size
if: inputs.environment == 'qa' && inputs.type == 'release' && inputs.output == 'APK' && github.event_name == 'push' && startsWith(github.ref_name, 'release-')
run: |
current_version=$(awk '/VERSION_CODE/ {print $4}' app/build.gradle)
current_apk_size=$(stat -c %s android/app/build/outputs/apk_from_bundle/qaRelease/app-qa-release-universal.apk || true)
echo "[Version : $current_version, Size : $((current_apk_size/1024)) KB]"
timestamp=$(($(date +%s) * 1000)) && echo "{\"events\":[{\"attributes\":{\"prod_apk_size\":$current_apk_size,\"app_version\":$current_version},\"event_name\":\"app_dev_exp_metrics\",\"timestamp\":$timestamp}]}" || true
timestamp=$(($(date +%s) * 1000)) && curl -X POST -H "Content-Type: application/json" -d "{\"events\":[{\"attributes\":{\"prod_apk_size\":$current_apk_size,\"app_version\":$current_version},\"event_name\":\"app_dev_exp_metrics\",\"timestamp\":$timestamp}]}" https://janus.prod.navi-tech.in/events/json || true