• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: android-full-build-test
2
3on:
4  workflow_call:
5    inputs:
6      build-environment:
7        required: true
8        type: string
9        description: Top-level label for what's being built/tested.
10      docker-image-name:
11        required: true
12        type: string
13        description: Name of the base docker image to build with.
14      sync-tag:
15        required: false
16        type: string
17        default: ""
18        description: |
19          If this is set, our linter will use this to make sure that every other
20          job with the same `sync-tag` is identical.
21      test-matrix:
22        required: true
23        type: string
24        description: |
25          A JSON description of what configs to run later on.
26
27env:
28  GIT_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
29
30jobs:
31  filter:
32    if: github.repository_owner == 'pytorch'
33    runs-on: [self-hosted, linux.large]
34    outputs:
35      test-matrix: ${{ steps.filter.outputs.test-matrix }}
36      is-test-matrix-empty: ${{ steps.filter.outputs.is-test-matrix-empty }}
37      keep-going: ${{ steps.filter.outputs.keep-going }}
38    steps:
39      - name: Checkout PyTorch
40        uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4
41        with:
42          fetch-depth: 1
43          submodules: false
44
45      - name: Select all requested test configurations
46        id: filter
47        uses: ./.github/actions/filter-test-configs
48        with:
49          github-token: ${{ secrets.GITHUB_TOKEN }}
50          test-matrix: ${{ inputs.test-matrix }}
51
52  build:
53    needs: filter
54    # Don't run on forked repos.
55    if: github.repository_owner == 'pytorch' && needs.filter.outputs.is-test-matrix-empty == 'False'
56    strategy:
57      matrix: ${{ fromJSON(needs.filter.outputs.test-matrix) }}
58      fail-fast: false
59    runs-on: ${{ matrix.runner }}
60    steps:
61      - name: Setup SSH (Click me for login details)
62        uses: pytorch/test-infra/.github/actions/setup-ssh@release/2.4
63        with:
64          github-secret: ${{ secrets.GITHUB_TOKEN }}
65
66      # [see note: pytorch repo ref]
67      - name: Checkout PyTorch
68        uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4
69
70      - name: Setup Linux
71        uses: ./.github/actions/setup-linux
72
73      - name: Calculate docker image
74        id: calculate-docker-image
75        uses: pytorch/test-infra/.github/actions/calculate-docker-image@release/2.4
76        with:
77          docker-image-name: ${{ inputs.docker-image-name }}
78
79      - name: Pull docker image
80        uses: pytorch/test-infra/.github/actions/pull-docker-image@release/2.4
81        with:
82          docker-image: ${{ steps.calculate-docker-image.outputs.docker-image }}
83
84      - name: Output disk space left
85        shell: bash
86        run: |
87          sudo df -H
88
89      - name: Preserve github env variables for use in docker
90        shell: bash
91        run: |
92          env | grep '^GITHUB' >> "/tmp/github_env_${GITHUB_RUN_ID}"
93          env | grep '^CI' >> "/tmp/github_env_${GITHUB_RUN_ID}"
94
95      - name: Parse ref
96        id: parse-ref
97        run: .github/scripts/parse_ref.py
98
99      - name: Build arm-v7a
100        uses: ./.github/actions/build-android
101        with:
102          arch: arm_v7a
103          arch-for-build-env: arm-v7a
104          github-secret: ${{ secrets.GITHUB_TOKEN }}
105          build-environment: ${{ inputs.build-environment }}
106          docker-image: ${{ steps.calculate-docker-image.outputs.docker-image }}
107          branch: ${{ steps.parse-ref.outputs.branch }}
108
109      - name: Build arm-v8a
110        uses: ./.github/actions/build-android
111        with:
112          arch: arm_v8a
113          arch-for-build-env: arm-v8a
114          github-secret: ${{ secrets.GITHUB_TOKEN }}
115          build-environment: ${{ inputs.build-environment }}
116          docker-image: ${{ steps.calculate-docker-image.outputs.docker-image }}
117          branch: ${{ steps.parse-ref.outputs.branch }}
118
119      - name: Build x86_32
120        id: build-x86_32
121        uses: ./.github/actions/build-android
122        with:
123          arch: x86_32
124          arch-for-build-env: x86_32
125          github-secret: ${{ secrets.GITHUB_TOKEN }}
126          build-environment: ${{ inputs.build-environment }}
127          docker-image: ${{ steps.calculate-docker-image.outputs.docker-image }}
128          branch: ${{ steps.parse-ref.outputs.branch }}
129
130      - name: Build x86_64
131        uses: ./.github/actions/build-android
132        with:
133          arch: x86_64
134          arch-for-build-env: x86_64
135          github-secret: ${{ secrets.GITHUB_TOKEN }}
136          build-environment: ${{ inputs.build-environment }}
137          docker-image: ${{ steps.calculate-docker-image.outputs.docker-image }}
138          branch: ${{ steps.parse-ref.outputs.branch }}
139
140      - name: Build final artifact
141        env:
142          BRANCH: ${{ steps.parse-ref.outputs.branch }}
143          DOCKER_IMAGE: ${{ steps.calculate-docker-image.outputs.docker-image }}
144          AWS_DEFAULT_REGION: us-east-1
145          PR_NUMBER: ${{ github.event.pull_request.number }}
146          SHA1: ${{ github.event.pull_request.head.sha || github.sha }}
147          SCCACHE_BUCKET: ossci-compiler-cache-circleci-v2
148          ID_X86_32: ${{ steps.build-x86_32.outputs.container_id }}
149        run: |
150          set -eux
151
152          # Putting everything together
153          # ID_X86_32 container were created during build-x86_32 step
154          docker cp "${GITHUB_WORKSPACE}/build_android_install_arm_v7a" "${ID_X86_32}:/var/lib/jenkins/workspace/build_android_install_arm_v7a"
155          docker cp "${GITHUB_WORKSPACE}/build_android_install_x86_64" "${ID_X86_32}:/var/lib/jenkins/workspace/build_android_install_x86_64"
156          docker cp "${GITHUB_WORKSPACE}/build_android_install_arm_v8a" "${ID_X86_32}:/var/lib/jenkins/workspace/build_android_install_arm_v8a"
157          docker cp "${GITHUB_WORKSPACE}/build_android_install_x86_32" "${ID_X86_32}:/var/lib/jenkins/workspace/build_android_install_x86_32"
158
159          # run gradle buildRelease
160          (echo "./scripts/build_android_gradle.sh" | docker exec \
161            -e BUILD_ENVIRONMENT="pytorch-linux-focal-py3-clang9-android-ndk-r21e-gradle-build" \
162            -e MAX_JOBS="$(nproc --ignore=2)" \
163            -e AWS_DEFAULT_REGION \
164            -e PR_NUMBER \
165            -e SHA1 \
166            -e BRANCH \
167            -e SCCACHE_BUCKET \
168            -e SKIP_SCCACHE_INITIALIZATION=1 \
169            --env-file="/tmp/github_env_${GITHUB_RUN_ID}" \
170            --user jenkins \
171            -u jenkins -i "${ID_X86_32}" bash) 2>&1
172
173          mkdir -p "${GITHUB_WORKSPACE}/build_android_artifacts"
174          docker cp "${ID_X86_32}:/var/lib/jenkins/workspace/android/artifacts.tgz" "${GITHUB_WORKSPACE}/build_android_artifacts/"
175
176      - name: Store PyTorch Android Build Artifacts on S3
177        uses: seemethere/upload-artifact-s3@v5
178        with:
179          name: ${{ inputs.build-environment }}
180          retention-days: 14
181          if-no-files-found: error
182          path: build_android_artifacts/artifacts.tgz
183
184      - name: Chown workspace
185        uses: ./.github/actions/chown-workspace
186        if: always()
187
188      - name: Teardown Linux
189        uses: pytorch/test-infra/.github/actions/teardown-linux@release/2.4
190        if: always()
191