Repository navigation
220 lines (206 loc) · 9.13 KB
/
Copy pathreusable_linux_build.yml
File metadata and controls
220 lines (206 loc) · 9.13 KB
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
211
212
213
214
215
216
217
218
219
220
name: Reusable Linux CPU/GPU Build and Test
on:
workflow_call:
inputs:
pool_name:
description: 'The specific 1ES pool name (e.g., onnxruntime-github-Ubuntu2204-AMD-CPU)'
required: true
type: string
build_config:
description: 'Build configuration (Debug or Release)'
required: true
type: string
architecture:
description: 'Target architecture (x64 or arm64)'
required: true
type: string
dockerfile_path:
description: 'Path to the Dockerfile relative to the workspace root'
required: true
type: string
docker_image_repo:
description: 'Name for the Docker image repository'
required: true
type: string
docker_build_args:
description: 'Arguments to pass to the docker image build command'
required: false
type: string
default: ''
execution_providers:
description: 'Space-separated list of execution providers to enable (passed to build.py)'
required: false
type: string
default: ''
extra_build_flags:
description: 'Additional flags for the build.py script (appended after EP flags)'
required: false
type: string
default: ''
python_path_prefix:
description: 'Optional prefix to add to the PATH for python command (e.g., PATH=/opt/python/cp310-cp310/bin:$PATH)'
required: false
type: string
default: ''
python_version:
description: 'Python version to set up on the runner host'
required: false
type: string
default: '3.x'
run_tests:
description: 'Whether to execute the test suite after building'
required: false
type: boolean
default: true
run_go_tests:
description: 'Whether to run the Go binding race tests against the built shared library'
required: false
type: boolean
default: false
upload_build_output:
description: 'Whether to upload the build output directory as an artifact (used when tests are skipped)'
required: false
type: boolean
default: false
job_identifier:
description: 'A unique identifier for the job, used for hosted pool tracking'
required: true
type: string
secrets:
GH_TOKEN:
description: 'GitHub token for accessing actions/packages'
required: true
jobs:
build_test_pipeline:
runs-on:
- self-hosted
- "1ES.Pool=${{ inputs.pool_name }}"
- "JobId=${{ inputs.job_identifier }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}"
timeout-minutes: 120
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Set up Python ${{ inputs.python_version }}
if: inputs.architecture != 'arm64'
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: ${{ inputs.python_version }}
- name: Build Docker Image (${{ inputs.architecture }} / ${{ inputs.build_config }})
uses: microsoft/onnxruntime-github-actions/build-docker-image@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12
id: build_docker_image_step
with:
dockerfile: ${{ github.workspace }}/${{ inputs.dockerfile_path }}
image-name: ghcr.io/microsoft/onnxruntime/${{ inputs.docker_image_repo }}
build-args: ${{ inputs.docker_build_args }}
push: true
azure-container-registry-name: onnxruntimebuildcache
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Setup CCache
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
key: 'ccache | "${{ inputs.job_identifier }}" | "${{ inputs.architecture }}" | "${{ inputs.build_config }}"'
path: ~/.cache/cache
- name: Setup VCPKG Cache
uses: ./.github/actions/setup-vcpkg-cache
with:
key: ${{ inputs.job_identifier }}-${{ inputs.architecture }}-${{ inputs.build_config }}
# ------------- Update Step (CMake Generation) -------------
- name: Generate Build Files (CMake) (${{ inputs.architecture }} / ${{ inputs.build_config }})
id: update_step
uses: microsoft/onnxruntime-github-actions/run-build-script-in-docker@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12
with:
docker_image: ${{ steps.build_docker_image_step.outputs.full-image-name }}
build_config: ${{ inputs.build_config }}
mode: 'update'
execution_providers: ${{ inputs.execution_providers }} # Pass down EP list
extra_build_flags: ${{ inputs.extra_build_flags }} --use_cache
python_path_prefix: ${{ inputs.python_path_prefix }}
# ------------- Build Step (Compilation) -------------
- name: Build ONNX Runtime (${{ inputs.architecture }} / ${{ inputs.build_config }})
id: build_step
uses: microsoft/onnxruntime-github-actions/run-build-script-in-docker@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12
with:
docker_image: ${{ steps.build_docker_image_step.outputs.full-image-name }}
build_config: ${{ inputs.build_config }}
mode: 'build'
execution_providers: ${{ inputs.execution_providers }} # Pass down EP list
extra_build_flags: ${{ inputs.extra_build_flags }} --use_cache
python_path_prefix: ${{ inputs.python_path_prefix }}
# ------------- Test Step -------------
- name: Test ONNX Runtime (${{ inputs.architecture }} / ${{ inputs.build_config }})
id: test_step
if: inputs.run_tests == true
uses: microsoft/onnxruntime-github-actions/run-build-script-in-docker@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12
with:
docker_image: ${{ steps.build_docker_image_step.outputs.full-image-name }}
build_config: ${{ inputs.build_config }}
mode: 'test'
execution_providers: ${{ inputs.execution_providers }} # Pass down EP list
extra_build_flags: ${{ inputs.extra_build_flags }} --use_cache
python_path_prefix: ${{ inputs.python_path_prefix }}
- name: Set up Go
if: inputs.run_go_tests == true
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version-file: go/go.mod
cache: false
- name: Test Go bindings
if: inputs.run_go_tests == true
shell: bash
working-directory: go
env:
ORT_LIB_PATH: ${{ runner.temp }}/${{ inputs.build_config }}/${{ inputs.build_config }}
run: |
set -euo pipefail
test -f "${ORT_LIB_PATH}/libonnxruntime.so"
go test -race -count=1 ./onnxruntime
# ------------- Prepare Artifact Step -------------
- name: Prepare Build Output for Upload
if: inputs.upload_build_output == true
shell: bash
run: |
#!/bin/bash
set -e -x
BUILD_DIR="${{ runner.temp }}/${{ inputs.build_config }}"
if [ ! -d "${BUILD_DIR}" ]; then
echo "Error: Build directory ${BUILD_DIR} not found. Cannot prepare artifact."
exit 1
fi
echo "--- Cleaning build directory: ${BUILD_DIR} ---"
rm -rf "${BUILD_DIR}/onnxruntime" || true
rm -rf "${BUILD_DIR}/pybind11" || true
rm -rf "${BUILD_DIR}/vcpkg_installed" || true
rm -f "${BUILD_DIR}/models" || true
DEPS_DIR="${BUILD_DIR}/_deps"
if [ -d "${DEPS_DIR}" ]; then
echo "Cleaning ${DEPS_DIR}, keeping onnx-src..."
find "${DEPS_DIR}" -mindepth 1 ! -regex "^${DEPS_DIR}/onnx-src\(/.*\)?$" -delete
else
echo "${DEPS_DIR} does not exist, skipping deps cleanup."
fi
echo "--- Saving executable permissions ---"
cd "${BUILD_DIR}"
find . -executable -type f -printf '%p\n' > perms.txt
echo "--- Cleanup and permission saving complete for ${BUILD_DIR} ---"
# ------------- Upload Build Output Step -------------
- name: Upload Build Output Artifact
if: inputs.upload_build_output == true
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: build-output-${{ inputs.architecture }}-${{ inputs.build_config }}
path: ${{ runner.temp }}/${{ inputs.build_config }}
if-no-files-found: error
# ------------- Upload Log on Build Failure Step -------------
- name: Upload VCPKG Manifest Install Log on Update or Build Failure
if: steps.update_step.outcome == 'failure' || steps.build_step.outcome == 'failure'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: vcpkg-manifest-install-log-${{ inputs.architecture }}-${{ inputs.build_config }}
path: ${{ runner.temp }}/${{ inputs.build_config }}/${{ inputs.build_config }}/vcpkg-manifest-install.log
if-no-files-found: ignore