sdk-tests.yml
1 # Copyright 2025 Alibaba Group Holding Ltd. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 name: SDK Tests 16 17 on: 18 pull_request: 19 branches: [main] 20 paths: 21 - "cli/**" 22 - "sdks/**" 23 - "specs/**" 24 push: 25 branches: [main] 26 paths: 27 - "cli/**" 28 - "sdks/**" 29 - "specs/**" 30 31 permissions: 32 contents: read 33 34 concurrency: 35 group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 36 cancel-in-progress: true 37 38 jobs: 39 cli-quality: 40 name: CLI Quality 41 runs-on: ubuntu-latest 42 steps: 43 - name: Checkout code 44 uses: actions/checkout@v6 45 46 - name: Set up Python 47 uses: actions/setup-python@v6 48 with: 49 python-version: "3.11" 50 51 - name: Install uv 52 uses: astral-sh/setup-uv@v7 53 with: 54 version: "latest" 55 56 - name: Install dependencies 57 working-directory: cli 58 run: | 59 uv sync 60 61 - name: Run ruff 62 working-directory: cli 63 run: | 64 uv run ruff check 65 66 - name: Run pyright 67 working-directory: cli 68 run: | 69 uv run pyright 70 71 cli-tests: 72 name: CLI Tests 73 runs-on: ubuntu-latest 74 steps: 75 - name: Checkout code 76 uses: actions/checkout@v6 77 78 - name: Set up Python 79 uses: actions/setup-python@v6 80 with: 81 python-version: "3.11" 82 83 - name: Install uv 84 uses: astral-sh/setup-uv@v7 85 with: 86 version: "latest" 87 88 - name: Install dependencies 89 working-directory: cli 90 run: | 91 uv sync 92 93 - name: Run tests 94 working-directory: cli 95 run: | 96 mkdir -p reports 97 uv run pytest tests/ -v --junitxml=reports/junit.xml 98 99 - name: Upload CLI reports 100 if: always() 101 uses: actions/upload-artifact@v4 102 with: 103 name: cli-reports 104 path: | 105 cli/reports/** 106 107 python-sdk-quality: 108 name: Python SDK Quality (${{ matrix.package_name }}) 109 runs-on: ubuntu-latest 110 strategy: 111 fail-fast: false 112 matrix: 113 include: 114 - package_name: sandbox 115 package_dir: sdks/sandbox/python 116 - package_name: code-interpreter 117 package_dir: sdks/code-interpreter/python 118 steps: 119 - name: Checkout code 120 uses: actions/checkout@v6 121 122 - name: Set up Python 123 uses: actions/setup-python@v6 124 with: 125 python-version: "3.11" 126 127 - name: Install uv 128 uses: astral-sh/setup-uv@v7 129 with: 130 version: "latest" 131 132 - name: Install dependencies 133 working-directory: ${{ matrix.package_dir }} 134 run: | 135 uv sync 136 137 - name: Generate API 138 if: matrix.package_name == 'sandbox' 139 working-directory: sdks/sandbox/python 140 run: | 141 uv run python scripts/generate_api.py 142 143 - name: Run ruff 144 working-directory: ${{ matrix.package_dir }} 145 run: | 146 uv run ruff check 147 148 - name: Run pyright 149 working-directory: ${{ matrix.package_dir }} 150 run: | 151 uv run pyright 152 153 python-sdk-tests: 154 name: Python SDK Tests (${{ matrix.package_name }}) 155 runs-on: ubuntu-latest 156 strategy: 157 fail-fast: false 158 matrix: 159 include: 160 - package_name: sandbox 161 package_dir: sdks/sandbox/python 162 coverage_target: src/opensandbox 163 - package_name: code-interpreter 164 package_dir: sdks/code-interpreter/python 165 coverage_target: src/code_interpreter 166 steps: 167 - name: Checkout code 168 uses: actions/checkout@v6 169 170 - name: Set up Python 171 uses: actions/setup-python@v6 172 with: 173 python-version: "3.11" 174 175 - name: Install uv 176 uses: astral-sh/setup-uv@v7 177 with: 178 version: "latest" 179 180 - name: Install dependencies 181 working-directory: ${{ matrix.package_dir }} 182 run: | 183 uv sync 184 185 - name: Generate API 186 if: matrix.package_name == 'sandbox' 187 working-directory: sdks/sandbox/python 188 run: | 189 uv run python scripts/generate_api.py 190 191 - name: Run tests 192 working-directory: ${{ matrix.package_dir }} 193 run: | 194 mkdir -p reports 195 uv run pytest tests/ -v \ 196 --junitxml=reports/junit.xml \ 197 --cov=${{ matrix.coverage_target }} \ 198 --cov-report=term-missing \ 199 --cov-report=xml:reports/coverage.xml 200 201 - name: Upload Python reports 202 if: always() 203 uses: actions/upload-artifact@v4 204 with: 205 name: python-${{ matrix.package_name }}-reports 206 path: | 207 ${{ matrix.package_dir }}/reports/** 208 209 javascript-sdk-quality: 210 name: JavaScript SDK Quality And Tests (${{ matrix.package_name }}) 211 runs-on: ubuntu-latest 212 strategy: 213 fail-fast: false 214 matrix: 215 include: 216 - package_name: sandbox 217 package_dir: sdks/sandbox/javascript 218 - package_name: code-interpreter 219 package_dir: sdks/code-interpreter/javascript 220 steps: 221 - name: Checkout code 222 uses: actions/checkout@v6 223 224 - name: Set up pnpm 225 uses: pnpm/action-setup@v4 226 with: 227 version: 9.15.0 228 run_install: false 229 230 - name: Set up Node.js 231 uses: actions/setup-node@v4 232 with: 233 node-version: "20" 234 cache: "pnpm" 235 cache-dependency-path: sdks/pnpm-lock.yaml 236 237 - name: Install dependencies 238 working-directory: sdks 239 run: | 240 pnpm install --frozen-lockfile 241 242 - name: Build JavaScript SDK dependencies 243 working-directory: sdks 244 run: | 245 pnpm run build:js 246 247 - name: Run eslint 248 working-directory: ${{ matrix.package_dir }} 249 run: | 250 pnpm run lint 251 252 - name: Run TypeScript typecheck 253 working-directory: ${{ matrix.package_dir }} 254 run: | 255 pnpm run typecheck 256 257 - name: Run tests 258 working-directory: ${{ matrix.package_dir }} 259 run: | 260 mkdir -p reports 261 node --test tests/*.test.mjs > reports/test-output.txt 262 263 - name: Upload JavaScript reports 264 if: always() 265 uses: actions/upload-artifact@v4 266 with: 267 name: javascript-${{ matrix.package_name }}-reports 268 path: | 269 ${{ matrix.package_dir }}/reports/** 270 271 kotlin-sdk-quality: 272 name: Kotlin SDK Quality And Tests (${{ matrix.package_name }}) 273 runs-on: ubuntu-latest 274 strategy: 275 fail-fast: false 276 matrix: 277 include: 278 - package_name: sandbox 279 package_dir: sdks/sandbox/kotlin 280 test_task: :sandbox:test 281 gradle_args: "" 282 - package_name: code-interpreter 283 package_dir: sdks/code-interpreter/kotlin 284 test_task: :code-interpreter:test 285 gradle_args: "-PuseMavenLocal" 286 steps: 287 - name: Checkout code 288 uses: actions/checkout@v6 289 290 - name: Set up Java 291 uses: actions/setup-java@v5 292 with: 293 distribution: temurin 294 java-version: "17" 295 296 - name: Set up Gradle 297 uses: gradle/actions/setup-gradle@v5 298 299 - name: Publish sandbox SDK to Maven local 300 if: matrix.package_name == 'code-interpreter' 301 working-directory: sdks/sandbox/kotlin 302 run: | 303 ./gradlew publishToMavenLocal 304 305 - name: Run quality checks and tests 306 working-directory: ${{ matrix.package_dir }} 307 run: | 308 ./gradlew spotlessCheck ${{ matrix.test_task }} ${{ matrix.gradle_args }} 309 310 - name: Upload Kotlin reports 311 if: always() 312 uses: actions/upload-artifact@v4 313 with: 314 name: kotlin-${{ matrix.package_name }}-reports 315 path: | 316 ${{ matrix.package_dir }}/**/build/test-results/test/** 317 ${{ matrix.package_dir }}/**/build/reports/tests/test/** 318 319 csharp-sdk-quality: 320 name: C# SDK Quality And Tests (${{ matrix.package_name }}) 321 runs-on: ubuntu-latest 322 strategy: 323 fail-fast: false 324 matrix: 325 include: 326 - package_name: sandbox 327 package_dir: sdks/sandbox/csharp 328 solution: OpenSandbox.sln 329 test_project: tests/OpenSandbox.Tests/OpenSandbox.Tests.csproj 330 - package_name: code-interpreter 331 package_dir: sdks/code-interpreter/csharp 332 solution: OpenSandbox.CodeInterpreter.sln 333 test_project: tests/OpenSandbox.CodeInterpreter.Tests/OpenSandbox.CodeInterpreter.Tests.csproj 334 steps: 335 - name: Checkout code 336 uses: actions/checkout@v6 337 338 - name: Set up .NET 10 339 uses: actions/setup-dotnet@v5 340 with: 341 dotnet-version: "10.0.x" 342 343 - name: Build with analyzers 344 working-directory: ${{ matrix.package_dir }} 345 run: | 346 dotnet build ${{ matrix.solution }} --configuration Release /warnaserror 347 348 - name: Run tests with reports 349 working-directory: ${{ matrix.package_dir }} 350 run: | 351 dotnet test ${{ matrix.test_project }} \ 352 --configuration Release \ 353 --no-build \ 354 --logger "trx;LogFileName=test-results.trx" \ 355 --results-directory TestResults \ 356 --collect:"XPlat Code Coverage" 357 358 - name: Upload C# reports 359 if: always() 360 uses: actions/upload-artifact@v4 361 with: 362 name: csharp-${{ matrix.package_name }}-reports 363 path: | 364 ${{ matrix.package_dir }}/TestResults/** 365 366 go-sdk-quality: 367 name: Go SDK Quality And Tests 368 runs-on: ubuntu-latest 369 steps: 370 - name: Checkout code 371 uses: actions/checkout@v6 372 373 - name: Set up Go 374 uses: actions/setup-go@v6 375 with: 376 go-version: "1.20" 377 378 - name: Run go vet 379 working-directory: sdks/sandbox/go 380 run: | 381 go vet ./... 382 383 - name: Run tests with race detector 384 working-directory: sdks/sandbox/go 385 run: | 386 mkdir -p reports 387 go test -v -race -coverprofile=reports/coverage.out ./... 388 go tool cover -func=reports/coverage.out 389 390 - name: Upload Go reports 391 if: always() 392 uses: actions/upload-artifact@v4 393 with: 394 name: go-sdk-reports 395 path: | 396 sdks/sandbox/go/reports/**