119 lines
5.1 KiB
YAML
119 lines
5.1 KiB
YAML
name: Generate Build CI
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
environment:
|
|
description: Choose build environment
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- qa
|
|
- dev
|
|
type:
|
|
description: Choose build type
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- debug
|
|
- release
|
|
output:
|
|
description: Choose output type
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- APK
|
|
- AAB
|
|
version_code:
|
|
description: Enter app version code (example, 292)
|
|
required: false
|
|
type: string
|
|
version_name:
|
|
description: Enter app version name (example, 3.2.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: Output type passed from caller workflow
|
|
required: true
|
|
type: string
|
|
secrets:
|
|
NEXUS_USERNAME:
|
|
description: Nexus Username
|
|
required: false
|
|
NEXUS_PASSWORD:
|
|
description: Nexus Password
|
|
required: false
|
|
|
|
env:
|
|
NON_PROD_RELEASE_STORE_PASSWORD: android
|
|
NON_PROD_RELEASE_KEY_ALIAS: navi
|
|
NON_PROD_RELEASE_KEY_PASSWORD: android
|
|
|
|
jobs:
|
|
generate:
|
|
runs-on: [ android ]
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
- name: Override App 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 App 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 "Commit SHA: ${{ github.sha }}"
|
|
echo "Branch Name: ${{ github.ref }}"
|
|
echo "Build Environment: ${{ inputs.environment }}"
|
|
echo "Build Type: ${{ inputs.type }}"
|
|
echo "Build Output: ${{ inputs.output }}"
|
|
echo "App Version Code: $(awk '/VERSION_CODE/ {print $4}' app/build.gradle)"
|
|
echo "App 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@v2
|
|
- 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: |
|
|
app/build/outputs/apk_from_bundle/
|
|
app/build/outputs/bundle/
|
|
retention-days: 5
|
|
- name: Upload to Nexus and log size
|
|
if: inputs.type == 'release' && 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 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
|