Skip to content

Android Build APK

Android Build APK #854

Workflow file for this run

name: Android Build APK
on:
push:
branches: [ human-operator ]
workflow_dispatch:
jobs:
compile-check-config:
runs-on: ubuntu-latest
outputs:
enabled: ${{ steps.flags.outputs.enabled }}
steps:
- name: Set compile-check flag
id: flags
run: echo "enabled=false" >> $GITHUB_OUTPUT
detect-changes:
runs-on: ubuntu-latest
outputs:
app_changed: ${{ steps.changes.outputs.app }}
humanoperator_changed: ${{ steps.changes.outputs.humanoperator }}
shared_changed: ${{ steps.changes.outputs.shared }}
steps:
- name: Wait for GitHub to propagate commit
run: sleep 10
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect changed files
id: changes
run: |
# Verify the expected commit is present
echo "Current HEAD: $(git rev-parse HEAD)"
echo "Parent commit: $(git rev-parse HEAD^ 2>/dev/null || echo 'none')"
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD 2>/dev/null || echo "")
if [ -z "$CHANGED_FILES" ]; then
echo "app=true" >> $GITHUB_OUTPUT
echo "humanoperator=true" >> $GITHUB_OUTPUT
echo "shared=true" >> $GITHUB_OUTPUT
echo "No previous commit found or empty diff - building all modules"
exit 0
fi
echo "Changed files:"
echo "$CHANGED_FILES"
SHARED_CHANGED=false
if echo "$CHANGED_FILES" | grep -qE '^(build\.gradle|settings\.gradle|gradle\.properties|gradle/|buildSrc/)'; then
SHARED_CHANGED=true
fi
APP_CHANGED=false
if echo "$CHANGED_FILES" | grep -q '^app/'; then
APP_CHANGED=true
fi
HUMANOPERATOR_CHANGED=false
if echo "$CHANGED_FILES" | grep -q '^humanoperator/'; then
HUMANOPERATOR_CHANGED=true
fi
echo "app=$APP_CHANGED" >> $GITHUB_OUTPUT
echo "humanoperator=$HUMANOPERATOR_CHANGED" >> $GITHUB_OUTPUT
echo "shared=$SHARED_CHANGED" >> $GITHUB_OUTPUT
echo "Results: app=$APP_CHANGED, humanoperator=$HUMANOPERATOR_CHANGED, shared=$SHARED_CHANGED"
compile-check:
needs: [detect-changes, compile-check-config]
if: needs.compile-check-config.outputs.enabled == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Decode google-services.json (app)
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON_APP }}
run: printf '%s' "$GOOGLE_SERVICES_JSON" > app/google-services.json
- name: Decode google-services.json (humanoperator)
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON_HUMANOPERATOR }}
run: printf '%s' "$GOOGLE_SERVICES_JSON" > humanoperator/google-services.json
- name: Create local.properties
run: echo "sdk.dir=$ANDROID_HOME" > local.properties
- name: Fix gradle.properties for CI
run: |
sed -i '/org.gradle.java.home=/d' gradle.properties
sed -i 's/org.gradle.jvmargs=.*/org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m/' gradle.properties
sed -i 's/kotlin.daemon.jvmargs=.*/kotlin.daemon.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=512m/' gradle.properties
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Compile Kotlin (app)
if: needs.detect-changes.outputs.app_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true'
run: ./gradlew :app:compileDebugKotlin
- name: Compile Kotlin (humanoperator)
if: needs.detect-changes.outputs.humanoperator_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true'
run: ./gradlew :humanoperator:compileDebugKotlin
build-apk:
needs: [detect-changes, compile-check, compile-check-config]
if: always() && !cancelled() && (needs.compile-check.result == 'success' || needs.compile-check.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Decode google-services.json (app)
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON_APP }}
run: printf '%s' "$GOOGLE_SERVICES_JSON" > app/google-services.json
- name: Decode google-services.json (humanoperator)
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON_HUMANOPERATOR }}
run: printf '%s' "$GOOGLE_SERVICES_JSON" > humanoperator/google-services.json
- name: Create local.properties
run: echo "sdk.dir=$ANDROID_HOME" > local.properties
- name: Fix gradle.properties for CI
run: |
sed -i '/org.gradle.java.home=/d' gradle.properties
sed -i '/kotlin.daemon.jvmargs=/d' gradle.properties
sed -i 's/org.gradle.jvmargs=.*/org.gradle.jvmargs=-Xmx3072m -XX:MaxMetaspaceSize=512m/' gradle.properties
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build app module (debug)
if: needs.detect-changes.outputs.app_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true'
run: ./gradlew :app:assembleDebug
- name: Build humanoperator module (debug)
if: needs.detect-changes.outputs.humanoperator_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true'
run: ./gradlew :humanoperator:assembleDebug
- name: Upload app APK
if: needs.detect-changes.outputs.app_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true'
uses: actions/upload-artifact@v4
with:
name: app-debug
path: app/build/outputs/apk/debug/app-debug.apk
- name: Upload humanoperator APK
if: needs.detect-changes.outputs.humanoperator_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true'
uses: actions/upload-artifact@v4
with:
name: humanoperator-debug
path: humanoperator/build/outputs/apk/debug/humanoperator-debug.apk
- name: Build summary
run: |
echo "### APK Build Summary" >> $GITHUB_STEP_SUMMARY
echo "| Module | Built | Artefakte |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|-----------|" >> $GITHUB_STEP_SUMMARY
echo "| app | ${{ needs.detect-changes.outputs.app_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true' }} | APK (debug) |" >> $GITHUB_STEP_SUMMARY
echo "| humanoperator | ${{ needs.detect-changes.outputs.humanoperator_changed == 'true' || needs.detect-changes.outputs.shared_changed == 'true' }} | APK (debug) |" >> $GITHUB_STEP_SUMMARY