Skip to content

Commit 257e991

Browse files
committed
Move android.yml to pull.yml
1 parent fe20be9 commit 257e991

File tree

4 files changed

+191
-17
lines changed

4 files changed

+191
-17
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
8+
"""
9+
Helper to determine whether a CI should run on a list of modified files.
10+
Takes a list of modified files and a list of matchers.
11+
If any modified file matches to the matcher, print '1' to indicate CI should
12+
run.
13+
"""
14+
15+
16+
import re
17+
18+
19+
def filename_matches(filename: str, matchers: list[str]):
20+
combined = "(" + ")|(".join(matchers) + ")"
21+
return re.match(combined, filename)
22+
23+
24+
def any_match(modified_files: list[str], matchers: list[str]):
25+
return any(filename_matches(f, matchers) for f in modified_files)
26+
27+
28+
def main(modified_file_list_path: str, matchers_path: str):
29+
with open(modified_file_list_path, "r") as f:
30+
modified_files = f.read().splitlines()
31+
with open(matchers_path, "r") as f:
32+
matchers = f.read().splitlines()
33+
if any_match(modified_files, matchers):
34+
print("1")
35+
else:
36+
print("0")
37+
38+
39+
if __name__ == "__main__":
40+
main()

.github/workflows/_android.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Android
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
build-llm-demo:
13+
name: build-llm-demo
14+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
15+
with:
16+
runner: linux.2xlarge
17+
docker-image: executorch-ubuntu-22.04-clang12-android
18+
submodules: 'true'
19+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
20+
timeout: 90
21+
upload-artifact: android-apps
22+
upload-artifact-to-s3: true
23+
script: |
24+
set -eux
25+
26+
# The generic Linux job chooses to use base env, not the one setup by the image
27+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
28+
conda activate "${CONDA_ENV}"
29+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
30+
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
31+
32+
# Build LLM Demo for Android
33+
bash build/build_android_llm_demo.sh ${ARTIFACTS_DIR_NAME}
34+
35+
# Running Android emulator directly on the runner and not using Docker
36+
run-emulator:
37+
needs: build-llm-demo
38+
# NB: Use metal install for KVM support to run the emulator faster
39+
runs-on: linux.24xl.spr-metal
40+
env:
41+
ANDROID_NDK_VERSION: r27b
42+
API_LEVEL: 34
43+
steps:
44+
- name: Setup SSH (Click me for login details)
45+
uses: pytorch/test-infra/.github/actions/setup-ssh@main
46+
with:
47+
github-secret: ${{ secrets.GITHUB_TOKEN }}
48+
instructions: |
49+
This is used to run Android emulators, ANDROID_HOME is installed at /opt/android/sdk
50+
51+
- uses: actions/checkout@v3
52+
with:
53+
submodules: false
54+
55+
- name: Setup conda
56+
uses: pytorch/test-infra/.github/actions/setup-miniconda@main
57+
with:
58+
python-version: '3.10'
59+
60+
- name: Install Android dependencies
61+
shell: bash
62+
run: |
63+
set -eux
64+
65+
# Reuse the script that install Android on ET Docker image
66+
sudo -E bash .ci/docker/common/install_android.sh
67+
68+
# After https://github.com/ReactiveCircus/android-emulator-runner/releases/tag/v2.33.0 release,
69+
# it seems that we need to chown the Android setup to the current user instead of root to
70+
# avoid permission issue
71+
sudo chown -R "${USER}" /opt/android
72+
73+
- name: Gradle cache
74+
uses: gradle/actions/setup-gradle@v3
75+
76+
- name: AVD cache
77+
uses: actions/cache@v4
78+
id: avd-cache
79+
with:
80+
path: |
81+
~/.android/avd/*
82+
~/.android/adb*
83+
key: avd-${{ env.API_LEVEL }}
84+
85+
# NB: It takes about 10m to cold boot the emulator here
86+
- name: Run Android emulator
87+
env:
88+
ANDROID_HOME: /opt/android/sdk
89+
uses: reactivecircus/android-emulator-runner@v2
90+
with:
91+
api-level: ${{ env.API_LEVEL }}
92+
arch: x86_64
93+
script: ./build/run_android_emulator.sh
94+
# NB: This is to boot the emulator faster following the instructions on
95+
# https://github.com/ReactiveCircus/android-emulator-runner. The max number
96+
# of cores we can set is 6, any higher number will be reduced to 6.
97+
cores: 6
98+
ram-size: 12288M
99+
force-avd-creation: false
100+
disable-animations: true
101+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
102+
# This is to make sure that the job doesn't fail flakily
103+
emulator-boot-timeout: 900

.github/workflows/android.yml

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
11
name: Android
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- release/*
8-
tags:
9-
- ciflow/android/*
10-
pull_request:
11-
paths:
12-
- .ci/docker/**
13-
- .github/workflows/android.yml
14-
- build/*android*.sh
15-
- install_requirements.sh
16-
- examples/demo-apps/android/**
17-
- extension/android/**
18-
- extension/benchmark/android/**
19-
- extension/module/**
4+
workflow_call:
205
workflow_dispatch:
216

227
concurrency:
23-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
249
cancel-in-progress: true
2510

2611
jobs:
12+
check_path:
13+
name: Check whether the affected path needs to be validated by this CI
14+
runs-on: ubuntu-22.04
15+
outputs:
16+
should_run: ${{ steps.check-path.outputs.should_run }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: '0'
21+
- uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.10'
24+
- name: Check path
25+
id: check-path
26+
env:
27+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
28+
GITHUB_PR_BASE: ${{ github.base_ref }}
29+
GITHUB_PR_HEAD: ${{ github.head_ref }}
30+
run: |
31+
if [ -z "$GITHUB_PR_NUMBER" ]; then
32+
# It's not for a PR, but pushed to a branch in pull.yml, or dispatch. Always run.
33+
echo "::set-output should_run=1"
34+
return 0
35+
fi
36+
if [ -z "$GITHUB_PR_BASE" ] || [ -z "$GITHUB_PR_HEAD" ] ; then
37+
# Seems like not a well-formed PR
38+
echo "::set-output should_run=1"
39+
return 0
40+
fi
41+
git diff --name-only "$GITHUB_PR_BASE" "$GITHUB_PR_HEAD" > modified_files
42+
cat >> matcher<< EOF
43+
.ci/docker/
44+
.github/workflows/android.yml
45+
build/.*android.*.sh
46+
install_requirements.sh
47+
examples/demo-apps/android
48+
extension/android
49+
extension/benchmark/android
50+
extension/module
51+
EOF
52+
echo "::set-output should_run=$(python .github/scripts/check_path_match.py modified_files matcher)"
53+
2754
build-llm-demo:
2855
name: build-llm-demo
2956
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
57+
if: ${{ steps.check_path.outputs.should_run }} == '1'
3058
with:
3159
runner: linux.2xlarge
3260
docker-image: executorch-ubuntu-22.04-clang12-android

.github/workflows/pull.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ jobs:
347347
exit 1
348348
fi
349349
350+
android:
351+
uses: ./.github/workflows/_android.yml
352+
350353
unittest:
351354
uses: ./.github/workflows/_unittest.yml
352355
with:

0 commit comments

Comments
 (0)