• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: android-tests
2
3on:
4  workflow_call:
5    inputs:
6      test-matrix:
7        required: true
8        type: string
9        description: |
10          A JSON description of what configs to run later on.
11
12defaults:
13  run:
14    shell: bash -e -l {0}
15
16jobs:
17  filter:
18    if: github.repository_owner == 'pytorch'
19    runs-on: [self-hosted, linux.large]
20    outputs:
21      test-matrix: ${{ steps.filter.outputs.test-matrix }}
22      is-test-matrix-empty: ${{ steps.filter.outputs.is-test-matrix-empty }}
23      keep-going: ${{ steps.filter.outputs.keep-going }}
24    steps:
25      - name: Checkout PyTorch
26        uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4
27        with:
28          fetch-depth: 1
29          submodules: false
30
31      - name: Select all requested test configurations
32        id: filter
33        uses: ./.github/actions/filter-test-configs
34        with:
35          github-token: ${{ secrets.GITHUB_TOKEN }}
36          test-matrix: ${{ inputs.test-matrix }}
37
38  build-and-test:
39    needs: filter
40    # Don't run on forked repos.
41    if: github.repository_owner == 'pytorch' && needs.filter.outputs.is-test-matrix-empty == 'False'
42    strategy:
43      matrix: ${{ fromJSON(needs.filter.outputs.test-matrix) }}
44      fail-fast: false
45    # NB: This job can only run on GitHub Linux runner atm. This is an ok thing though
46    # because that runner is ephemeral and could access upload secrets
47    runs-on: ${{ matrix.runner }}
48    env:
49      # GitHub runner installs Android SDK on this path
50      ANDROID_ROOT: /usr/local/lib/android
51      ANDROID_NDK_VERSION: '21.4.7075529'
52      BUILD_LITE_INTERPRETER: ${{ matrix.use_lite_interpreter }}
53      # 4 of them are supported atm: armeabi-v7a, arm64-v8a, x86, x86_64
54      SUPPORT_ABI: '${{ matrix.support_abi }}'
55    steps:
56      - name: Checkout PyTorch
57        uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4
58
59      - name: Setup miniconda
60        uses: pytorch/test-infra/.github/actions/setup-miniconda@release/2.4
61        with:
62          python-version: 3.8
63          environment-file: .github/requirements/conda-env-${{ runner.os }}-${{ runner.arch }}.txt
64
65      - name: Install NDK
66        uses: nick-fields/retry@v2.8.2
67        with:
68          timeout_minutes: 5
69          max_attempts: 3
70          retry_wait_seconds: 90
71          command: |
72            set -eux
73
74            # Install NDK 21 after GitHub update
75            # https://github.com/actions/virtual-environments/issues/5595
76            ANDROID_SDK_ROOT="${ANDROID_ROOT}/sdk"
77            ANDROID_NDK="${ANDROID_SDK_ROOT}/ndk-bundle"
78
79            SDKMANAGER="${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager"
80            # NB: This step downloads and installs NDK, thus it could be flaky.
81            # However, SDKMANAGER doesn't return a non-zero status code when it
82            # happens despite the fact that the corrupted file that it has isn't
83            # a ZIP archive and couldn't be extracted
84            echo "y" | ${SDKMANAGER} "ndk;${ANDROID_NDK_VERSION}"
85
86            ln -sfn "${ANDROID_SDK_ROOT}/ndk/${ANDROID_NDK_VERSION}" "${ANDROID_NDK}"
87            # So, we need to manually verify the existence of NDK afterward
88            # and return a failure if the file isn't there
89            if [ ! -f "${ANDROID_NDK}/build/cmake/android.toolchain.cmake" ]; then
90              exit 1
91            fi
92
93            echo "ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}" >> "${GITHUB_ENV}"
94            echo "ANDROID_NDK=${ANDROID_NDK}" >> "${GITHUB_ENV}"
95
96      - name: Build PyTorch Android
97        run: |
98          set -eux
99
100          echo "CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname "$(which conda)")/../"}" >> "${GITHUB_ENV}"
101          ${CONDA_RUN} ./scripts/build_pytorch_android.sh "${SUPPORT_ABI}"
102
103      - name: Run tests
104        uses: reactivecircus/android-emulator-runner@v2
105        with:
106          api-level: 25
107          script: ./android/run_tests.sh
108