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