1name: mac-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 test-matrix: 11 required: true 12 type: string 13 description: JSON description of what test configs to run. 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 python-version: 22 required: false 23 type: string 24 default: "3.8" 25 description: | 26 The python version to be used. Will be 3.8 by default 27 timeout-minutes: 28 required: false 29 type: number 30 default: 270 31 description: | 32 Set the maximum (in minutes) how long the workflow should take to finish 33 34jobs: 35 test: 36 # Don't run on forked repos or empty test matrix 37 if: github.repository_owner == 'pytorch' && toJSON(fromJSON(inputs.test-matrix).include) != '[]' 38 # For setup-miniconda, see https://github.com/conda-incubator/setup-miniconda/issues/179 39 # Also ensure that we always run with the right architecture 40 defaults: 41 run: 42 shell: bash -e -l {0} 43 strategy: 44 matrix: ${{ fromJSON(inputs.test-matrix) }} 45 fail-fast: false 46 runs-on: ${{ matrix.runner }} 47 timeout-minutes: ${{ matrix.mem_leak_check == 'mem_leak_check' && 600 || inputs.timeout-minutes }} 48 env: 49 GIT_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} 50 BUILD_ENVIRONMENT: ${{ inputs.build-environment }} 51 TEST_CONFIG: ${{ matrix.config }} 52 SHARD_NUMBER: ${{ matrix.shard }} 53 NUM_TEST_SHARDS: ${{ matrix.num_shards }} 54 PR_BODY: ${{ github.event.pull_request.body }} 55 steps: 56 - name: Print runner OS/HW info 57 run: | 58 sysctl machdep.cpu.brand_string kern.osproductversion 59 60 - name: Clean up leftover processes on MacOS pet runner 61 continue-on-error: true 62 run: | 63 for PROCESS in "python" "conda" "ninja" "clang"; do 64 echo "Cleaning up all remaining ${PROCESS} process" 65 pkill "${PROCESS}" || true 66 done 67 68 - name: Clean up leftover local python3 site-packages on MacOS pet runner 69 continue-on-error: true 70 run: | 71 for dir in ~/.local/lib/python3.*/site-packages; do 72 echo "Cleaning up ${dir}" 73 rm -rf "${dir}" 74 done 75 76 - name: Clean up disk space before running MacOS workflow 77 uses: pytorch/test-infra/.github/actions/check-disk-space@release/2.4 78 79 # [see note: pytorch repo ref] 80 - name: Checkout PyTorch 81 uses: pytorch/pytorch/.github/actions/checkout-pytorch@release/2.4 82 83 - name: Download build artifacts 84 uses: ./.github/actions/download-build-artifacts 85 with: 86 name: ${{ inputs.build-environment }} 87 use-gha: true 88 89 - name: Download TD artifacts 90 continue-on-error: true 91 uses: ./.github/actions/download-td-artifacts 92 with: 93 use-gha: true 94 95 - name: Setup miniconda 96 uses: pytorch/test-infra/.github/actions/setup-miniconda@release/2.4 97 with: 98 python-version: ${{ inputs.python-version }} 99 environment-file: .github/requirements/conda-env-${{ runner.os }}-${{ runner.arch }} 100 pip-requirements-file: .github/requirements/pip-requirements-${{ runner.os }}.txt 101 102 - name: Start monitoring script 103 id: monitor-script 104 continue-on-error: true 105 run: | 106 ${CONDA_RUN} python3 -m tools.stats.monitor > usage_log.txt 2>&1 & 107 echo "monitor-script-pid=${!}" >> "${GITHUB_OUTPUT}" 108 109 - name: Parse ref 110 id: parse-ref 111 run: .github/scripts/parse_ref.py 112 113 - name: Get workflow job id 114 id: get-job-id 115 uses: ./.github/actions/get-workflow-job-id 116 if: always() 117 with: 118 github-token: ${{ secrets.GITHUB_TOKEN }} 119 120 - name: Check for keep-going label and re-enabled test issues 121 # This uses the filter-test-configs action because it conviniently 122 # checks for labels and re-enabled test issues. It does not actually do 123 # any filtering. All filtering is done in the build step. 124 id: keep-going 125 uses: ./.github/actions/filter-test-configs 126 with: 127 github-token: ${{ secrets.GITHUB_TOKEN }} 128 test-matrix: ${{ inputs.test-matrix }} 129 job-name: ${{ steps.get-job-id.outputs.job-name }} 130 131 - name: Set Test step time 132 id: test-timeout 133 shell: bash 134 env: 135 JOB_TIMEOUT: ${{ matrix.mem_leak_check == 'mem_leak_check' && 600 || inputs.timeout-minutes }} 136 run: | 137 echo "timeout=$((JOB_TIMEOUT-30))" >> "${GITHUB_OUTPUT}" 138 139 - name: Test 140 id: test 141 timeout-minutes: ${{ fromJson(steps.test-timeout.outputs.timeout) }} 142 env: 143 PYTORCH_TEST_CUDA_MEM_LEAK_CHECK: ${{ matrix.mem_leak_check && '1' || '0' }} 144 PYTORCH_TEST_RERUN_DISABLED_TESTS: ${{ matrix.rerun_disabled_tests && '1' || '0' }} 145 CONTINUE_THROUGH_ERROR: ${{ steps.keep-going.outputs.keep-going }} 146 VERBOSE_TEST_LOGS: ${{ steps.keep-going.outputs.ci-verbose-test-logs }} 147 NO_TEST_TIMEOUT: ${{ steps.keep-going.outputs.ci-no-test-timeout }} 148 NO_TD: ${{ steps.keep-going.outputs.ci-no-td }} 149 PIP_REQUIREMENTS_FILE: .github/requirements/pip-requirements-${{ runner.os }}.txt 150 GITHUB_REPOSITORY: ${{ github.repository }} 151 GITHUB_WORKFLOW: ${{ github.workflow }} 152 GITHUB_JOB: ${{ github.job }} 153 GITHUB_RUN_ID: ${{ github.run_id }} 154 GITHUB_RUN_NUMBER: ${{ github.run_number }} 155 GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }} 156 JOB_ID: ${{ steps.get-job-id.outputs.job-id }} 157 JOB_NAME: ${{ steps.get-job-id.outputs.job-name }} 158 REENABLED_ISSUES: ${{ steps.keep-going.outputs.reenabled-issues }} 159 run: | 160 # shellcheck disable=SC1090 161 set -ex 162 163 arch 164 165 if [[ -n "$CONDA_ENV" ]]; then 166 # Use binaries under conda environment 167 export PATH="$CONDA_ENV/bin":$PATH 168 fi 169 170 # Print out some information about the test environment 171 which conda 172 conda --version 173 ${CONDA_RUN} which python3 174 ${CONDA_RUN} python3 --version 175 ${CONDA_RUN} which python 176 ${CONDA_RUN} python --version 177 178 ${CONDA_RUN} python3 -mpip install --no-index --no-deps dist/*.whl 179 180 set +e 181 pushd "${RUNNER_TEMP}" 182 # Install pip dependencies if they are not found. This is to mitigate a peculiar 183 # flaky missing dependencies on MacOS 184 ${CONDA_RUN} python3 -c "import torch" 185 RC=$? 186 popd 187 188 if [ "${RC}" -ne 0 ]; then 189 ${CONDA_RUN} python3 -mpip install --ignore-installed -r "${PIP_REQUIREMENTS_FILE}" 190 fi 191 set -e 192 193 ${CONDA_RUN} .ci/pytorch/macos-test.sh 194 195 - name: Print remaining test logs 196 shell: bash 197 if: always() && steps.test.conclusion 198 run: | 199 cat test/**/*_toprint.log || true 200 201 - name: Stop monitoring script 202 if: always() && ${{ steps.monitor-script.outputs.monitor-script-pid }} 203 continue-on-error: true 204 env: 205 MONITOR_SCRIPT_PID: ${{ steps.monitor-script.outputs.monitor-script-pid }} 206 run: | 207 kill "$MONITOR_SCRIPT_PID" 208 209 - name: Upload test artifacts 210 uses: ./.github/actions/upload-test-artifacts 211 if: always() && steps.test.conclusion && steps.test.conclusion != 'skipped' 212 with: 213 use-gha: true 214 file-suffix: ${{ github.job }}-${{ matrix.config }}-${{ matrix.shard }}-${{ matrix.num_shards }}-${{ matrix.runner }}_${{ steps.get-job-id.outputs.job-id }} 215 216 - name: Clean up disk space 217 if: always() 218 continue-on-error: true 219 uses: pytorch/test-infra/.github/actions/check-disk-space@release/2.4 220