1name: bazel 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 cuda-version: 15 required: true 16 type: string 17 description: What CUDA version to build with (i.e. "11.7"), "cpu" for none. 18 sync-tag: 19 required: false 20 type: string 21 default: "" 22 description: | 23 If this is set, our linter will use this to make sure that every other 24 job with the same `sync-tag` is identical. 25 test-matrix: 26 required: true 27 type: string 28 description: | 29 A JSON description of what configs to run later on. 30 31env: 32 GIT_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} 33 34jobs: 35 filter: 36 if: github.repository_owner == 'pytorch' 37 runs-on: [self-hosted, linux.large] 38 outputs: 39 test-matrix: ${{ steps.filter.outputs.test-matrix }} 40 is-test-matrix-empty: ${{ steps.filter.outputs.is-test-matrix-empty }} 41 keep-going: ${{ steps.filter.outputs.keep-going }} 42 reenabled-issues: ${{ steps.filter.outputs.reenabled-issues }} 43 steps: 44 - name: Checkout PyTorch 45 uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4 46 with: 47 fetch-depth: 1 48 submodules: false 49 50 - name: Select all requested test configurations 51 id: filter 52 uses: ./.github/actions/filter-test-configs 53 with: 54 github-token: ${{ secrets.GITHUB_TOKEN }} 55 test-matrix: ${{ inputs.test-matrix }} 56 57 build-and-test: 58 needs: filter 59 # Don't run on forked repos. 60 if: github.repository_owner == 'pytorch' && needs.filter.outputs.is-test-matrix-empty == 'False' 61 strategy: 62 matrix: ${{ fromJSON(needs.filter.outputs.test-matrix) }} 63 fail-fast: false 64 runs-on: ${{ matrix.runner }} 65 steps: 66 - name: Setup SSH (Click me for login details) 67 uses: pytorch/test-infra/.github/actions/setup-ssh@release/2.4 68 with: 69 github-secret: ${{ secrets.GITHUB_TOKEN }} 70 71 # [see note: pytorch repo ref] 72 - name: Checkout PyTorch 73 uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4 74 75 - name: Setup Linux 76 uses: ./.github/actions/setup-linux 77 78 - name: Calculate docker image 79 id: calculate-docker-image 80 uses: pytorch/test-infra/.github/actions/calculate-docker-image@release/2.4 81 with: 82 docker-image-name: ${{ inputs.docker-image-name }} 83 84 - name: Pull docker image 85 uses: pytorch/test-infra/.github/actions/pull-docker-image@release/2.4 86 with: 87 docker-image: ${{ steps.calculate-docker-image.outputs.docker-image }} 88 89 - name: Check if in a ARC runner 90 shell: bash 91 id: check_arc_runner 92 run: echo "IN_ARC_RUNNER=$([ -f /.inarc ] && echo true || echo false)" >> "$GITHUB_OUTPUT" 93 94 - name: Install nvidia driver, nvidia-docker runtime, set GPU_FLAG 95 uses: pytorch/test-infra/.github/actions/setup-nvidia@release/2.4 96 if: ${{ inputs.cuda-version != 'cpu' && steps.check_arc_runner.outputs.IN_ARC_RUNNER == 'false' }} 97 98 - name: Output disk space left 99 run: | 100 sudo df -H 101 102 - name: Preserve github env variables for use in docker 103 run: | 104 env | grep '^GITHUB' >> "/tmp/github_env_${GITHUB_RUN_ID}" 105 env | grep '^CI' >> "/tmp/github_env_${GITHUB_RUN_ID}" 106 107 - name: Parse ref 108 id: parse-ref 109 run: .github/scripts/parse_ref.py 110 111 - name: Get workflow job id 112 id: get-job-id 113 uses: ./.github/actions/get-workflow-job-id 114 if: always() 115 with: 116 github-token: ${{ secrets.GITHUB_TOKEN }} 117 118 - name: Build 119 env: 120 BUILD_ENVIRONMENT: ${{ inputs.build-environment }} 121 PR_NUMBER: ${{ github.event.pull_request.number }} 122 BRANCH: ${{ steps.parse-ref.outputs.branch }} 123 GITHUB_REPOSITORY: ${{ github.repository }} 124 GITHUB_WORKFLOW: ${{ github.workflow }} 125 GITHUB_JOB: ${{ github.job }} 126 GITHUB_RUN_ID: ${{ github.run_id }} 127 GITHUB_RUN_NUMBER: ${{ github.run_number }} 128 GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }} 129 JOB_ID: ${{ steps.get-job-id.outputs.job-id }} 130 REENABLED_ISSUES: ${{ needs.filter.outputs.reenabled-issues }} 131 # TODO duplicated 132 AWS_DEFAULT_REGION: us-east-1 133 SHA1: ${{ github.event.pull_request.head.sha || github.sha }} 134 SCCACHE_BUCKET: ossci-compiler-cache-circleci-v2 135 TORCH_CUDA_ARCH_LIST: 5.2 136 DOCKER_IMAGE: ${{ steps.calculate-docker-image.outputs.docker-image }} 137 OUR_GITHUB_JOB_ID: ${{ steps.get-job-id.outputs.job-id }} 138 CUDA_VERSION: ${{ inputs.cuda-version }} 139 run: | 140 export SHARD_NUMBER=0 141 # detached container should get cleaned up by teardown_ec2_linux 142 # TODO: Stop building test binaries as part of the build phase 143 # Make sure we copy test results from bazel-testlogs symlink to 144 # a regular directory ./test/test-reports 145 # shellcheck disable=SC2086 146 container_name=$(docker run \ 147 ${GPU_FLAG:-} \ 148 -e BUILD_ENVIRONMENT \ 149 -e GITHUB_ACTIONS \ 150 -e GITHUB_REPOSITORY \ 151 -e GITHUB_WORKFLOW \ 152 -e GITHUB_JOB \ 153 -e GITHUB_RUN_NUMBER \ 154 -e GITHUB_RUN_ATTEMPT \ 155 -e JOB_ID \ 156 -e GIT_DEFAULT_BRANCH="$GIT_DEFAULT_BRANCH" \ 157 -e SHARD_NUMBER \ 158 -e NUM_TEST_SHARDS \ 159 -e MAX_JOBS="$(nproc --ignore=2)" \ 160 -e SCCACHE_BUCKET \ 161 -e SKIP_SCCACHE_INITIALIZATION=1 \ 162 -e REENABLED_ISSUES \ 163 -e TORCH_CUDA_ARCH_LIST \ 164 -e OUR_GITHUB_JOB_ID \ 165 -e CUDA_VERSION \ 166 --env-file="/tmp/github_env_${GITHUB_RUN_ID}" \ 167 --security-opt seccomp=unconfined \ 168 --cap-add=SYS_PTRACE \ 169 --shm-size="1g" \ 170 --tty \ 171 --detach \ 172 --user jenkins \ 173 -v "${GITHUB_WORKSPACE}:/var/lib/jenkins/workspace" \ 174 -w /var/lib/jenkins/workspace \ 175 "${DOCKER_IMAGE}" 176 ) 177 docker exec -t "${container_name}" sh -c '.ci/pytorch/build.sh' 178 echo "container_id=${container_name}" >> "${GITHUB_ENV}" 179 180 - name: Test 181 id: test 182 # Time out the test phase after 3.5 hours 183 timeout-minutes: 120 184 run: | 185 docker exec -t "${container_id}" sh -c '.ci/pytorch/test.sh && cp -Lr ./bazel-testlogs ./test/test-reports' 186 187 - name: Print remaining test logs 188 shell: bash 189 if: always() && steps.test.conclusion 190 run: | 191 cat test/**/*_toprint.log || true 192 193 - name: Chown workspace 194 uses: ./.github/actions/chown-workspace 195 if: always() 196 197 - name: Upload test artifacts 198 uses: ./.github/actions/upload-test-artifacts 199 if: always() && steps.test.conclusion && steps.test.conclusion != 'skipped' 200 with: 201 file-suffix: bazel-${{ github.job }}_${{ steps.get-job-id.outputs.job-id }} 202 203 - name: Teardown Linux 204 uses: pytorch/test-infra/.github/actions/teardown-linux@release/2.4 205 if: always() 206