|
| 1 | +name: Reusable Linux CPU/GPU Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + pool_name: |
| 7 | + description: 'The specific 1ES pool name (e.g., onnxruntime-github-Ubuntu2204-AMD-CPU)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + build_config: |
| 11 | + description: 'Build configuration (Debug or Release)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + architecture: |
| 15 | + description: 'Target architecture (x64 or arm64)' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + dockerfile_path: |
| 19 | + description: 'Path to the Dockerfile relative to the workspace root' |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + docker_image_repo: |
| 23 | + description: 'Name for the Docker image repository' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + docker_build_args: |
| 27 | + description: 'Arguments to pass to the docker image build command' |
| 28 | + required: false |
| 29 | + type: string |
| 30 | + default: '' |
| 31 | + execution_providers: |
| 32 | + description: 'Space-separated list of execution providers to enable (passed to build.py)' |
| 33 | + required: false |
| 34 | + type: string |
| 35 | + default: '' |
| 36 | + extra_build_flags: |
| 37 | + description: 'Additional flags for the build.py script (appended after EP flags)' |
| 38 | + required: false |
| 39 | + type: string |
| 40 | + default: '' |
| 41 | + python_path_prefix: |
| 42 | + description: 'Optional prefix to add to the PATH for python command (e.g., PATH=/opt/python/cp310-cp310/bin:$PATH)' |
| 43 | + required: false |
| 44 | + type: string |
| 45 | + default: '' |
| 46 | + python_version: |
| 47 | + description: 'Python version to set up on the runner host' |
| 48 | + required: false |
| 49 | + type: string |
| 50 | + default: '3.x' |
| 51 | + run_tests: |
| 52 | + description: 'Whether to execute the test suite after building' |
| 53 | + required: false |
| 54 | + type: boolean |
| 55 | + default: true |
| 56 | + upload_build_output: |
| 57 | + description: 'Whether to upload the build output directory as an artifact (used when tests are skipped)' |
| 58 | + required: false |
| 59 | + type: boolean |
| 60 | + default: false |
| 61 | + secrets: |
| 62 | + GH_TOKEN: |
| 63 | + description: 'GitHub token for accessing actions/packages' |
| 64 | + required: true |
| 65 | + |
| 66 | +jobs: |
| 67 | + build_test_pipeline: |
| 68 | + runs-on: [self-hosted, Linux, X64] |
| 69 | + permissions: |
| 70 | + contents: read |
| 71 | + packages: write |
| 72 | + attestations: write |
| 73 | + id-token: write |
| 74 | + steps: |
| 75 | + - name: Checkout code |
| 76 | + uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Set up Python ${{ inputs.python_version }} |
| 79 | + uses: actions/setup-python@v5 |
| 80 | + with: |
| 81 | + python-version: ${{ inputs.python_version }} |
| 82 | + |
| 83 | + - name: Build Docker Image (${{ inputs.architecture }} / ${{ inputs.build_config }}) |
| 84 | + uses: microsoft/onnxruntime-github-actions/[email protected] |
| 85 | + id: build_docker_image_step |
| 86 | + with: |
| 87 | + dockerfile: ${{ github.workspace }}/${{ inputs.dockerfile_path }} |
| 88 | + image-name: ghcr.io/microsoft/onnxruntime/${{ inputs.docker_image_repo }} |
| 89 | + build-args: ${{ inputs.docker_build_args }} |
| 90 | + push: true |
| 91 | + azure-container-registry-name: onnxruntimebuildcache |
| 92 | + env: |
| 93 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
| 94 | + |
| 95 | + - name: Export GitHub Actions cache environment variables |
| 96 | + uses: actions/github-script@v7 |
| 97 | + with: |
| 98 | + script: | |
| 99 | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); |
| 100 | + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); |
| 101 | + # ------------- Update Step (CMake Generation) ------------- |
| 102 | + - name: Generate Build Files (CMake) (${{ inputs.architecture }} / ${{ inputs.build_config }}) |
| 103 | + id: update_step |
| 104 | + uses: microsoft/onnxruntime-github-actions/[email protected] |
| 105 | + with: |
| 106 | + docker_image: ${{ steps.build_docker_image_step.outputs.full-image-name }} |
| 107 | + build_config: ${{ inputs.build_config }} |
| 108 | + mode: 'update' |
| 109 | + execution_providers: ${{ inputs.execution_providers }} # Pass down EP list |
| 110 | + extra_build_flags: ${{ inputs.extra_build_flags }} |
| 111 | + python_path_prefix: ${{ inputs.python_path_prefix }} |
| 112 | + |
| 113 | + # ------------- Build Step (Compilation) ------------- |
| 114 | + - name: Build ONNX Runtime (${{ inputs.architecture }} / ${{ inputs.build_config }}) |
| 115 | + id: build_step |
| 116 | + uses: microsoft/onnxruntime-github-actions/[email protected] |
| 117 | + with: |
| 118 | + docker_image: ${{ steps.build_docker_image_step.outputs.full-image-name }} |
| 119 | + build_config: ${{ inputs.build_config }} |
| 120 | + mode: 'build' |
| 121 | + execution_providers: ${{ inputs.execution_providers }} # Pass down EP list |
| 122 | + extra_build_flags: ${{ inputs.extra_build_flags }} |
| 123 | + python_path_prefix: ${{ inputs.python_path_prefix }} |
| 124 | + |
| 125 | + # ------------- Test Step ------------- |
| 126 | + - name: Test ONNX Runtime (${{ inputs.architecture }} / ${{ inputs.build_config }}) |
| 127 | + id: test_step |
| 128 | + if: inputs.run_tests == true |
| 129 | + uses: microsoft/onnxruntime-github-actions/[email protected] |
| 130 | + with: |
| 131 | + docker_image: ${{ steps.build_docker_image_step.outputs.full-image-name }} |
| 132 | + build_config: ${{ inputs.build_config }} |
| 133 | + mode: 'test' |
| 134 | + execution_providers: ${{ inputs.execution_providers }} # Pass down EP list |
| 135 | + extra_build_flags: ${{ inputs.extra_build_flags }} |
| 136 | + python_path_prefix: ${{ inputs.python_path_prefix }} |
| 137 | + |
| 138 | + # ------------- Prepare Artifact Step ------------- |
| 139 | + - name: Prepare Build Output for Upload |
| 140 | + if: inputs.upload_build_output == true |
| 141 | + shell: bash |
| 142 | + run: | |
| 143 | + #!/bin/bash |
| 144 | + set -e -x |
| 145 | + BUILD_DIR="${{ runner.temp }}/${{ inputs.build_config }}" |
| 146 | + if [ ! -d "${BUILD_DIR}" ]; then |
| 147 | + echo "Error: Build directory ${BUILD_DIR} not found. Cannot prepare artifact." |
| 148 | + exit 1 |
| 149 | + fi |
| 150 | + echo "--- Cleaning build directory: ${BUILD_DIR} ---" |
| 151 | + rm -rf "${BUILD_DIR}/onnxruntime" || true |
| 152 | + rm -rf "${BUILD_DIR}/pybind11" || true |
| 153 | + rm -rf "${BUILD_DIR}/vcpkg_installed" || true |
| 154 | + rm -f "${BUILD_DIR}/models" || true |
| 155 | + DEPS_DIR="${BUILD_DIR}/_deps" |
| 156 | + if [ -d "${DEPS_DIR}" ]; then |
| 157 | + echo "Cleaning ${DEPS_DIR}, keeping onnx-src..." |
| 158 | + find "${DEPS_DIR}" -mindepth 1 ! -regex "^${DEPS_DIR}/onnx-src\(/.*\)?$" -delete |
| 159 | + else |
| 160 | + echo "${DEPS_DIR} does not exist, skipping deps cleanup." |
| 161 | + fi |
| 162 | + echo "--- Saving executable permissions ---" |
| 163 | + cd "${BUILD_DIR}" |
| 164 | + find . -executable -type f -printf '%p\n' > perms.txt |
| 165 | + echo "--- Cleanup and permission saving complete for ${BUILD_DIR} ---" |
| 166 | +
|
| 167 | + # ------------- Upload Build Output Step ------------- |
| 168 | + - name: Upload Build Output Artifact |
| 169 | + if: inputs.upload_build_output == true |
| 170 | + uses: actions/upload-artifact@v4 |
| 171 | + with: |
| 172 | + name: build-output-${{ inputs.architecture }}-${{ inputs.build_config }} |
| 173 | + path: ${{ runner.temp }}/${{ inputs.build_config }} |
| 174 | + if-no-files-found: error |
| 175 | + |
| 176 | + # ------------- Upload Log on Build Failure Step ------------- |
| 177 | + - name: Upload VCPKG Manifest Install Log on Update or Build Failure |
| 178 | + if: steps.update_step.outcome == 'failure' || steps.build_step.outcome == 'failure' |
| 179 | + uses: actions/upload-artifact@v4 |
| 180 | + with: |
| 181 | + name: vcpkg-manifest-install-log-${{ inputs.architecture }}-${{ inputs.build_config }} |
| 182 | + path: ${{ runner.temp }}/${{ inputs.build_config }}/${{ inputs.build_config }}/vcpkg-manifest-install.log |
| 183 | + if-no-files-found: ignore |
0 commit comments