Skip to content

Commit 3488ba3

Browse files
authored
Move Android CI Pipeline to Github Actions (microsoft#24094)
### Description Move Android CI Pipeline to Github Actions
1 parent 7fc7d5e commit 3488ba3

File tree

4 files changed

+275
-253
lines changed

4 files changed

+275
-253
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# .github/actions/setup-android-ndk/action.yml
2+
name: 'Setup Android NDK'
3+
description: 'Installs and configures a specific version of the Android NDK'
4+
inputs:
5+
ndk-version:
6+
description: 'The version of the Android NDK to install (e.g., 27.2.12479018)'
7+
required: true
8+
default: '27.2.12479018'
9+
android-sdk-root:
10+
description: 'The root directory of the Android SDK'
11+
required: true
12+
default: '/usr/local/lib/android/sdk'
13+
14+
runs:
15+
using: "composite" # Use a composite action for multiple shell commands
16+
steps:
17+
- name: Install coreutils and ninja
18+
shell: bash
19+
run: sudo apt-get update -y && sudo apt-get install -y coreutils ninja-build
20+
21+
- name: Install Android NDK
22+
shell: bash
23+
run: |
24+
set -e
25+
"${{ inputs.android-sdk-root }}/cmdline-tools/latest/bin/sdkmanager" --install "ndk;${{ inputs.ndk-version }}"
26+
27+
NDK_PATH="${{ inputs.android-sdk-root }}/ndk/${{ inputs.ndk-version }}"
28+
if [[ ! -d "${NDK_PATH}" ]]; then
29+
echo "NDK directory is not in expected location: ${NDK_PATH}"
30+
exit 1
31+
fi
32+
33+
# Use standard environment variable setting in bash and add to GITHUB_ENV
34+
echo "ANDROID_NDK_HOME=${NDK_PATH}" >> $GITHUB_ENV
35+
echo "ANDROID_NDK_ROOT=${NDK_PATH}" >> $GITHUB_ENV
36+
echo "ANDROID_NDK_HOME: ${NDK_PATH}"
37+
echo "ANDROID_NDK_ROOT: ${NDK_PATH}"
38+
39+
- name: Check if emulator are installed and add to PATH
40+
shell: bash
41+
run: |
42+
if [[ ":$PATH:" == *":${ANDROID_SDK_ROOT}/emulator:"* ]]; then
43+
echo "${ANDROID_SDK_ROOT}/emulator is in PATH"
44+
else
45+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "emulator"
46+
echo "${ANDROID_SDK_ROOT}/emulator" >> $GITHUB_PATH
47+
fi
48+
49+
- name: Check if platform tools are installed and add to PATH
50+
shell: bash
51+
run: |
52+
if [[ ":$PATH:" == *":${ANDROID_SDK_ROOT}/platform-tools:"* ]]; then
53+
echo "${ANDROID_SDK_ROOT}/platform-tools is in PATH"
54+
else
55+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "platform-tools"
56+
echo "${ANDROID_SDK_ROOT}/platform-tools" >> $GITHUB_PATH
57+
fi
58+
ls -R "${ANDROID_SDK_ROOT}/platform-tools"
59+
60+
- name: Create Android Emulator
61+
shell: bash
62+
env:
63+
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
64+
run: |
65+
python3 tools/python/run_android_emulator.py \
66+
--android-sdk-root "${ANDROID_SDK_ROOT}" \
67+
--create-avd --system-image "system-images;android-31;default;x86_64"
68+
69+
- name: List Android AVDs
70+
shell: bash
71+
env:
72+
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
73+
run: |
74+
"${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/avdmanager" list avd
75+
76+
- name: Check emulator.pid does not exist
77+
shell: bash
78+
run: |
79+
if test -f ./emulator.pid; then
80+
echo "Emulator PID file was not expected to exist but does and has pid: `cat ./emulator.pid`"
81+
exit 1
82+
fi
83+
84+
- name: Start Android Emulator
85+
shell: bash
86+
env:
87+
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
88+
run: |
89+
set -e -x
90+
python3 tools/python/run_android_emulator.py \
91+
--android-sdk-root "${ANDROID_SDK_ROOT}" \
92+
--start --emulator-extra-args="-partition-size 2047" \
93+
--emulator-pid-file ./emulator.pid
94+
echo "Emulator PID: `cat ./emulator.pid`"
95+
96+
- name: View Android ENVs
97+
shell: bash
98+
run: env | grep ANDROID

.github/workflows/android.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Android CI
2+
# This workflow is used to build and test on Android Emulator on Linux
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- rel-*
9+
pull_request:
10+
branches:
11+
- main
12+
- rel-*
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }}
17+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
18+
19+
jobs:
20+
android_nnapi_ep:
21+
runs-on: ["self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU"]
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Use jdk 17
26+
uses: actions/setup-java@v4
27+
with:
28+
distribution: 'temurin'
29+
java-version: '17'
30+
architecture: x64
31+
32+
- name: Setup Android NDK
33+
uses: ./.github/actions/setup-android-ndk
34+
with:
35+
ndk-version: 27.2.12479018
36+
37+
- name: Export GitHub Actions cache environment variables
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
42+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
43+
44+
- name: NNAPI EP, Build, Test on Android Emulator
45+
run: >-
46+
python3 tools/ci_build/build.py
47+
--enable_lto
48+
--android
49+
--build_dir build_nnapi
50+
--android_sdk_path "$ANDROID_HOME"
51+
--android_ndk_path "$ANDROID_NDK_HOME"
52+
--android_abi=x86_64
53+
--android_api=29
54+
--skip_submodule_sync
55+
--parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache
56+
--use_nnapi
57+
--build_shared_lib
58+
--cmake_generator=Ninja
59+
--build_java
60+
shell: bash
61+
62+
63+
- name: Build Minimal ORT with NNAPI and run tests
64+
run: tools/ci_build/github/linux/ort_minimal/nnapi_minimal_build_minimal_ort_and_run_tests.sh "$(pwd)"
65+
shell: bash
66+
67+
- name: Install psutil for emulator shutdown by run_android_emulator.py
68+
if: always()
69+
run: python3 -m pip install psutil
70+
shell: bash
71+
72+
- name: Stop Android Emulator
73+
if: always()
74+
run: |
75+
env | grep ANDROID
76+
if test -f ${{ github.workspace }}/emulator.pid; then
77+
echo "Emulator PID:"`cat ${{ github.workspace }}/emulator.pid`
78+
python3 tools/python/run_android_emulator.py \
79+
--android-sdk-root "${ANDROID_SDK_ROOT}" \
80+
--stop \
81+
--emulator-pid-file ${{ github.workspace }}/emulator.pid
82+
rm ${{ github.workspace }}/emulator.pid
83+
else
84+
echo "Emulator PID file was expected to exist but does not."
85+
fi
86+
shell: bash
87+
88+
android_cpu_ep:
89+
name: Android CI Pipeline
90+
runs-on: ["self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU"]
91+
steps:
92+
- uses: actions/checkout@v4
93+
94+
- name: Use jdk 17
95+
uses: actions/setup-java@v4
96+
with:
97+
distribution: 'temurin'
98+
java-version: '17'
99+
architecture: x64
100+
101+
- name: Setup Android NDK
102+
uses: ./.github/actions/setup-android-ndk
103+
with:
104+
ndk-version: 27.2.12479018
105+
106+
- name: Export GitHub Actions cache environment variables
107+
uses: actions/github-script@v7
108+
with:
109+
script: |
110+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
111+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
112+
113+
- name: CPU EP, Build and Test
114+
run: >-
115+
python3 tools/ci_build/build.py
116+
--enable_lto
117+
--android
118+
--build_dir build
119+
--android_sdk_path $ANDROID_HOME
120+
--android_ndk_path $ANDROID_NDK_HOME
121+
--android_abi=x86_64
122+
--android_api=30
123+
--skip_submodule_sync
124+
--parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache
125+
--cmake_generator=Ninja
126+
--build_java
127+
shell: bash
128+
129+
- name: Install psutil for emulator shutdown by run_android_emulator.py
130+
if: always()
131+
run: python3 -m pip install psutil
132+
shell: bash
133+
134+
- name: Stop Android Emulator
135+
if: always()
136+
run: |
137+
if test -f ${{ github.workspace }}/emulator.pid; then
138+
echo "Emulator PID:"`cat ${{ github.workspace }}/emulator.pid`
139+
python3 tools/python/run_android_emulator.py \
140+
--android-sdk-root "${ANDROID_SDK_ROOT}" \
141+
--stop \
142+
--emulator-pid-file ${{ github.workspace }}/emulator.pid
143+
rm ${{ github.workspace }}/emulator.pid
144+
else
145+
echo "Emulator PID file was expected to exist but does not."
146+
fi
147+
shell: bash

0 commit comments

Comments
 (0)