forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (187 loc) · 8.34 KB
/
_mac-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: mac-build
on:
workflow_call:
inputs:
build-environment:
required: true
type: string
description: Top-level label for what's being built/tested.
runner-type:
required: true
type: string
description: Name of the GitHub-managed runner type to use for the build.
build-generates-artifacts:
required: true
type: boolean
description: If set, upload generated build artifacts.
xcode-version:
required: false
type: string
default: ""
description: What xcode version to build with.
sync-tag:
required: false
type: string
default: ""
description: |
If this is set, our linter will use this to make sure that every other
job with the same `sync-tag` is identical.
python-version:
required: false
type: string
default: "3.8"
description: |
The python version to be used. Will be 3.8 by default
environment-file:
required: false
type: string
description: Set the conda environment file used to setup macOS build.
test-matrix:
required: false
type: string
description: |
An option JSON description of what test configs to run later on. This
is moved here from the Linux test workflow so that we can apply filter
logic using test-config labels earlier and skip unnecessary builds
sccache-use-gha:
required: false
type: boolean
default: false
description: If true, use the Github cache as the storage option for sccache instead of S3.
outputs:
test-matrix:
value: ${{ jobs.build.outputs.test-matrix }}
description: An optional JSON description of what test configs to run later on.
build-outcome:
value: ${{ jobs.build.outputs.build-outcome }}
description: The outcome of the build step. This is used to influence test filtering logic later on.
jobs:
build:
# Don't run on forked repos.
if: github.repository_owner == 'pytorch'
runs-on: ${{ inputs.runner-type }}
env:
BUILD_ENVIRONMENT: ${{ inputs.build-environment }}
SCCACHE_USE_GHA: ${{ inputs.sccache-use-gha }} # this is placed here instead of the sccache step to appease actionlint
outputs:
build-outcome: ${{ steps.build.outcome }}
test-matrix: ${{ steps.filter.outputs.test-matrix }}
steps:
- name: Clean up disk space before running MacOS workflow
uses: pytorch/test-infra/.github/actions/check-disk-space@main
# [see note: pytorch repo ref]
- name: Checkout PyTorch
uses: pytorch/pytorch/.github/actions/checkout-pytorch@main
- name: Set xcode version
env:
XCODE_VERSION: ${{ inputs.xcode-version }}
run: |
if [ -n "${XCODE_VERSION}" ]; then
echo "DEVELOPER_DIR=/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer" >> "${GITHUB_ENV}"
fi
- name: Setup miniconda
if: inputs.environment-file == ''
uses: pytorch/test-infra/.github/actions/setup-miniconda@main
with:
python-version: ${{ inputs.python-version }}
environment-file: .github/requirements/conda-env-${{ runner.os }}-${{ runner.arch }}
pip-requirements-file: .github/requirements/pip-requirements-${{ runner.os }}.txt
# This option is used when cross-compiling arm64 from x86-64. Specifically, we need arm64 conda
# environment even though the arch is x86-64
- name: Setup miniconda using the provided environment file
if: inputs.environment-file != ''
uses: pytorch/test-infra/.github/actions/setup-miniconda@main
with:
python-version: ${{ inputs.python-version }}
environment-file: ${{ inputs.environment-file }}
pip-requirements-file: .github/requirements/pip-requirements-${{ runner.os }}.txt
- name: Install sccache (only for non-forked PRs, and pushes to trunk)
uses: nick-fields/[email protected]
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
with:
timeout_minutes: 5
max_attempts: 3
retry_wait_seconds: 90
command: |
set -ex
DOWNLOAD_SCCACHE=0
SCCACHE_VERSION="0.4.1"
LOCAL_PATH="/usr/local/bin"
if [ ! -f "${LOCAL_PATH}/sccache" ]; then
DOWNLOAD_SCCACHE=1
else
LOCAL_VERSION=$("${LOCAL_PATH}/sccache" --version | cut -d" " -f2)
if [ "${LOCAL_VERSION}" != "${SCCACHE_VERSION}" ]; then
DOWNLOAD_SCCACHE=1
fi
fi
if [ "${DOWNLOAD_SCCACHE}" == "1" ]; then
sudo curl --retry 3 --retry-all-errors "https://s3.amazonaws.com/ossci-macos/sccache/sccache-v0.4.1-${RUNNER_ARCH}" --output "${LOCAL_PATH}/sccache"
sudo chmod +x "${LOCAL_PATH}/sccache"
fi
if [[ "${SCCACHE_USE_GHA}" == "true" ]]; then
echo "ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}" >> "${GITHUB_ENV}"
echo "ACTIONS_RUNTIME_TOKEN=${ACTIONS_RUNTIME_TOKEN}" >> "${GITHUB_ENV}"
echo "SCCACHE_GHA_ENABLED=on" >> "${GITHUB_ENV}"
else
# The runner has access to the S3 bucket via IAM profile without the need
# for any credential
echo "SCCACHE_BUCKET=ossci-compiler-cache-circleci-v2" >> "${GITHUB_ENV}"
echo "SCCACHE_S3_KEY_PREFIX=${GITHUB_WORKFLOW}" >> "${GITHUB_ENV}"
fi
# This is needed so that later build script could find sccache (which sccache)
echo "${LOCAL_PATH}" >> $GITHUB_PATH
- name: Get workflow job id
id: get-job-id
uses: ./.github/actions/get-workflow-job-id
if: always()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# Apply the filter logic to the build step too if the test-config label is already there
- name: Select all requested test configurations (if the test matrix is available)
id: filter
uses: ./.github/actions/filter-test-configs
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
test-matrix: ${{ inputs.test-matrix }}
job-name: ${{ steps.get-job-id.outputs.job-name }}
- name: Build
if: steps.filter.outputs.is-test-matrix-empty == 'False' || inputs.test-matrix == ''
id: build
env:
OUR_GITHUB_JOB_ID: ${{ steps.get-job-id.outputs.job-id }}
run: |
echo "CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname "$(which conda)")/../"}" >> "${GITHUB_ENV}"
if [[ -n "$CONDA_ENV" ]]; then
# Use binaries under conda environment
export PATH="$CONDA_ENV/bin":$PATH
fi
# NB: Same trick as Linux, there is no need to initialize sccache with the risk of getting
# it hangs or timeout at initialization. The cache will be started automatically
export SKIP_SCCACHE_INITIALIZATION=1
${CONDA_RUN} .ci/pytorch/macos-build.sh
- name: Archive artifacts into zip
if: inputs.build-generates-artifacts && steps.build.outcome != 'skipped'
run: |
zip -1 -r artifacts.zip dist/ build/.ninja_log build/compile_commands.json .additional_ci_files
- name: Store PyTorch Build Artifacts on GHA
uses: actions/upload-artifact@v3
if: inputs.build-generates-artifacts && steps.build.outcome != 'skipped'
with:
name: ${{ env.BUILD_ENVIRONMENT }}
retention-days: 14
if-no-files-found: error
path: artifacts.zip
- name: Upload sccache stats to GHA
uses: actions/upload-artifact@v3
# Only if sccache is installed, see above
if: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && steps.build.outcome != 'skipped' }}
with:
name: sccache-stats-${{ inputs.build-environment }}-runattempt${{ github.run_attempt }}-${{ steps.get-job-id.outputs.job-id }}
retention-days: 14
if-no-files-found: warn
path: sccache-stats-*.json
- name: Clean up disk space
if: always()
continue-on-error: true
uses: pytorch/test-infra/.github/actions/check-disk-space@main