|
| 1 | +name: Build Python SDK |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + useWinML: |
| 10 | + required: false |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | + platform: |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + default: 'windows' |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ${{ inputs.platform }}-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + clean: true |
| 30 | + |
| 31 | + - name: Setup Python |
| 32 | + uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: '3.12' |
| 35 | + |
| 36 | + # Clone test-data-shared from Azure DevOps (models for integration tests) |
| 37 | + - name: Checkout test-data-shared from Azure DevOps |
| 38 | + shell: pwsh |
| 39 | + working-directory: ${{ github.workspace }}/.. |
| 40 | + run: | |
| 41 | + $pat = "${{ secrets.AZURE_DEVOPS_PAT }}" |
| 42 | + $encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) |
| 43 | +
|
| 44 | + git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat" |
| 45 | +
|
| 46 | + git lfs install |
| 47 | + git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared |
| 48 | +
|
| 49 | + Write-Host "Clone completed successfully to ${{ github.workspace }}/../test-data-shared" |
| 50 | +
|
| 51 | + - name: Checkout specific commit in test-data-shared |
| 52 | + shell: pwsh |
| 53 | + working-directory: ${{ github.workspace }}/../test-data-shared |
| 54 | + run: | |
| 55 | + git checkout 231f820fe285145b7ea4a449b112c1228ce66a41 |
| 56 | + if ($LASTEXITCODE -ne 0) { |
| 57 | + Write-Error "Git checkout failed." |
| 58 | + exit 1 |
| 59 | + } |
| 60 | +
|
| 61 | + - name: Install build tool |
| 62 | + run: | |
| 63 | + python -m pip install build |
| 64 | +
|
| 65 | + - name: Configure pip for Azure Artifacts |
| 66 | + run: | |
| 67 | + pip config set global.index-url https://pkgs.dev.azure.com/aiinfra/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ |
| 68 | + pip config set global.extra-index-url https://pypi.org/simple/ |
| 69 | + pip config set global.pre true |
| 70 | +
|
| 71 | + - name: Set package version |
| 72 | + working-directory: sdk/python |
| 73 | + run: echo '__version__ = "${{ inputs.version }}"' > src/version.py |
| 74 | + |
| 75 | + - name: Build wheel (Cross-Platform) |
| 76 | + if: ${{ inputs.useWinML == false }} |
| 77 | + working-directory: sdk/python |
| 78 | + run: python -m build --wheel --outdir dist/ |
| 79 | + |
| 80 | + - name: Build wheel (WinML) |
| 81 | + if: ${{ inputs.useWinML == true }} |
| 82 | + working-directory: sdk/python |
| 83 | + run: python -m build --wheel -C winml=true --outdir dist/ |
| 84 | + |
| 85 | + - name: Install built wheel |
| 86 | + working-directory: sdk/python |
| 87 | + shell: pwsh |
| 88 | + run: | |
| 89 | + $wheel = (Get-ChildItem dist/*.whl | Select-Object -First 1).FullName |
| 90 | + pip install $wheel |
| 91 | +
|
| 92 | + - name: Install test dependencies |
| 93 | + run: pip install coverage pytest>=7.0.0 pytest-timeout>=2.1.0 |
| 94 | + |
| 95 | + - name: Run tests |
| 96 | + working-directory: sdk/python |
| 97 | + run: python -m pytest test/ -v |
| 98 | + |
| 99 | + - name: Upload Python packages |
| 100 | + uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: python-sdk-${{ inputs.platform }}${{ inputs.useWinML == true && '-winml' || '' }} |
| 103 | + path: sdk/python/dist/* |
| 104 | + |
| 105 | + - name: Upload flcore logs |
| 106 | + uses: actions/upload-artifact@v4 |
| 107 | + if: always() |
| 108 | + with: |
| 109 | + name: python-sdk-${{ inputs.platform }}${{ inputs.useWinML == true && '-winml' || '' }}-logs |
| 110 | + path: sdk/python/logs/** |
0 commit comments