2323 description : ' Name for the Docker image repository'
2424 required : true
2525 type : string
26+ docker_build_args :
27+ description : ' Arguments to pass to the docker build command'
28+ required : false
29+ type : string
30+ default : ' '
2631 extra_build_flags :
2732 description : ' Additional flags for the build.py script'
2833 required : false
3843 required : false
3944 type : string
4045 default : ' 3.x' # Use a sensible default
46+ run_tests :
47+ description : ' Whether to execute the test suite after building'
48+ required : false
49+ type : boolean
50+ default : true
51+ upload_build_output :
52+ description : ' Whether to upload the build output directory as an artifact (used when tests are skipped)'
53+ required : false
54+ type : boolean
55+ default : false
4156 secrets :
4257 GH_TOKEN :
4358 description : ' GitHub token for accessing actions/packages'
6681 with :
6782 Dockerfile : ${{ github.workspace }}/${{ inputs.dockerfile_path }}
6883 Repository : ${{ inputs.docker_image_repo }}
84+ DockerBuildArgs : ${{ inputs.DockerBuildArgs }}
6985 env :
7086 GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
7187
@@ -79,26 +95,23 @@ jobs:
7995 core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
8096 core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
8197
82- # ------------- Main Build and Test Step -------------
83- - name : Build and Test ONNX Runtime in Docker (${{ inputs.architecture }} / ${{ inputs.build_config }})
84- id : build_test # Add an ID to potentially reference its outcome if needed, though `if: failure()` is simpler
98+ # ------------- Build Step -------------
99+ - name : Build ONNX Runtime in Docker (${{ inputs.architecture }} / ${{ inputs.build_config }})
100+ id : build_step
85101 env :
86102 ALLOW_RELEASED_ONNX_OPSET_ONLY : 0
87103 NIGHTLY_BUILD : 1
88104 run : |
89105 set -ex
90- # Construct the build command
91- BUILD_CMD="${{ inputs.python_path_prefix }} python3 tools/ci_build/build.py \
106+ BUILD_CMD_BASE="${{ inputs.python_path_prefix }} python3 tools/ci_build/build.py \
92107 --build_dir build/${{ inputs.build_config }} --cmake_generator Ninja \
93108 --config ${{ inputs.build_config }} \
94109 --skip_submodule_sync \
95110 --build_shared_lib \
96111 --parallel \
97112 --use_vcpkg --use_vcpkg_ms_internal_asset_cache \
98113 --enable_onnx_tests \
99- ${{ inputs.extra_build_flags }}" # Add extra flags here
100-
101- # Execute build
114+ ${{ inputs.extra_build_flags }}"
102115 docker run --rm \
103116 --volume /data/onnx:/data/onnx:ro \
104117 --volume /data/models:/data/models:ro \
@@ -112,9 +125,27 @@ jobs:
112125 -e ACTIONS_CACHE_URL \
113126 -e RUNNER_TEMP=/onnxruntime_src/build \
114127 ${{ inputs.docker_image_repo }} \
115- /bin/bash -c "${BUILD_CMD} --update --build"
128+ /bin/bash -c "${BUILD_CMD_BASE} --update --build"
129+ # ------------- End Build Step -------------
116130
117- # Execute test (using the same base command but adding --test)
131+ # ------------- Test Step -------------
132+ - name : Test ONNX Runtime in Docker (${{ inputs.architecture }} / ${{ inputs.build_config }})
133+ id : test_step
134+ if : inputs.run_tests == true
135+ env :
136+ ALLOW_RELEASED_ONNX_OPSET_ONLY : 0
137+ NIGHTLY_BUILD : 1
138+ run : |
139+ set -ex
140+ BUILD_CMD_BASE="${{ inputs.python_path_prefix }} python3 tools/ci_build/build.py \
141+ --build_dir build/${{ inputs.build_config }} --cmake_generator Ninja \
142+ --config ${{ inputs.build_config }} \
143+ --skip_submodule_sync \
144+ --build_shared_lib \
145+ --parallel \
146+ --use_vcpkg --use_vcpkg_ms_internal_asset_cache \
147+ --enable_onnx_tests \
148+ ${{ inputs.extra_build_flags }}"
118149 docker run --rm \
119150 --volume /data/onnx:/data/onnx:ro \
120151 --volume /data/models:/data/models:ro \
@@ -128,16 +159,71 @@ jobs:
128159 -e ACTIONS_CACHE_URL \
129160 -e RUNNER_TEMP=/onnxruntime_src/build \
130161 ${{ inputs.docker_image_repo }} \
131- /bin/bash -c "${BUILD_CMD} --test"
132- # ------------- End Main Build and Test Step -------------
162+ /bin/bash -c "${BUILD_CMD_BASE} --test"
163+ # ------------- End Test Step -------------
164+
165+ # ------------- Prepare Artifact Step -------------
166+ - name : Prepare Build Output for Upload
167+ if : inputs.upload_build_output == true # Run only if upload is requested
168+ shell : bash
169+ run : |
170+ #!/bin/bash
171+ set -e -x
172+
173+ # Define the build directory based on workflow inputs
174+ BUILD_DIR="${{ github.workspace }}/build/${{ inputs.build_config }}"
175+
176+ # Check if build directory exists before proceeding
177+ if [ ! -d "${BUILD_DIR}" ]; then
178+ echo "Error: Build directory ${BUILD_DIR} not found. Cannot prepare artifact."
179+ exit 1
180+ fi
181+
182+ echo "--- Cleaning build directory: ${BUILD_DIR} ---"
183+
184+ # Remove specific subdirectories (use || true if they might not exist)
185+ rm -rf "${BUILD_DIR}/onnxruntime" || true
186+ rm -rf "${BUILD_DIR}/pybind11" || true
187+ rm -rf "${BUILD_DIR}/vcpkg_installed" || true
188+
189+ # Remove specific file
190+ rm -f "${BUILD_DIR}/models" || true
191+
192+ # Clean _deps directory, keeping only onnx-src
193+ DEPS_DIR="${BUILD_DIR}/_deps"
194+ if [ -d "${DEPS_DIR}" ]; then
195+ echo "Cleaning ${DEPS_DIR}, keeping onnx-src..."
196+ # Ensure paths in regex are correctly quoted/escaped for find
197+ find "${DEPS_DIR}" -mindepth 1 ! -regex "^${DEPS_DIR}/onnx-src\(/.*\)?$" -delete
198+ else
199+ echo "${DEPS_DIR} does not exist, skipping deps cleanup."
200+ fi
201+
202+ echo "--- Saving executable permissions ---"
203+ cd "${BUILD_DIR}"
204+ # Find executable files within the build directory and save list relative to BUILD_DIR
205+ # Using -printf '%p\n' ensures newline separation even with funny filenames
206+ find . -executable -type f -printf '%p\n' > perms.txt
207+
208+ echo "--- Cleanup and permission saving complete for ${BUILD_DIR} ---"
209+ # ------------- End Prepare Artifact Step -------------
210+
211+ # ------------- Upload Build Output Step -------------
212+ - name : Upload Build Output Artifact
213+ if : inputs.upload_build_output == true # Run only if upload is requested
214+ uses : actions/upload-artifact@v4
215+ with :
216+ name : build-output-${{ inputs.architecture }}-${{ inputs.build_config }}
217+ path : ${{ github.workspace }}/build/${{ inputs.build_config }}
218+ if-no-files-found : error # Fail if the directory to upload doesn't exist
219+ # ------------- End Upload Build Output Step -------------
133220
134- # ------------- Upload Log on Failure Step -------------
135- - name : Upload VCPKG Manifest Install Log on Failure
136- if : failure() # This step only runs if the previous steps (like build_test) failed
221+ # ------------- Upload Log on Build Failure Step -------------
222+ - name : Upload VCPKG Manifest Install Log on Build Failure
223+ if : steps.build_step.outcome == ' failure' # Only run if the build_step specifically failed
137224 uses : actions/upload-artifact@v4
138225 with :
139- name : vcpkg-manifest-install-log-${{ inputs.architecture }}-${{ inputs.build_config }} # Descriptive artifact name
140- # Use the exact path provided in the request
226+ name : vcpkg-manifest-install-log-${{ inputs.architecture }}-${{ inputs.build_config }}
141227 path : ${{ github.workspace }}/build/${{ inputs.build_config }}/${{ inputs.build_config }}/vcpkg-manifest-install.log
142228 if-no-files-found : ignore
143- # ------------- End Upload Log on Failure Step -------------
229+ # ------------- End Upload Log on Build Failure Step -------------
0 commit comments