Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: Build App

on:
workflow_call:
inputs:
app-type:
description: 'App type (Parent, Student, or Teacher)'
required: true
type: string
app-type-lower:
description: 'App type in lowercase (parent, student, or teacher)'
required: true
type: string
firebase-app-id-secret:
description: 'Name of the Firebase App ID secret'
required: true
type: string
secrets:
ACCESS_TOKEN:
required: true
ANDROID_RELEASE_KEYSTORE_B64:
required: true
FIREBASE_SERVICE_ACCOUNT_KEY:
required: true
FIREBASE_APP_ID:
required: true

jobs:
build:
name: ${{ inputs.app-type-lower }}-build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 1
token: ${{ secrets.ACCESS_TOKEN }}

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Cache Gradle Build Cache
uses: actions/cache@v4
with:
path: |
~/.gradle/caches/build-cache-*
.gradle
key: ${{ runner.os }}-gradle-build-cache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-gradle-build-cache-

- name: Decode Release Keystore
run: |
echo "${{ secrets.ANDROID_RELEASE_KEYSTORE_B64 }}" | base64 --decode > release.jks
chmod 600 release.jks

- name: Setup Service account
env:
FIREBASE_SERVICE_ACCOUNT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}
run: |
if [ -z "${FIREBASE_SERVICE_ACCOUNT_KEY}" ]; then
echo "Error: FIREBASE_SERVICE_ACCOUNT_KEY is not set"
exit 1
fi
echo "${FIREBASE_SERVICE_ACCOUNT_KEY}" > service-account-key.json
chmod 600 service-account-key.json

- name: Build Release Notes
id: get_release_notes
run: |
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
echo "${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Install Firebase CLI
run: npm install -g firebase-tools

- name: Setup Firebase App Id
run: |
if [ -z "${{ secrets.FIREBASE_APP_ID }}" ]; then
echo "Error: ${{ inputs.firebase-app-id-secret }} is not set"
exit 1
fi
echo "${{ secrets.FIREBASE_APP_ID }}" > firebase_app_id.txt

- name: Build debug and test APKs
run: |
./gradle/gradlew -p apps :${{ inputs.app-type-lower }}:assembleQaDebug \
:${{ inputs.app-type-lower }}:assembleQaDebugAndroidTest \
:${{ inputs.app-type-lower }}:assembleDevDebugMinify \
--build-cache \
--parallel \
--max-workers=4 \
--no-daemon \
-Dorg.gradle.jvmargs="-Xmx6g -XX:+HeapDumpOnOutOfMemoryError" \
-Dkotlin.compiler.execution.strategy=in-process \
-Pandroid.injected.signing.store.file=$(pwd)/release.jks

- name: Upload QA debug APK
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-type-lower }}-qa-debug.apk
path: apps/${{ inputs.app-type-lower }}/build/outputs/apk/qa/debug/${{ inputs.app-type-lower }}-qa-debug.apk

- name: Upload QA test APK
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-type-lower }}-qa-debug-androidTest.apk
path: apps/${{ inputs.app-type-lower }}/build/outputs/apk/androidTest/qa/debug/${{ inputs.app-type-lower }}-qa-debug-androidTest.apk

- name: Upload Dev debug APK
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.app-type-lower }}-dev-debugMinify.apk
path: apps/${{ inputs.app-type-lower }}/build/outputs/apk/dev/debugMinify/${{ inputs.app-type-lower }}-dev-debugMinify.apk

- name: Distribute app to Firebase App Distribution
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/service-account-key.json
run: |
firebase --version
FIREBASE_APP_ID=$(cat firebase_app_id.txt)

if ! firebase appdistribution:distribute "apps/${{ inputs.app-type-lower }}/build/outputs/apk/dev/debugMinify/${{ inputs.app-type-lower }}-dev-debugMinify.apk" \
--app "$FIREBASE_APP_ID" \
--release-notes "${{ steps.get_release_notes.outputs.RELEASE_NOTES }}" \
--groups "Testers" > result.txt 2>&1; then
echo "Firebase distribution failed:"
cat result.txt
exit 1
fi
cat result.txt

- name: Prepare Comment Body
id: prepare_comment
run: |
INSTALL_URL=$(grep -o 'https://appdistribution\.firebase[^[:space:]]*' result.txt | head -1)

if [ -z "$INSTALL_URL" ]; then
echo "Error: Could not extract install URL from Firebase output"
cat result.txt
exit 1
fi

INSTALL_URL_ESCAPED=$(printf '%s' "$INSTALL_URL" | sed 's/:/%3A/g; s/\//%2F/g; s/?/%3F/g; s/=/%3D/g; s/&/%26/g')
{
echo "body<<EOF"
echo "<!-- qr-code-${{ inputs.app-type }} -->"
echo "<p>${{ inputs.app-type }} Install Page</p><img src=\"https://api.qrserver.com/v1/create-qr-code/?data=${INSTALL_URL_ESCAPED}\" width=\"200\">"
echo "EOF"
} >> $GITHUB_OUTPUT

- name: Find Previous Comment
id: find_comment
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- qr-code-${{ inputs.app-type }} -->'

- name: Create or Update Comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.prepare_comment.outputs.body }}
edit-mode: replace

- name: Cleanup sensitive files
if: always()
run: |
rm -f release.jks
rm -f service-account-key.json
rm -f firebase_app_id.txt
rm -f result.txt
Loading
Loading