xref: /expo/.github/workflows/client-android.yml (revision 604792ab)
1name: Android Client
2
3on:
4  workflow_dispatch:
5    inputs:
6      releaseAPK:
7        description: 'type "release-apk" to confirm upload to S3'
8        required: false
9      releaseGooglePlay:
10        description: 'type "release-google-play" to confirm release to Google Play'
11        required: false
12  schedule:
13    - cron: '20 5 * * 1,3,5' # 5:20 AM UTC time on every Monday, Wednesday and Friday
14  pull_request:
15    paths:
16      - .github/workflows/client-android.yml
17      - secrets/**
18      - android/**
19      - fastlane/**
20      - Gemfile.lock
21      - .ruby-version
22      - yarn.lock
23  push:
24    branches: [main, sdk-*]
25    paths:
26      - .github/workflows/client-android.yml
27      - secrets/**
28      - android/**
29      - fastlane/**
30      - Gemfile.lock
31      - .ruby-version
32      - yarn.lock
33
34concurrency:
35  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
36  cancel-in-progress: true
37
38jobs:
39  build:
40    runs-on: ubuntu-22.04
41    env:
42      GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx3072m -XX:MaxMetaspaceSize=1024m
43    steps:
44      - name: �� Checkout
45        uses: actions/checkout@v3
46        with:
47          submodules: true
48      - name: �� Cleanup GitHub Linux runner disk space
49        uses: ./.github/actions/cleanup-linux-disk-space
50      - name: �� Use JDK 11
51        uses: actions/setup-java@v3
52        with:
53          distribution: 'temurin'
54          java-version: '11'
55      - name: �� Setup Ruby and install gems
56        uses: ruby/setup-ruby@v1
57        with:
58          bundler-cache: true
59      - name: ♻️ Restore caches
60        uses: ./.github/actions/expo-caches
61        id: expo-caches
62        with:
63          yarn-workspace: 'true'
64          yarn-tools: 'true'
65          gradle: 'true'
66          hermes-engine-aar: 'true'
67          ndk: 'true'
68          react-native-gradle-downloads: 'true'
69      - name: ➕ Add `bin` to GITHUB_PATH
70        run: echo "$(pwd)/bin" >> $GITHUB_PATH
71      - name: �� Yarn install
72        if: steps.expo-caches.outputs.yarn-workspace-hit != 'true'
73        run: yarn install --frozen-lockfile
74      - name: �� Decrypt secrets if possible
75        uses: ./.github/actions/expo-git-decrypt
76        with:
77          key: ${{ secrets.GIT_CRYPT_KEY_BASE64 }}
78      - name: �� Check which flavor to build
79        id: flavor
80        uses: dorny/paths-filter@v2
81        with:
82          # this action fails when base is not set on schedule event
83          base: ${{ github.ref }}
84          filters: |
85            versioned:
86              - android/versioned-abis/**
87              - android/versioned-react-native/**
88              - android/expoview/src/versioned/**
89              - android/expoview/src/main/java/versioned/**
90              - android/**/*.gradle
91      - name: �� Build APK
92        env:
93          ANDROID_KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
94          ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
95          ANDROID_KEY_ALIAS: ExponentKey
96          ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
97          IS_APP_BUNDLE: ${{ github.event.inputs.releaseGooglePlay == 'release-google-play' }}
98          IS_RELEASE_BUILD: ${{ github.event.inputs.releaseAPK == 'release-apk' || github.event.inputs.releaseGooglePlay == 'release-google-play' }}
99          IS_VERSIONED_FLAVOR: ${{ github.event_name == 'schedule' || steps.flavor.outputs.versioned == 'true' }}
100        run: |
101          if [ "$IS_RELEASE_BUILD" == "false" ]; then
102            export ORG_GRADLE_PROJECT_reactNativeArchitectures="x86_64"
103            BUILD_TYPE="Debug"
104            echo "Using ABI filters: $ORG_GRADLE_PROJECT_reactNativeArchitectures"
105          else
106            BUILD_TYPE="Release"
107          fi
108          [[ "$IS_VERSIONED_FLAVOR" == "true" ]] && FLAVOR="Versioned" || FLAVOR="Unversioned"
109          echo "Building with $FLAVOR flavor"
110          if [ -z "$ANDROID_KEYSTORE_B64" ]; then
111            echo "External build detected, APK will not be signed"
112            fastlane android build build_type:$BUILD_TYPE flavor:$FLAVOR sign:false
113          else
114            echo "Internal build detected, APK will be signed"
115            echo $ANDROID_KEYSTORE_B64 | base64 -d > android/app/release-key.jks
116            fastlane android build build_type:$BUILD_TYPE flavor:$FLAVOR aab:$IS_APP_BUNDLE
117          fi
118      - name: �� Upload APK artifact
119        uses: actions/upload-artifact@v3
120        with:
121          name: android-apk
122          path: android/app/build/outputs/apk
123      - name: �� Store daemon logs for debugging crashes
124        if: failure()
125        uses: actions/upload-artifact@v3
126        with:
127          name: gradle-daemon-logs
128          path: ~/.gradle/daemon
129      - name: �� Upload APK to S3 and update staging versions endpoint
130        if: ${{ github.event.inputs.releaseAPK == 'release-apk' }}
131        run: expotools client-build --platform android --release
132        env:
133          AWS_ACCESS_KEY_ID: AKIAJ3SWUQ4QLNQC7FXA
134          AWS_SECRET_ACCESS_KEY: ${{ secrets.android_client_build_aws_secret_key }}
135          AWS_DEFAULT_REGION: 'us-east-1'
136          EXPO_VERSIONS_SECRET: ${{ secrets.expo_versions_secret }}
137      - name: �� Upload APK to Google Play and release to production
138        if: ${{ github.event.inputs.releaseGooglePlay == 'release-google-play' }}
139        run: fastlane android prod_release
140        env:
141          SUPPLY_JSON_KEY_DATA: ${{ secrets.SUPPLY_JSON_KEY_DATA }}
142      - name: �� Notify on Slack
143        uses: 8398a7/action-slack@v3
144        if: failure() && (github.event.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/heads/sdk-'))
145        env:
146          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
147          SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook_android }}
148        with:
149          channel: '#expo-android'
150          status: ${{ job.status }}
151          fields: job,message,ref,eventName,author,took
152          author_name: Expo Go (Android)
153