Skip to content

Commit 84c6f1e

Browse files
authored
Add CI Android targets (#105)
Adds a CI Workflow to build the testapps against the publicly available packaged SDK.
1 parent b74606b commit 84c6f1e

File tree

11 files changed

+1718
-7
lines changed

11 files changed

+1718
-7
lines changed

.github/workflows/android.yml

+200-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,209 @@
1-
name: Android builds
1+
name: Android Builds
22

33
on:
4+
schedule:
5+
- cron: "0 9 * * *" # 9am UTC = 1am PST / 2am PDT. for all testapps except firestore
6+
pull_request:
7+
types: [opened, reopened, synchronize]
48
workflow_dispatch:
59
inputs:
610
apis:
7-
description: 'CSV of apis whose quickstart examples we should build'
11+
description: 'CSV of apis to build and test'
12+
default: 'admob,analytics,auth,database,dynamic_links,firestore,functions,gma,messaging,remote_config,storage'
13+
required: true
14+
15+
env:
16+
CCACHE_DIR: ${{ github.workspace }}/ccache_dir
17+
GITHUB_TOKEN: ${{ github.token }}
18+
xcodeVersion: "13.3.1" # Only affects Mac runners, and only for prerequisites.
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }}
22+
cancel-in-progress: true
823

924
jobs:
10-
build:
25+
check_and_prepare:
1126
runs-on: ubuntu-latest
27+
outputs:
28+
apis: ${{ steps.set_outputs.outputs.apis }}
1229
steps:
13-
- name: noop
14-
run: true
30+
- id: set_outputs
31+
run: |
32+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
33+
apis="${{ github.event.inputs.apis }}"
34+
else
35+
apis="admob,analytics,auth,database,dynamic_links,firestore,functions,gma,messaging,remote_config,storage"
36+
fi
37+
echo apis: ${apis}
38+
echo "::set-output name=apis::${apis}"
39+
40+
build:
41+
name: android-${{ matrix.os }}-${{ matrix.architecture }}-${{ matrix.python_version }}
42+
runs-on: ${{ matrix.os }}
43+
needs: [check_and_prepare]
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
os: [macos-12, ubuntu-latest, windows-latest]
48+
architecture: [x64]
49+
python_version: [3.7]
50+
steps:
51+
- name: setup Xcode version (macos)
52+
if: runner.os == 'macOS'
53+
run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer
54+
55+
- name: Store git credentials for all git commands
56+
# Forces all git commands to use authenticated https, to prevent throttling.
57+
shell: bash
58+
run: |
59+
git config --global credential.helper 'store --file /tmp/git-credentials'
60+
echo 'https://${{ github.token }}@github.com' > /tmp/git-credentials
61+
62+
- name: Enable Git Long-paths Support
63+
if: runner.os == 'Windows'
64+
run: git config --system core.longpaths true
65+
66+
- uses: actions/checkout@v2
67+
with:
68+
submodules: true
69+
70+
- name: Set env variables for subsequent steps (all)
71+
shell: bash
72+
run: |
73+
echo "MATRIX_UNIQUE_NAME=${{ matrix.os }}-${{ matrix.architecture }}" >> $GITHUB_ENV
74+
echo "GHA_INSTALL_CCACHE=1" >> $GITHUB_ENV
75+
76+
- name: Setup python
77+
uses: actions/setup-python@v2
78+
with:
79+
python-version: ${{ matrix.python_version }}
80+
architecture: ${{ matrix.architecture }}
81+
82+
- name: Add msbuild to PATH
83+
if: startsWith(matrix.os, 'windows')
84+
uses: microsoft/[email protected]
85+
86+
- name: Cache NDK
87+
id: cache_ndk
88+
uses: actions/cache@v2
89+
with:
90+
path: /tmp/android-ndk-r21e
91+
key: android-ndk-${{ matrix.os }}-r21e
92+
93+
- name: Check cached NDK
94+
shell: bash
95+
if: steps.cache_ndk.outputs.cache-hit != 'true'
96+
run: |
97+
# If the NDK failed to download from the cache, but there is a
98+
# /tmp/android-ndk-r21e directory, it's incomplete, so remove it.
99+
if [[ -d "/tmp/android-ndk-r21e" ]]; then
100+
echo "Removing incomplete download of NDK"
101+
rm -rf /tmp/android-ndk-r21e
102+
fi
103+
104+
- name: Update homebrew (avoid bintray errors)
105+
uses: nick-invision/retry@v2
106+
if: startsWith(matrix.os, 'macos')
107+
with:
108+
timeout_minutes: 10
109+
max_attempts: 3
110+
command: |
111+
# Temporarily here until Github runners have updated their version of
112+
# homebrew. This prevents errors arising from the shut down of
113+
# binutils, used by older version of homebrew for hosting packages.
114+
brew update
115+
116+
- name: Install prerequisites
117+
uses: nick-invision/retry@v2
118+
with:
119+
timeout_minutes: 10
120+
max_attempts: 3
121+
shell: bash
122+
command: |
123+
scripts/build_scripts/android/install_prereqs.sh
124+
echo "NDK_ROOT=/tmp/android-ndk-r21e" >> $GITHUB_ENV
125+
echo "ANDROID_NDK_HOME=/tmp/android-ndk-r21e" >> $GITHUB_ENV
126+
pip install -r scripts/build_scripts/python_requirements.txt
127+
python scripts/restore_secrets.py --passphrase "${{ secrets.TEST_SECRET }}"
128+
129+
- name: Download C++ SDK
130+
shell: bash
131+
run: |
132+
set +e
133+
# Retry up to 10 times because Curl has a tendency to timeout on
134+
# Github runners.
135+
for retry in {1..10} error; do
136+
if [[ $retry == "error" ]]; then exit 5; fi
137+
curl -LSs \
138+
"https://firebase.google.com/download/cpp" \
139+
--output firebase_cpp_sdk.zip && break
140+
sleep 300
141+
done
142+
set -e
143+
mkdir /tmp/downloaded_sdk
144+
unzip -q firebase_cpp_sdk.zip -d /tmp/downloaded_sdk/
145+
rm -f firebase_cpp_sdk.zip
146+
147+
- name: Cache ccache files
148+
id: cache_ccache
149+
uses: actions/cache@v2
150+
with:
151+
path: ccache_dir
152+
key: dev-test-ccache-${{ env.MATRIX_UNIQUE_NAME }}
153+
154+
- name: Build testapp
155+
shell: bash
156+
run: |
157+
set -x
158+
python scripts/build_scripts/build_testapps.py --p Android \
159+
--t ${{ needs.check_and_prepare.outputs.apis }} \
160+
--output_directory "${{ github.workspace }}" \
161+
--artifact_name "android-${{ matrix.os }}" \
162+
--noadd_timestamp \
163+
--short_output_paths \
164+
--gha_build \
165+
--packaged_sdk /tmp/downloaded_sdk/firebase_cpp_sdk
166+
167+
- name: Stats for ccache (mac and linux)
168+
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
169+
run: ccache -s
170+
171+
- name: Prepare results summary artifact
172+
if: ${{ !cancelled() }}
173+
shell: bash
174+
run: |
175+
if [ ! -f build-results-android-${{ matrix.os }}.log.json ]; then
176+
echo "__SUMMARY_MISSING__" > build-results-android-${{ matrix.os }}.log.json
177+
fi
178+
179+
- name: Upload Android integration tests artifact
180+
uses: actions/upload-artifact@v3
181+
if: ${{ !cancelled() }}
182+
with:
183+
name: testapps-android-${{ matrix.os }}
184+
path: testapps-android-${{ matrix.os }}
185+
retention-days: ${{ env.artifactRetentionDays }}
186+
187+
- name: Upload Android build results artifact
188+
uses: actions/upload-artifact@v3
189+
if: ${{ !cancelled() }}
190+
with:
191+
name: log-artifact
192+
path: build-results-android-${{ matrix.os }}*
193+
retention-days: ${{ env.artifactRetentionDays }}
194+
195+
- name: Download log artifacts
196+
if: ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
197+
uses: actions/download-artifact@v3
198+
with:
199+
path: test_results
200+
name: log-artifact
201+
202+
- name: Summarize build results
203+
if: ${{ !cancelled() }}
204+
shell: bash
205+
run: |
206+
cat build-results-android-${{ matrix.os }}.log
207+
if [[ "${{ job.status }}" != "success" ]]; then
208+
exit 1
209+
fi

