Skip to content

Commit 0ec6e47

Browse files
authored
fix(ci): separate dotnet unit and integration event selection (#9415)
* fix(ci): separate dotnet unit and integration event selection Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 * fix(ci): select reports from the integration job result Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 * fix(ci): preserve emulators for branch unit checks Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 * fix(ci): remove workflow-specific unit tests Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 * fix(ci): run integration checks for repository pull requests Include reviewer-approved merge groups and keep branch runs independent of an additional ref filter. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 * fix(ci): skip credentialed jobs for Dependabot PR events Keep integration checks enabled for reviewer-approved merge groups. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 * fix(ci): queue shared Foundry hosted integration runs Serialize hosted-agent jobs across PRs and branches without replacing pending checks. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279 --------- Copilot-Session: 8e12a2a7-61c0-487c-b0f4-9cd99c5a6279
1 parent f940e51 commit 0ec6e47

1 file changed

Lines changed: 42 additions & 21 deletions

File tree

‎.github/workflows/dotnet-build-and-test.yml‎

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
filters: |
4848
dotnet:
4949
- 'dotnet/**'
50+
- '.github/workflows/dotnet-build-and-test.yml'
5051
cosmosdb:
5152
- 'dotnet/src/Microsoft.Agents.AI.CosmosNoSql/**'
5253
azurestorage:
@@ -170,23 +171,21 @@ jobs:
170171
popd
171172
rm -rf "$TEMP_DIR"
172173
173-
# Build src+tests only (no samples) for a single TFM and run tests.
174+
# Unit and integration jobs share steps but run with separate permissions and environments.
174175
dotnet-test:
175176
needs: paths-filter
176177
if: needs.paths-filter.outputs.dotnetChanges == 'true'
177178
permissions:
178179
contents: read
179-
id-token: "write"
180180
strategy:
181181
fail-fast: false
182182
matrix:
183183
include:
184-
- { targetFramework: "net10.0", os: "ubuntu-latest", configuration: Release, integration-tests: true, environment: "integration" }
185-
- { targetFramework: "net472", os: "windows-latest", configuration: Release, integration-tests: true, environment: "integration" }
184+
- { targetFramework: "net10.0", os: "ubuntu-latest", configuration: Release, integration-tests: false }
185+
- { targetFramework: "net472", os: "windows-latest", configuration: Release, integration-tests: false }
186186

187187
runs-on: ${{ matrix.os }}
188-
environment: ${{ matrix.environment }}
189-
steps:
188+
steps: &dotnet-test-steps
190189
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
191190
with:
192191
persist-credentials: false
@@ -201,9 +200,9 @@ jobs:
201200
- name: Free runner disk space
202201
uses: ./.github/actions/free-runner-disk-space
203202

204-
# Start Cosmos DB Emulator for all integration tests and only for unit tests when CosmosDB changes happened)
203+
# Branch and merge-queue unit checks always use the emulator; direct PR checks are path-selected.
205204
- name: Start Azure Cosmos DB Emulator
206-
if: ${{ runner.os == 'Windows' && (needs.paths-filter.outputs.cosmosDbChanges == 'true' || (github.event_name != 'pull_request' && matrix.integration-tests)) }}
205+
if: ${{ runner.os == 'Windows' && (needs.paths-filter.outputs.cosmosDbChanges == 'true' || matrix.integration-tests || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group') }}
207206
shell: pwsh
208207
run: |
209208
$ErrorActionPreference = "Stop"
@@ -329,7 +328,7 @@ jobs:
329328
}
330329
331330
- name: Start Azurite Blob service
332-
if: ${{ runner.os == 'Linux' && (needs.paths-filter.outputs.azureStorageChanges == 'true' || (github.event_name != 'pull_request' && matrix.integration-tests)) }}
331+
if: ${{ runner.os == 'Linux' && (needs.paths-filter.outputs.azureStorageChanges == 'true' || matrix.integration-tests || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group') }}
333332
shell: bash
334333
run: |
335334
docker run --detach --rm \
@@ -386,6 +385,7 @@ jobs:
386385
-OutputPath dotnet/filtered-integration.slnx
387386
388387
- name: Run Unit Tests
388+
if: ${{ !matrix.integration-tests }}
389389
shell: pwsh
390390
working-directory: dotnet
391391
run: |
@@ -417,7 +417,7 @@ jobs:
417417
run: echo "github.event_name:${{ github.event_name }} matrix.integration-tests:${{ matrix.integration-tests }} github.event.action:${{ github.event.action }} github.event.pull_request.merged:${{ github.event.pull_request.merged }}"
418418

419419
- name: Azure CLI Login
420-
if: github.event_name != 'pull_request' && matrix.integration-tests
420+
if: matrix.integration-tests
421421
uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0
422422
with:
423423
client-id: ${{ secrets.AZURE_CLIENT_ID }}
@@ -427,7 +427,7 @@ jobs:
427427
- name: Run Integration Tests
428428
shell: pwsh
429429
working-directory: dotnet
430-
if: github.event_name != 'pull_request' && matrix.integration-tests
430+
if: matrix.integration-tests
431431
run: |
432432
dotnet test --solution ./filtered-integration.slnx `
433433
-f ${{ matrix.targetFramework }} `
@@ -465,27 +465,27 @@ jobs:
465465

466466
# Generate test reports and check coverage
467467
- name: Generate test reports
468-
if: matrix.targetFramework == env.COVERAGE_FRAMEWORK
468+
if: ${{ !matrix.integration-tests && matrix.targetFramework == env.COVERAGE_FRAMEWORK }}
469469
uses: danielpalme/ReportGenerator-GitHub-Action@d3ebf1f760f7d8ab92cc44d9bcfee7ad73722a31 # 5.5.11
470470
with:
471471
reports: "./TestResults/Coverage/**/*.cobertura.xml"
472472
targetdir: "./TestResults/Reports"
473473
reporttypes: "HtmlInline;JsonSummary;Cobertura"
474474

475475
- name: Upload coverage report artifact
476-
if: matrix.targetFramework == env.COVERAGE_FRAMEWORK
476+
if: ${{ !matrix.integration-tests && matrix.targetFramework == env.COVERAGE_FRAMEWORK }}
477477
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
478478
with:
479479
name: CoverageReport-${{ matrix.os }}-${{ matrix.targetFramework }}-${{ matrix.configuration }} # Artifact name
480480
path: ./TestResults/Reports # Directory containing files to upload
481481

482482
- name: Check coverage
483-
if: matrix.targetFramework == env.COVERAGE_FRAMEWORK
483+
if: ${{ !matrix.integration-tests && matrix.targetFramework == env.COVERAGE_FRAMEWORK }}
484484
shell: pwsh
485485
run: ./dotnet/eng/scripts/dotnet-check-coverage.ps1 -JsonReportPath "TestResults/Reports/Summary.json" -CoverageThreshold $env:COVERAGE_THRESHOLD
486486

487487
- name: Upload integration test results
488-
if: always() && github.event_name != 'pull_request' && matrix.integration-tests
488+
if: always() && matrix.integration-tests
489489
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
490490
with:
491491
name: dotnet-test-results-${{ matrix.targetFramework }}-${{ matrix.os }}
@@ -494,6 +494,23 @@ jobs:
494494
IntegrationTestResults/**/*.junit.xml
495495
if-no-files-found: ignore
496496

497+
# Repository PRs and reviewer-approved merge groups can run integration checks before merging.
498+
dotnet-integration-test:
499+
needs: paths-filter
500+
if: needs.paths-filter.outputs.dotnetChanges == 'true' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'))
501+
permissions:
502+
contents: read
503+
id-token: "write"
504+
strategy:
505+
fail-fast: false
506+
matrix:
507+
include:
508+
- { targetFramework: "net10.0", os: "ubuntu-latest", configuration: Release, integration-tests: true }
509+
- { targetFramework: "net472", os: "windows-latest", configuration: Release, integration-tests: true }
510+
runs-on: ${{ matrix.os }}
511+
environment: integration
512+
steps: *dotnet-test-steps
513+
497514
dotnet-upload-coverage:
498515
needs: [paths-filter, dotnet-test]
499516
if: needs.paths-filter.outputs.dotnetChanges == 'true' && github.event_name != 'merge_group' && ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') || (github.event_name != 'pull_request' && github.ref_name == github.event.repository.default_branch))
@@ -525,12 +542,17 @@ jobs:
525542
# gated on paths-filter.outputs.foundryHostingChanges so unrelated edits skip the work.
526543
dotnet-foundry-hosted-it:
527544
needs: paths-filter
528-
if: github.event_name != 'pull_request' && needs.paths-filter.outputs.foundryHostingChanges == 'true'
545+
if: needs.paths-filter.outputs.foundryHostingChanges == 'true' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'))
529546
permissions:
530547
contents: read
531548
id-token: "write"
532549
runs-on: ubuntu-latest
533550
environment: integration
551+
# Scenario agents share @latest endpoints across PRs and branch runs.
552+
concurrency:
553+
group: dotnet-foundry-hosted-integration
554+
cancel-in-progress: false
555+
queue: max
534556
env:
535557
configuration: Release
536558
steps:
@@ -611,7 +633,7 @@ jobs:
611633
dotnet-build-and-test-check:
612634
if: always()
613635
runs-on: ubuntu-latest
614-
needs: [dotnet-build, dotnet-test, dotnet-foundry-hosted-it]
636+
needs: [dotnet-build, dotnet-test, dotnet-integration-test, dotnet-foundry-hosted-it]
615637
steps:
616638
- name: Get Date
617639
shell: bash
@@ -655,10 +677,9 @@ jobs:
655677
name: Integration Test Report
656678
if: >
657679
always() &&
658-
github.event_name != 'pull_request' &&
659-
(contains(join(needs.*.result, ','), 'success') ||
660-
contains(join(needs.*.result, ','), 'failure'))
661-
needs: [dotnet-test]
680+
(needs.dotnet-integration-test.result == 'success' ||
681+
needs.dotnet-integration-test.result == 'failure')
682+
needs: [dotnet-integration-test]
662683
runs-on: ubuntu-latest
663684
defaults:
664685
run:

0 commit comments

Comments
 (0)