|
| 1 | +name: Samples Integration Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'samples/**' |
| 7 | + - '.github/workflows/samples-integration-test.yml' |
| 8 | + push: |
| 9 | + paths: |
| 10 | + - 'samples/**' |
| 11 | + - '.github/workflows/samples-integration-test.yml' |
| 12 | + branches: |
| 13 | + - main |
| 14 | + workflow_dispatch: |
| 15 | + schedule: |
| 16 | + - cron: '0 6 * * 1' # Weekly Monday 6am UTC |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +jobs: |
| 22 | + # ── Python Samples ────────────────────────────────────────────────── |
| 23 | + python-samples: |
| 24 | + runs-on: ${{ matrix.platform }}-latest |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + platform: [windows, macos] |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + clean: true |
| 35 | + |
| 36 | + - name: Setup Python |
| 37 | + uses: actions/setup-python@v5 |
| 38 | + with: |
| 39 | + python-version: '3.12' |
| 40 | + |
| 41 | + - name: Checkout test-data-shared from Azure DevOps |
| 42 | + shell: pwsh |
| 43 | + working-directory: ${{ github.workspace }}/.. |
| 44 | + run: | |
| 45 | + $pat = "${{ secrets.AZURE_DEVOPS_PAT }}" |
| 46 | + $encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) |
| 47 | + git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat" |
| 48 | + git lfs install |
| 49 | + git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared |
| 50 | +
|
| 51 | + - name: Configure pip for Azure Artifacts |
| 52 | + run: | |
| 53 | + pip config set global.index-url https://pkgs.dev.azure.com/aiinfra/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ |
| 54 | + pip config set global.extra-index-url https://pypi.org/simple/ |
| 55 | + pip config set global.pre true |
| 56 | +
|
| 57 | + - name: Build and install SDK from source |
| 58 | + working-directory: sdk/python |
| 59 | + shell: pwsh |
| 60 | + run: | |
| 61 | + python -m pip install build |
| 62 | + echo '__version__ = "0.0.0-dev"' > src/version.py |
| 63 | + python -m build --wheel --outdir dist/ |
| 64 | + $wheel = (Get-ChildItem dist/*.whl | Select-Object -First 1).FullName |
| 65 | + pip install $wheel |
| 66 | +
|
| 67 | + - name: Install sample dependencies |
| 68 | + shell: pwsh |
| 69 | + run: | |
| 70 | + Get-ChildItem samples/python/*/requirements.txt -ErrorAction SilentlyContinue | ForEach-Object { |
| 71 | + Write-Host "Installing dependencies for $($_.Directory.Name)..." |
| 72 | + pip install -r $_.FullName |
| 73 | + } |
| 74 | +
|
| 75 | + - name: Run Python samples |
| 76 | + shell: pwsh |
| 77 | + run: | |
| 78 | + $failed = @() |
| 79 | + $samples = Get-ChildItem samples/python/*/src/app.py -ErrorAction SilentlyContinue |
| 80 | + foreach ($sample in $samples) { |
| 81 | + $name = $sample.Directory.Parent.Name |
| 82 | + Write-Host "`n=== Running: $name ===" |
| 83 | + try { |
| 84 | + $proc = Start-Process python -ArgumentList $sample.FullName -NoNewWindow -PassThru -Wait -RedirectStandardOutput "stdout.txt" -RedirectStandardError "stderr.txt" |
| 85 | + if ($proc.ExitCode -ne 0) { |
| 86 | + Write-Host "FAILED (exit code $($proc.ExitCode))" |
| 87 | + Get-Content stderr.txt | Write-Host |
| 88 | + $failed += $name |
| 89 | + } else { |
| 90 | + Write-Host "PASSED" |
| 91 | + } |
| 92 | + } catch { |
| 93 | + Write-Host "ERROR: $_" |
| 94 | + $failed += $name |
| 95 | + } |
| 96 | + } |
| 97 | + if ($failed.Count -gt 0) { |
| 98 | + Write-Error "Failed samples: $($failed -join ', ')" |
| 99 | + exit 1 |
| 100 | + } |
| 101 | +
|
| 102 | + - name: Upload logs |
| 103 | + uses: actions/upload-artifact@v4 |
| 104 | + if: always() |
| 105 | + with: |
| 106 | + name: python-samples-${{ matrix.platform }}-logs |
| 107 | + path: samples/python/**/logs/** |
| 108 | + |
| 109 | + # ── JavaScript Samples ────────────────────────────────────────────── |
| 110 | + js-samples: |
| 111 | + runs-on: ${{ matrix.platform }}-latest |
| 112 | + strategy: |
| 113 | + fail-fast: false |
| 114 | + matrix: |
| 115 | + platform: [windows, macos] |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Checkout repository |
| 119 | + uses: actions/checkout@v4 |
| 120 | + with: |
| 121 | + clean: true |
| 122 | + |
| 123 | + - name: Setup Node.js |
| 124 | + uses: actions/setup-node@v4 |
| 125 | + with: |
| 126 | + node-version: '20.x' |
| 127 | + |
| 128 | + - name: Setup .NET SDK for NuGet authentication |
| 129 | + uses: actions/setup-dotnet@v5 |
| 130 | + with: |
| 131 | + dotnet-version: '10.0.x' |
| 132 | + |
| 133 | + - name: Checkout test-data-shared from Azure DevOps |
| 134 | + shell: pwsh |
| 135 | + working-directory: ${{ github.workspace }}/.. |
| 136 | + run: | |
| 137 | + $pat = "${{ secrets.AZURE_DEVOPS_PAT }}" |
| 138 | + $encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) |
| 139 | + git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat" |
| 140 | + git lfs install |
| 141 | + git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared |
| 142 | +
|
| 143 | + - name: Build SDK from source |
| 144 | + working-directory: sdk/js |
| 145 | + run: | |
| 146 | + npm install |
| 147 | + npm run build |
| 148 | +
|
| 149 | + - name: Run JS samples |
| 150 | + shell: pwsh |
| 151 | + run: | |
| 152 | + $failed = @() |
| 153 | + $samples = Get-ChildItem samples/js/*/app.js -ErrorAction SilentlyContinue |
| 154 | + foreach ($sample in $samples) { |
| 155 | + $name = $sample.Directory.Name |
| 156 | + Write-Host "`n=== Running: $name ===" |
| 157 | + # Install dependencies if package.json exists |
| 158 | + $pkgJson = Join-Path $sample.DirectoryName "package.json" |
| 159 | + if (Test-Path $pkgJson) { |
| 160 | + Push-Location $sample.DirectoryName |
| 161 | + npm install |
| 162 | + Pop-Location |
| 163 | + } |
| 164 | + try { |
| 165 | + $proc = Start-Process node -ArgumentList $sample.FullName -NoNewWindow -PassThru -Wait -RedirectStandardOutput "stdout.txt" -RedirectStandardError "stderr.txt" |
| 166 | + if ($proc.ExitCode -ne 0) { |
| 167 | + Write-Host "FAILED (exit code $($proc.ExitCode))" |
| 168 | + Get-Content stderr.txt | Write-Host |
| 169 | + $failed += $name |
| 170 | + } else { |
| 171 | + Write-Host "PASSED" |
| 172 | + } |
| 173 | + } catch { |
| 174 | + Write-Host "ERROR: $_" |
| 175 | + $failed += $name |
| 176 | + } |
| 177 | + } |
| 178 | + if ($failed.Count -gt 0) { |
| 179 | + Write-Error "Failed samples: $($failed -join ', ')" |
| 180 | + exit 1 |
| 181 | + } |
| 182 | +
|
| 183 | + - name: Upload logs |
| 184 | + uses: actions/upload-artifact@v4 |
| 185 | + if: always() |
| 186 | + with: |
| 187 | + name: js-samples-${{ matrix.platform }}-logs |
| 188 | + path: samples/js/**/logs/** |
| 189 | + |
| 190 | + # ── C# Samples ───────────────────────────────────────────────────── |
| 191 | + cs-samples: |
| 192 | + runs-on: ${{ matrix.platform }}-latest |
| 193 | + strategy: |
| 194 | + fail-fast: false |
| 195 | + matrix: |
| 196 | + platform: [windows, macos] |
| 197 | + |
| 198 | + steps: |
| 199 | + - name: Checkout repository |
| 200 | + uses: actions/checkout@v4 |
| 201 | + with: |
| 202 | + clean: true |
| 203 | + |
| 204 | + - name: Setup .NET 10 SDK |
| 205 | + uses: actions/setup-dotnet@v5 |
| 206 | + with: |
| 207 | + dotnet-version: '10.0.x' |
| 208 | + |
| 209 | + - name: Checkout test-data-shared from Azure DevOps |
| 210 | + shell: pwsh |
| 211 | + working-directory: ${{ github.workspace }}/.. |
| 212 | + run: | |
| 213 | + $pat = "${{ secrets.AZURE_DEVOPS_PAT }}" |
| 214 | + $encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) |
| 215 | + git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat" |
| 216 | + git lfs install |
| 217 | + git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared |
| 218 | +
|
| 219 | + - name: Build C# samples |
| 220 | + shell: pwsh |
| 221 | + run: | |
| 222 | + $failed = @() |
| 223 | + $projects = Get-ChildItem samples/cs -Recurse -Filter "*.csproj" |
| 224 | + foreach ($proj in $projects) { |
| 225 | + $name = $proj.BaseName |
| 226 | + Write-Host "`n=== Building: $name ===" |
| 227 | + dotnet build $proj.FullName --configuration Debug |
| 228 | + if ($LASTEXITCODE -ne 0) { |
| 229 | + Write-Host "BUILD FAILED: $name" |
| 230 | + $failed += $name |
| 231 | + } else { |
| 232 | + Write-Host "BUILD PASSED: $name" |
| 233 | + } |
| 234 | + } |
| 235 | + if ($failed.Count -gt 0) { |
| 236 | + Write-Error "Failed builds: $($failed -join ', ')" |
| 237 | + exit 1 |
| 238 | + } |
| 239 | +
|
| 240 | + - name: Run C# samples |
| 241 | + shell: pwsh |
| 242 | + run: | |
| 243 | + $failed = @() |
| 244 | + $projects = Get-ChildItem samples/cs -Recurse -Filter "*.csproj" |
| 245 | + foreach ($proj in $projects) { |
| 246 | + $name = $proj.BaseName |
| 247 | + Write-Host "`n=== Running: $name ===" |
| 248 | + try { |
| 249 | + dotnet run --project $proj.FullName --no-build --configuration Debug 2>&1 |
| 250 | + if ($LASTEXITCODE -ne 0) { |
| 251 | + Write-Host "FAILED: $name (exit code $LASTEXITCODE)" |
| 252 | + $failed += $name |
| 253 | + } else { |
| 254 | + Write-Host "PASSED: $name" |
| 255 | + } |
| 256 | + } catch { |
| 257 | + Write-Host "ERROR: $_" |
| 258 | + $failed += $name |
| 259 | + } |
| 260 | + } |
| 261 | + if ($failed.Count -gt 0) { |
| 262 | + Write-Error "Failed samples: $($failed -join ', ')" |
| 263 | + exit 1 |
| 264 | + } |
| 265 | +
|
| 266 | + - name: Upload logs |
| 267 | + uses: actions/upload-artifact@v4 |
| 268 | + if: always() |
| 269 | + with: |
| 270 | + name: cs-samples-${{ matrix.platform }}-logs |
| 271 | + path: samples/cs/**/logs/** |
| 272 | + |
| 273 | + # ── Rust Samples ──────────────────────────────────────────────────── |
| 274 | + rust-samples: |
| 275 | + runs-on: ${{ matrix.platform }}-latest |
| 276 | + strategy: |
| 277 | + fail-fast: false |
| 278 | + matrix: |
| 279 | + platform: [windows, macos] |
| 280 | + |
| 281 | + steps: |
| 282 | + - name: Checkout repository |
| 283 | + uses: actions/checkout@v4 |
| 284 | + with: |
| 285 | + clean: true |
| 286 | + |
| 287 | + - name: Install Rust toolchain |
| 288 | + uses: dtolnay/rust-toolchain@stable |
| 289 | + with: |
| 290 | + components: clippy |
| 291 | + |
| 292 | + - name: Cache cargo dependencies |
| 293 | + uses: Swatinem/rust-cache@v2 |
| 294 | + with: |
| 295 | + workspaces: samples/rust -> target |
| 296 | + |
| 297 | + - name: Use crates.io directly |
| 298 | + shell: pwsh |
| 299 | + working-directory: sdk/rust |
| 300 | + run: | |
| 301 | + if (Test-Path .cargo/config.toml) { |
| 302 | + Remove-Item .cargo/config.toml |
| 303 | + Write-Host "Removed .cargo/config.toml crates-io redirect" |
| 304 | + } |
| 305 | +
|
| 306 | + - name: Checkout test-data-shared from Azure DevOps |
| 307 | + shell: pwsh |
| 308 | + working-directory: ${{ github.workspace }}/.. |
| 309 | + run: | |
| 310 | + $pat = "${{ secrets.AZURE_DEVOPS_PAT }}" |
| 311 | + $encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")) |
| 312 | + git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat" |
| 313 | + git lfs install |
| 314 | + git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared |
| 315 | +
|
| 316 | + - name: Build Rust samples |
| 317 | + shell: pwsh |
| 318 | + run: | |
| 319 | + $failed = @() |
| 320 | + $manifests = Get-ChildItem samples/rust/*/Cargo.toml |
| 321 | + foreach ($manifest in $manifests) { |
| 322 | + $name = $manifest.Directory.Name |
| 323 | + Write-Host "`n=== Building: $name ===" |
| 324 | + cargo build --manifest-path $manifest.FullName |
| 325 | + if ($LASTEXITCODE -ne 0) { |
| 326 | + Write-Host "BUILD FAILED: $name" |
| 327 | + $failed += $name |
| 328 | + } else { |
| 329 | + Write-Host "BUILD PASSED: $name" |
| 330 | + } |
| 331 | + } |
| 332 | + if ($failed.Count -gt 0) { |
| 333 | + Write-Error "Failed builds: $($failed -join ', ')" |
| 334 | + exit 1 |
| 335 | + } |
| 336 | +
|
| 337 | + - name: Upload logs |
| 338 | + uses: actions/upload-artifact@v4 |
| 339 | + if: always() |
| 340 | + with: |
| 341 | + name: rust-samples-${{ matrix.platform }}-logs |
| 342 | + path: samples/rust/**/logs/** |
0 commit comments