analytics/testapp/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.2.1'
9+
classpath 'com.android.tools.build:gradle:3.3.3'
1010
classpath 'com.google.gms:google-services:4.0.1'
1111
}
1212
}

dynamic_links/testapp/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.2.1'
9+
classpath 'com.android.tools.build:gradle:3.3.3'
1010
classpath 'com.google.gms:google-services:4.0.1'
1111
}
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2022 Google LLC
4+
5+
if [[ $(uname) == "Darwin" ]]; then
6+
platform=darwin
7+
if [[ ! -z "${GHA_INSTALL_CCACHE}" ]]; then
8+
brew install ccache
9+
echo "CCACHE_INSTALLED=1" >> $GITHUB_ENV
10+
fi
11+
elif [[ $(uname) == "Linux" ]]; then
12+
platform=linux
13+
if [[ ! -z "${GHA_INSTALL_CCACHE}" ]]; then
14+
sudo apt install ccache
15+
echo "CCACHE_INSTALLED=1" >> $GITHUB_ENV
16+
fi
17+
else
18+
platform=windows
19+
fi
20+
21+
if [[ -z $(which cmake) ]]; then
22+
echo "Error, cmake is not installed or is not in the PATH."
23+
exit 1
24+
fi
25+
26+
if [[ -z $(which python) ]]; then
27+
echo "Error, python is not installed or is not in the PATH."
28+
exit 1
29+
else
30+
updated_pip=0
31+
if ! $(echo "import absl"$'\n' | python - 2> /dev/null); then
32+
echo "Installing python packages."
33+
set -x
34+
# On Windows bash shell, sudo doesn't exist
35+
if [[ $(uname) == "Linux" ]] || [[ $(uname) == "Darwin" ]]; then
36+
sudo python -m pip install --upgrade pip
37+
else
38+
python -m pip install --upgrade pip
39+
fi
40+
pip install absl-py
41+
set +x
42+
fi
43+
fi
44+
45+
if [[ -z "${ANDROID_HOME}" ]]; then
46+
echo "Error, ANDROID_HOME environment variable is not set."
47+
exit 1
48+
fi
49+
50+
if [[ -z "${NDK_ROOT}" || -z $(grep "Pkg\.Revision = 21\." "${NDK_ROOT}/source.properties") ]]; then
51+
if [[ -d /tmp/android-ndk-r21e && \
52+
-n $(grep "Pkg\.Revision = 21\." "/tmp/android-ndk-r21e/source.properties") ]]; then
53+
echo "Using NDK r21e in /tmp/android-ndk-r21e".
54+
else
55+
echo "NDK_ROOT environment variable is not set, or NDK version is incorrect."
56+
echo "This build recommends NDK r21e, downloading..."
57+
if [[ -z $(which curl) ]]; then
58+
echo "Error, could not run 'curl' to download NDK. Is it in your PATH?"
59+
exit 1
60+
fi
61+
set +e
62+
# Retry up to 10 times because Curl has a tendency to timeout on
63+
# Github runners.
64+
for retry in {1..10} error; do
65+
if [[ $retry == "error" ]]; then exit 5; fi
66+
curl --http1.1 -LSs \
67+
"https://dl.google.com/android/repository/android-ndk-r21e-${platform}-x86_64.zip" \
68+
--output /tmp/android-ndk-r21e.zip && break
69+
sleep 300
70+
done
71+
set -e
72+
(cd /tmp && unzip -oq android-ndk-r21e.zip && rm -f android-ndk-r21e.zip)
73+
echo "NDK r21e has been downloaded into /tmp/android-ndk-r21e"
74+
fi
75+
fi

0 commit comments

Comments
 (0)