Skip to content

Add CI Android targets #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 200 additions & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,209 @@
name: Android builds
name: Android Builds

on:
schedule:
- cron: "0 9 * * *" # 9am UTC = 1am PST / 2am PDT. for all testapps except firestore
pull_request:
types: [opened, reopened, synchronize]
workflow_dispatch:
inputs:
apis:
description: 'CSV of apis whose quickstart examples we should build'
description: 'CSV of apis to build and test'
default: 'admob,analytics,auth,database,dynamic_links,firestore,functions,gma,messaging,remote_config,storage'
required: true

env:
CCACHE_DIR: ${{ github.workspace }}/ccache_dir
GITHUB_TOKEN: ${{ github.token }}
xcodeVersion: "13.3.1" # Only affects Mac runners, and only for prerequisites.

concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
build:
check_and_prepare:
runs-on: ubuntu-latest
outputs:
apis: ${{ steps.set_outputs.outputs.apis }}
steps:
- name: noop
run: true
- id: set_outputs
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
apis="${{ github.event.inputs.apis }}"
else
apis="admob,analytics,auth,database,dynamic_links,firestore,functions,gma,messaging,remote_config,storage"
fi
echo apis: ${apis}
echo "::set-output name=apis::${apis}"

build:
name: android-${{ matrix.os }}-${{ matrix.architecture }}-${{ matrix.python_version }}
runs-on: ${{ matrix.os }}
needs: [check_and_prepare]
strategy:
fail-fast: false
matrix:
os: [macos-12, ubuntu-latest, windows-latest]
architecture: [x64]
python_version: [3.7]
steps:
- name: setup Xcode version (macos)
if: runner.os == 'macOS'
run: sudo xcode-select -s /Applications/Xcode_${{ env.xcodeVersion }}.app/Contents/Developer

- name: Store git credentials for all git commands
# Forces all git commands to use authenticated https, to prevent throttling.
shell: bash
run: |
git config --global credential.helper 'store --file /tmp/git-credentials'
echo 'https://${{ github.token }}@github.com' > /tmp/git-credentials

- name: Enable Git Long-paths Support
if: runner.os == 'Windows'
run: git config --system core.longpaths true

- uses: actions/checkout@v2
with:
submodules: true

- name: Set env variables for subsequent steps (all)
shell: bash
run: |
echo "MATRIX_UNIQUE_NAME=${{ matrix.os }}-${{ matrix.architecture }}" >> $GITHUB_ENV
echo "GHA_INSTALL_CCACHE=1" >> $GITHUB_ENV

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}
architecture: ${{ matrix.architecture }}

- name: Add msbuild to PATH
if: startsWith(matrix.os, 'windows')
uses: microsoft/[email protected]

- name: Cache NDK
id: cache_ndk
uses: actions/cache@v2
with:
path: /tmp/android-ndk-r21e
key: android-ndk-${{ matrix.os }}-r21e

- name: Check cached NDK
shell: bash
if: steps.cache_ndk.outputs.cache-hit != 'true'
run: |
# If the NDK failed to download from the cache, but there is a
# /tmp/android-ndk-r21e directory, it's incomplete, so remove it.
if [[ -d "/tmp/android-ndk-r21e" ]]; then
echo "Removing incomplete download of NDK"
rm -rf /tmp/android-ndk-r21e
fi

- name: Update homebrew (avoid bintray errors)
uses: nick-invision/retry@v2
if: startsWith(matrix.os, 'macos')
with:
timeout_minutes: 10
max_attempts: 3
command: |
# Temporarily here until Github runners have updated their version of
# homebrew. This prevents errors arising from the shut down of
# binutils, used by older version of homebrew for hosting packages.
brew update

- name: Install prerequisites
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
shell: bash
command: |
scripts/build_scripts/android/install_prereqs.sh
echo "NDK_ROOT=/tmp/android-ndk-r21e" >> $GITHUB_ENV
echo "ANDROID_NDK_HOME=/tmp/android-ndk-r21e" >> $GITHUB_ENV
pip install -r scripts/build_scripts/python_requirements.txt
python scripts/restore_secrets.py --passphrase "${{ secrets.TEST_SECRET }}"

- name: Download C++ SDK
shell: bash
run: |
set +e
# Retry up to 10 times because Curl has a tendency to timeout on
# Github runners.
for retry in {1..10} error; do
if [[ $retry == "error" ]]; then exit 5; fi
curl -LSs \
"https://firebase.google.com/download/cpp" \
--output firebase_cpp_sdk.zip && break
sleep 300
done
set -e
mkdir /tmp/downloaded_sdk
unzip -q firebase_cpp_sdk.zip -d /tmp/downloaded_sdk/
rm -f firebase_cpp_sdk.zip

