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@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.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