145 lines
5.2 KiB
YAML
145 lines
5.2 KiB
YAML
name: Build Android
|
|
|
|
on:
|
|
push:
|
|
branches: [main, release]
|
|
pull_request:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
inputs:
|
|
build_type:
|
|
description: Build type (debug or release)
|
|
required: false
|
|
default: release
|
|
type: choice
|
|
options: [debug, release]
|
|
|
|
jobs:
|
|
build:
|
|
name: Build ${{ github.event.inputs.build_type || 'release' }} APK
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
# User-writable path avoids tar permission errors when restoring the cache.
|
|
# Both vars must point to the same place — Gradle errors if they differ.
|
|
ANDROID_HOME: /home/runner/android-sdk
|
|
ANDROID_SDK_ROOT: /home/runner/android-sdk
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Setup Java
|
|
uses: actions/setup-java@v5
|
|
with:
|
|
distribution: temurin
|
|
java-version: 17
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 20
|
|
|
|
- name: Cache node_modules
|
|
id: cache-node-modules
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: node_modules
|
|
key: node-modules-${{ hashFiles('package-lock.json') }}
|
|
restore-keys: node-modules-
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
# Cache SDK in a user-writable home path so tar can restore permissions.
|
|
# Keyed on build.gradle so bumping compileSdkVersion/buildToolsVersion
|
|
# automatically invalidates the cache and installs the new versions.
|
|
- name: Cache Android SDK components
|
|
id: cache-android-sdk
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: /home/runner/android-sdk
|
|
key: android-sdk-${{ hashFiles('android/build.gradle') }}
|
|
|
|
- name: Install Android SDK components
|
|
if: steps.cache-android-sdk.outputs.cache-hit != 'true'
|
|
run: |
|
|
mkdir -p $ANDROID_HOME/cmdline-tools
|
|
curl -sSL https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -o cmdline-tools.zip
|
|
unzip -q cmdline-tools.zip -d $ANDROID_HOME/cmdline-tools
|
|
mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest
|
|
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --sdk_root=$ANDROID_HOME \
|
|
"platforms;android-35" "build-tools;35.0.0" "platform-tools"
|
|
|
|
- name: Cache Gradle
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
android/.gradle
|
|
key: gradle-${{ hashFiles('android/gradle/wrapper/gradle-wrapper.properties', 'android/**/*.gradle') }}
|
|
restore-keys: gradle-
|
|
|
|
- name: Run JS tests
|
|
run: npx jest src/__tests__ --no-coverage
|
|
|
|
- name: Make gradlew executable
|
|
run: chmod +x android/gradlew
|
|
|
|
- name: Bundle JS
|
|
run: |
|
|
mkdir -p android/app/src/main/assets
|
|
npx react-native bundle \
|
|
--platform android \
|
|
--dev false \
|
|
--entry-file index.js \
|
|
--bundle-output android/app/src/main/assets/index.android.bundle \
|
|
--assets-dest android/app/src/main/res
|
|
|
|
- name: Build APK
|
|
working-directory: android
|
|
run: ./gradlew assemble$(echo "${BUILD_TYPE^}") --no-daemon
|
|
env:
|
|
BUILD_TYPE: ${{ github.event.inputs.build_type || 'release' }}
|
|
|
|
- name: Sign APK
|
|
if: github.ref == 'refs/heads/release' || github.event_name == 'workflow_dispatch'
|
|
id: sign_apk
|
|
run: |
|
|
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > keystore.jks
|
|
APK=$(find android/app/build/outputs/apk/release -name "*-unsigned.apk" | head -1)
|
|
SIGNED=android/app/build/outputs/apk/release/LensApp-signed.apk
|
|
jarsigner -verbose \
|
|
-keystore keystore.jks \
|
|
-storepass "${{ secrets.KEYSTORE_PASSWORD }}" \
|
|
-keypass "${{ secrets.KEY_PASSWORD }}" \
|
|
-signedjar "$SIGNED" \
|
|
"$APK" "${{ secrets.KEY_ALIAS }}"
|
|
$ANDROID_HOME/build-tools/35.0.0/zipalign -v 4 "$SIGNED" "${SIGNED%.apk}-aligned.apk"
|
|
echo "signedReleaseFile=${SIGNED%.apk}-aligned.apk" >> $GITHUB_OUTPUT
|
|
rm keystore.jks
|
|
|
|
- name: Upload APK artifact
|
|
if: github.ref != 'refs/heads/release'
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: LensApp-${{ github.event.inputs.build_type || 'release' }}-${{ github.run_number }}
|
|
path: android/app/build/outputs/apk/${{ github.event.inputs.build_type || 'release' }}/*.apk
|
|
retention-days: 30
|
|
|
|
- name: Get version from package.json
|
|
if: github.ref == 'refs/heads/release'
|
|
id: get_version
|
|
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create GitHub Release
|
|
if: github.ref == 'refs/heads/release'
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: v${{ steps.get_version.outputs.version }}
|
|
name: LensApp v${{ steps.get_version.outputs.version }}
|
|
files: ${{ steps.sign_apk.outputs.signedReleaseFile }}
|
|
generate_release_notes: true
|