- name: Cache ccache files
id: cache_ccache
uses: actions/cache@v2
with:
path: ccache_dir
key: dev-test-ccache-${{ env.MATRIX_UNIQUE_NAME }}

- name: Build testapp
shell: bash
run: |
set -x
python scripts/build_scripts/build_testapps.py --p Android \
--t ${{ needs.check_and_prepare.outputs.apis }} \
--output_directory "${{ github.workspace }}" \
--artifact_name "android-${{ matrix.os }}" \
--noadd_timestamp \
--short_output_paths \
--gha_build \
--packaged_sdk /tmp/downloaded_sdk/firebase_cpp_sdk

- name: Stats for ccache (mac and linux)
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
run: ccache -s

- name: Prepare results summary artifact
if: ${{ !cancelled() }}
shell: bash
run: |
if [ ! -f build-results-android-${{ matrix.os }}.log.json ]; then
echo "__SUMMARY_MISSING__" > build-results-android-${{ matrix.os }}.log.json
fi

- name: Upload Android integration tests artifact
uses: actions/upload-artifact@v3
if: ${{ !cancelled() }}
with:
name: testapps-android-${{ matrix.os }}
path: testapps-android-${{ matrix.os }}
retention-days: ${{ env.artifactRetentionDays }}

- name: Upload Android build results artifact
uses: actions/upload-artifact@v3
if: ${{ !cancelled() }}
with:
name: log-artifact
path: build-results-android-${{ matrix.os }}*
retention-days: ${{ env.artifactRetentionDays }}

- name: Download log artifacts
if: ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
uses: actions/download-artifact@v3
with:
path: test_results
name: log-artifact

- name: Summarize build results
if: ${{ !cancelled() }}
shell: bash
run: |
cat build-results-android-${{ matrix.os }}.log
if [[ "${{ job.status }}" != "success" ]]; then
exit 1
fi
2 changes: 1 addition & 1 deletion analytics/testapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
Expand Down
2 changes: 1 addition & 1 deletion dynamic_links/testapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
Expand Down
75 changes: 75 additions & 0 deletions scripts/build_scripts/android/install_prereqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash -e

# Copyright 2022 Google LLC

if [[ $(uname) == "Darwin" ]]; then
platform=darwin
if [[ ! -z "${GHA_INSTALL_CCACHE}" ]]; then
brew install ccache
echo "CCACHE_INSTALLED=1" >> $GITHUB_ENV
fi
elif [[ $(uname) == "Linux" ]]; then
platform=linux
if [[ ! -z "${GHA_INSTALL_CCACHE}" ]]; then
sudo apt install ccache
echo "CCACHE_INSTALLED=1" >> $GITHUB_ENV
fi
else
platform=windows
fi

if [[ -z $(which cmake) ]]; then
echo "Error, cmake is not installed or is not in the PATH."
exit 1
fi

if [[ -z $(which python) ]]; then
echo "Error, python is not installed or is not in the PATH."
exit 1
else
updated_pip=0
if ! $(echo "import absl"$'\n' | python - 2> /dev/null); then
echo "Installing python packages."
set -x
# On Windows bash shell, sudo doesn't exist
if [[ $(uname) == "Linux" ]] || [[ $(uname) == "Darwin" ]]; then
sudo python -m pip install --upgrade pip
else
python -m pip install --upgrade pip
fi
pip install absl-py
set +x
fi
fi

if [[ -z "${ANDROID_HOME}" ]]; then
echo "Error, ANDROID_HOME environment variable is not set."
exit 1
fi

if [[ -z "${NDK_ROOT}" || -z $(grep "Pkg\.Revision = 21\." "${NDK_ROOT}/source.properties") ]]; then
if [[ -d /tmp/android-ndk-r21e && \
-n $(grep "Pkg\.Revision = 21\." "/tmp/android-ndk-r21e/source.properties") ]]; then
echo "Using NDK r21e in /tmp/android-ndk-r21e".
else
echo "NDK_ROOT environment variable is not set, or NDK version is incorrect."
echo "This build recommends NDK r21e, downloading..."
if [[ -z $(which curl) ]]; then
echo "Error, could not run 'curl' to download NDK. Is it in your PATH?"
exit 1
fi
set +e
# Retry up to 10 times because Curl has a tendency to timeout on
# Github runners.
for retry in {1..10} error; do
if [[ $retry == "error" ]]; then exit 5; fi
curl --http1.1 -LSs \
"https://dl.google.com/android/repository/android-ndk-r21e-${platform}-x86_64.zip" \
--output /tmp/android-ndk-r21e.zip && break
sleep 300
done
set -e
(cd /tmp && unzip -oq android-ndk-r21e.zip && rm -f android-ndk-r21e.zip)
echo "NDK r21e has been downloaded into /tmp/android-ndk-r21e"
fi
fi
Loading