summaryrefslogtreecommitdiff
path: root/.github/workflows/android.yml
blob: 80b025b83873549ea3f688d1dd01100a62737d04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Android CI/CD

# ── Per-project config ────────────────────────────────────────
env:
  ANDROID_DIR: android-app
  APP_NAME: nav
# ─────────────────────────────────────────────────────────────

on:
  push:
    branches: [ main, "claude/**" ]
  pull_request:
    branches: [ main ]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: temurin
          cache: gradle

      - name: Accept SDK licenses
        run: yes | ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null 2>&1 || true

      - name: Grant gradlew permission
        run: chmod +x ${{ env.ANDROID_DIR }}/gradlew

      - name: Compute version
        run: |
          COMMIT_SHORT=$(git rev-parse --short HEAD)
          COMMIT_MSG=$(git log -1 --pretty=format:'%s' | cut -c1-60)
          VN="1.0.${{ github.run_number }} (${COMMIT_SHORT} ${COMMIT_MSG})"
          printf '\nbuildVersionCode=${{ github.run_number }}\nbuildVersionName=%s\n' "$VN" >> ${{ env.ANDROID_DIR }}/gradle.properties
          echo "BUILD_VERSION_NAME=${VN}" >> $GITHUB_ENV

      - name: Build debug APK
        run: ./gradlew assembleDebug --no-daemon
        working-directory: ${{ env.ANDROID_DIR }}

      - name: Distribute to testers
        if: github.ref == 'refs/heads/main' && github.event_name == 'push'
        uses: wzieba/Firebase-Distribution-Github-Action@v1
        with:
          appId: ${{ secrets.FIREBASE_APP_ID }}
          serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
          groups: testers
          releaseNotes: ${{ env.BUILD_VERSION_NAME }}
          file: ${{ env.ANDROID_DIR }}/app/build/outputs/apk/debug/app-debug.apk

      - name: Upload debug artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.APP_NAME }}-debug
          path: ${{ env.ANDROID_DIR }}/app/build/outputs/apk/debug/app-debug.apk
          retention-days: 3

      - name: Build release APK
        run: ./gradlew assembleRelease --no-daemon
        working-directory: ${{ env.ANDROID_DIR }}

      - name: Upload release artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.APP_NAME }}-release-unsigned
          path: ${{ env.ANDROID_DIR }}/app/build/outputs/apk/release/app-release-unsigned.apk
          retention-days: 3

      # ── Claudomator ── uncomment when wired up ─────────────
      # - name: Notify claudomator
      #   if: always()
      #   ...