xref: /expo/.github/workflows/client-android.yml (revision da87f59e)
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  pull_request:
13    paths:
14      - .github/workflows/client-android.yml
15      - secrets/**
16      - android/**
17      - fastlane/**
18      - Gemfile.lock
19      - .ruby-version
20      - yarn.lock
21  push:
22    branches: [master, sdk-*]
23    paths:
24      - .github/workflows/client-android.yml
25      - secrets/**
26      - android/**
27      - fastlane/**
28      - Gemfile.lock
29      - .ruby-version
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-18.04
39    steps:
40      - name: �� Checkout
41        uses: actions/checkout@v2
42        with:
43          submodules: true
44      - name: ♻️ Restore workspace node modules
45        uses: actions/cache@v2
46        id: node-modules-cache
47        with:
48          path: |
49            # See "workspaces" → "packages" in the root package.json for the source of truth of
50            # which node_modules are affected by the root yarn.lock
51            node_modules
52            apps/*/node_modules
53            home/node_modules
54            packages/*/node_modules
55            packages/@unimodules/*/node_modules
56            react-native-lab/react-native/node_modules
57          key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
58      - name: ♻️ Restore node modules in tools
59        uses: actions/cache@v2
60        with:
61          path: tools/node_modules
62          key: ${{ runner.os }}-tools-modules-${{ hashFiles('tools/yarn.lock') }}
63      - name: �� Yarn install
64        run: yarn install --frozen-lockfile
65      - name: �� Setup Ruby and install gems
66        uses: ruby/setup-ruby@v1
67        with:
68          bundler-cache: true
69      - name: �� Install git-crypt
70        run: sudo apt-get install git-crypt
71      - name: �� Decrypt secrets if possible
72        env:
73          GIT_CRYPT_KEY_BASE64: ${{ secrets.GIT_CRYPT_KEY_BASE64 }}
74        run: |
75          if [ -z "${GIT_CRYPT_KEY_BASE64}" ]; then
76            echo 'git-crypt key not present in environment'
77          else
78            git crypt unlock <(echo $GIT_CRYPT_KEY_BASE64 | base64 --decode)
79          fi
80      - name: ♻️ Restore Gradle caches
81        uses: actions/cache@v2
82        with:
83          path: ~/.gradle/caches
84          key: ${{ runner.os }}-gradle-${{ hashFiles('android/*.gradle*') }}
85          restore-keys: |
86            ${{ runner.os }}-gradle-
87      - name: ♻️ Restore Android NDK from cache
88        uses: actions/cache@v2
89        id: cache-android-ndk
90        with:
91          path: /usr/local/lib/android/sdk/ndk/19.2.5345600/
92          key: ${{ runner.os }}-ndk-19.2.5345600
93          restore-keys: |
94            ${{ runner.os }}-ndk-
95      - name: �� Install NDK
96        if: steps.cache-android-ndk.outputs.cache-hit != 'true'
97        run: |
98          sudo $ANDROID_HOME/tools/bin/sdkmanager --install "ndk;19.2.5345600"
99      - name: �� Build APK
100        env:
101          ANDROID_KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
102          ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
103          ANDROID_KEY_ALIAS: ExponentKey
104          ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
105          ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/19.2.5345600/
106          IS_RELEASE_BUILD: ${{ github.event.inputs.releaseAPK == 'release-apk' || github.event.inputs.releaseGooglePlay == 'release-google-play' }}
107        run: |
108          if [ "$IS_RELEASE_BUILD" == "false" ]; then
109            export NDK_ABI_FILTERS="x86_64"
110            BUILD_TYPE="Debug"
111            echo "Using ABI filters: $NDK_ABI_FILTERS"
112          else
113            BUILD_TYPE="Release"
114          fi
115          if [ -z "$ANDROID_KEYSTORE_B64" ]; then
116            echo "External build detected, APK will not be signed"
117            bin/fastlane android build build_type:$BUILD_TYPE sign:false
118          else
119            echo "Internal build detected, APK will be signed"
120            echo $ANDROID_KEYSTORE_B64 | base64 -d > android/app/release-key.jks
121            bin/fastlane android build build_type:$BUILD_TYPE
122          fi
123      - name: �� Upload APK artifact
124        uses: actions/upload-artifact@v2
125        with:
126          name: android-apk
127          path: android/app/build/outputs/apk
128      - name: �� Store daemon logs for debugging crashes
129        if: failure()
130        uses: actions/upload-artifact@v2
131        with:
132          name: gradle-daemon-logs
133          path: ~/.gradle/daemon
134      - name: �� Upload APK to S3 and update staging versions endpoint
135        if: ${{ github.event.inputs.releaseAPK == 'release-apk' }}
136        run: bin/expotools client-build --platform android --release
137        env:
138          AWS_ACCESS_KEY_ID: AKIAJ3SWUQ4QLNQC7FXA
139          AWS_SECRET_ACCESS_KEY: ${{ secrets.android_client_build_aws_secret_key }}
140          EXPO_VERSIONS_SECRET: ${{ secrets.expo_versions_secret }}
141      - name: �� Upload APK to Google Play and release to production
142        if: ${{ github.event.inputs.releaseGooglePlay == 'release-google-play' }}
143        run: bin/fastlane android prod_release
144        env:
145          SUPPLY_JSON_KEY_DATA: ${{ secrets.SUPPLY_JSON_KEY_DATA }}
146      - name: �� Notify on Slack
147        uses: 8398a7/action-slack@v3
148        if: failure() && (github.event.ref == 'refs/heads/master' || startsWith(github.event.ref, 'refs/heads/sdk-'))
149        env:
150          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151          SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook_android }}
152        with:
153          channel: '#platform-android'
154          status: ${{ job.status }}
155          fields: job,message,ref,eventName,author,took
156          author_name: Expo Go (Android)
157