Skip to content

Commit 1e76304

Browse files
radicalCopilot
andauthoredMar 25, 2025··
[tests] PR validation speed ups (#8227)
Improves `Tests` workflow time from ~14 mins to ~10 mins. ### Build packages once on Linux, and use with tests This reduces the run time by avoiding package builds on Windows, and reduces total compute consumption. ### Merge github action enumerate-template-tests into enumerate-tests These two tasks were called sequentially, and each would checkout-code+install-dotnet before doing any work. By combining the tasks, we get an improved run time. ### Always use system dotnet for EndToEnd tests, thus avoiding the need for test sdks to be installed ### Avoid building test projects when TestNoBuild!=true Saves on build unnecessary build times. * address review feedback from @ joperezr Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b0be284 commit 1e76304

File tree

8 files changed

+126
-79
lines changed

8 files changed

+126
-79
lines changed
 

‎.github/actions/enumerate-template-tests/action.yml

-51
This file was deleted.

‎.github/actions/enumerate-tests/action.yml

+55-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
name: 'Enumerate test projects'
22
description: 'Enumerate list of test projects'
3+
inputs:
4+
includeIntegrations:
5+
required: false
6+
type: boolean
7+
default: false
8+
includeTemplates:
9+
required: false
10+
type: boolean
11+
default: false
12+
313
outputs:
414
integrations_tests_matrix:
5-
description: tests matrix
6-
value: ${{ steps.generate_test_matrix.outputs.integrations_tests_matrix }}
15+
description: Integration tests matrix
16+
value: ${{ steps.generate_integrations_matrix.outputs.integrations_tests_matrix }}
17+
templates_tests_matrix:
18+
description: Templates tests matrix
19+
value: ${{ steps.generate_templates_matrix.outputs.templates_tests_matrix }}
720
runs:
821
using: "composite"
922
steps:
@@ -16,7 +29,8 @@ runs:
1629
dotnet-version: |
1730
9.x
1831
19-
- name: Get list of tests
32+
- name: Get list of integration tests
33+
if: ${{ inputs.includeIntegrations }}
2034
env:
2135
CI: false
2236
shell: pwsh
@@ -25,8 +39,23 @@ runs:
2539
/p:TestsListOutputPath=${{ github.workspace }}/artifacts/TestsForGithubActions.list
2640
/p:ContinuousIntegrationBuild=true
2741
42+
- name: Generate list of template tests
43+
if: ${{ inputs.includeTemplates }}
44+
env:
45+
CI: false
46+
shell: pwsh
47+
run: >
48+
dotnet build ${{ github.workspace }}/tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj
49+
"/t:Build;ExtractTestClassNames"
50+
/bl:${{ github.workspace }}/artifacts/log/Debug/BuildTemplatesTests.binlog
51+
-p:ExtractTestClassNamesForHelix=true
52+
-p:ArchiveTests=true
53+
-p:ExtractTestClassNamesPrefix=Aspire.Templates.Tests
54+
-p:InstallBrowsersForPlaywright=false
55+
2856
- name: Generate tests matrix
29-
id: generate_test_matrix
57+
id: generate_integrations_matrix
58+
if: ${{ inputs.includeIntegrations }}
3059
shell: pwsh
3160
env:
3261
CI: false
@@ -39,3 +68,25 @@ runs:
3968
$jsonString = ConvertTo-Json $jsonObject -Compress
4069
"integrations_tests_matrix=$jsonString"
4170
"integrations_tests_matrix=$jsonString" | Out-File -FilePath $env:GITHUB_OUTPUT
71+
72+
- name: Generate tests matrix
73+
id: generate_templates_matrix
74+
if: ${{ inputs.includeTemplates }}
75+
shell: pwsh
76+
env:
77+
CI: false
78+
run: |
79+
$inputFilePath = "${{ github.workspace }}/artifacts/helix/templates-tests/Aspire.Templates.Tests.tests.list"
80+
$lines = Get-Content $inputFilePath
81+
82+
$prefix = "Aspire.Templates.Tests."
83+
$lines = Get-Content $inputFilePath | ForEach-Object {
84+
$_ -replace "^$prefix", ""
85+
}
86+
87+
$jsonObject = @{
88+
"shortname" = $lines | Sort-Object
89+
}
90+
$jsonString = ConvertTo-Json $jsonObject -Compress
91+
"templates_tests_matrix=$jsonString"
92+
"templates_tests_matrix=$jsonString" | Out-File -FilePath $env:GITHUB_OUTPUT

‎.github/workflows/run-tests.yml

+20-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ on:
2424
extraTestArgs:
2525
required: false
2626
type: string
27+
# Triggers downloading the built nugets, and running the tests
28+
# from the archive outside the repo
2729
requiresNugets:
2830
required: false
2931
type: boolean
3032
default: false
33+
# Installs the sdks used for test via tests/workloads.proj
34+
# Useful for tests that can't use system dotnet
35+
requiresTestSdk:
36+
required: false
37+
type: boolean
38+
default: false
3139
os:
3240
required: false
3341
type: string
@@ -83,14 +91,21 @@ jobs:
8391
if: inputs.os == 'ubuntu-latest'
8492
run: docker info
8593

86-
- name: Build with packages
94+
- name: Download built nugets
8795
if: ${{ inputs.requiresNugets }}
88-
env:
89-
CI: false
90-
run: ${{ env.BUILD_SCRIPT }} -restore -build -ci -pack -testnobuild /bl
96+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
97+
with:
98+
pattern: built-nugets
99+
path: ${{ github.workspace }}/artifacts/packages
91100

92-
- name: Install sdk for nuget based testing
101+
- name: Copy nugets to the correct location
93102
if: ${{ inputs.requiresNugets }}
103+
shell: pwsh
104+
run:
105+
Move-Item -Path "${{ github.workspace }}/artifacts/packages/built-nugets/Debug" -Destination "${{ github.workspace }}/artifacts/packages"
106+
107+
- name: Install sdk for nuget based testing
108+
if: ${{ inputs.requiresTestSdk }}
94109
env:
95110
CI: false
96111
run: >

‎.github/workflows/tests.yml

+46-17
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,49 @@ jobs:
1919
name: Setup for tests (Linux)
2020
runs-on: ubuntu-latest
2121
outputs:
22-
integrations_tests_matrix: ${{ steps.generate_integrations_test_matrix.outputs.integrations_tests_matrix }}
23-
templates_tests_matrix: ${{ steps.generate_templates_test_matrix.outputs.templates_tests_matrix }}
22+
integrations_tests_matrix: ${{ steps.generate_tests_matrix.outputs.integrations_tests_matrix }}
23+
templates_tests_matrix: ${{ steps.generate_tests_matrix.outputs.templates_tests_matrix }}
2424
steps:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2626

27-
- uses: ./.github/actions/enumerate-template-tests
28-
id: generate_templates_test_matrix
29-
3027
- uses: ./.github/actions/enumerate-tests
31-
id: generate_integrations_test_matrix
28+
id: generate_tests_matrix
29+
with:
30+
includeIntegrations: true
31+
includeTemplates: true
3232

3333
setup_for_tests_win:
3434
name: Setup for tests (Windows)
3535
runs-on: windows-latest
3636
outputs:
37-
integrations_tests_matrix: ${{ steps.generate_integrations_test_matrix.outputs.integrations_tests_matrix }}
38-
templates_tests_matrix: ${{ steps.generate_templates_test_matrix.outputs.templates_tests_matrix }}
37+
integrations_tests_matrix: ${{ steps.generate_tests_matrix.outputs.integrations_tests_matrix }}
38+
templates_tests_matrix: ${{ steps.generate_tests_matrix.outputs.templates_tests_matrix }}
3939
steps:
4040
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4141

42-
- uses: ./.github/actions/enumerate-template-tests
43-
id: generate_templates_test_matrix
44-
4542
- uses: ./.github/actions/enumerate-tests
46-
id: generate_integrations_test_matrix
43+
id: generate_tests_matrix
44+
with:
45+
includeIntegrations: true
46+
includeTemplates: true
47+
48+
build_packages:
49+
name: Build packages
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
54+
55+
- name: Build with packages
56+
env:
57+
CI: false
58+
run: ./build.sh -restore -build -ci -pack -testnobuild /bl /p:InstallBrowsersForPlaywright=false
59+
60+
- name: Upload built NuGets
61+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
62+
with:
63+
name: built-nugets
64+
path: artifacts/packages
4765

4866
integrations_test_lin:
4967
uses: ./.github/workflows/run-tests.yml
@@ -56,7 +74,6 @@ jobs:
5674
with:
5775
testShortName: ${{ matrix.shortname }}
5876
os: "ubuntu-latest"
59-
requiresNugets: ${{ matrix.shortname == 'EndToEnd' }}
6077

6178
integrations_test_win:
6279
uses: ./.github/workflows/run-tests.yml
@@ -69,12 +86,11 @@ jobs:
6986
with:
7087
testShortName: ${{ matrix.shortname }}
7188
os: "windows-latest"
72-
requiresNugets: ${{ matrix.shortname == 'EndToEnd' }}
7389

7490
templates_test_lin:
7591
name: Templates Linux
7692
uses: ./.github/workflows/run-tests.yml
77-
needs: setup_for_tests_lin
93+
needs: [setup_for_tests_lin, build_packages]
7894
strategy:
7995
fail-fast: false
8096
matrix: ${{ fromJson(needs.setup_for_tests_lin.outputs.templates_tests_matrix) }}
@@ -87,11 +103,12 @@ jobs:
87103
# append '.' to the name so only the test class with exactly that name is run
88104
extraTestArgs: "--filter FullyQualifiedName~Aspire.Templates.Tests.${{ matrix.shortname }}."
89105
requiresNugets: true
106+
requiresTestSdk: true
90107

91108
templates_test_win:
92109
name: Templates Windows
93110
uses: ./.github/workflows/run-tests.yml
94-
needs: setup_for_tests_win
111+
needs: [setup_for_tests_win, build_packages]
95112
strategy:
96113
fail-fast: false
97114
matrix: ${{ fromJson(needs.setup_for_tests_win.outputs.templates_tests_matrix) }}
@@ -104,12 +121,24 @@ jobs:
104121
# append '.' to the name so only the test class with exactly that name is run
105122
extraTestArgs: "--filter FullyQualifiedName~Aspire.Templates.Tests.${{ matrix.shortname }}."
106123
requiresNugets: true
124+
requiresTestSdk: true
125+
126+
endtoend_tests:
127+
name: EndToEnd ${{ matrix.os }}
128+
uses: ./.github/workflows/run-tests.yml
129+
needs: build_packages
130+
with:
131+
testShortName: EndToEnd
132+
# EndToEnd is not run on Windows due to missing Docker support
133+
os: ubuntu-latest
134+
testProjectPath: tests/Aspire.EndToEnd.Tests/Aspire.EndToEnd.Tests.csproj
135+
requiresNugets: true
107136

108137
results: # This job is used for branch protection. It ensures all the above tests passed
109138
if: ${{ always() }}
110139
runs-on: ubuntu-latest
111140
name: Final Results
112-
needs: [ integrations_test_lin, integrations_test_win, templates_test_lin, templates_test_win ]
141+
needs: [ integrations_test_lin, integrations_test_win, templates_test_lin, templates_test_win, endtoend_tests ]
113142
steps:
114143
# get all the test-job-result* artifacts into a single directory
115144
- uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9

‎eng/Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ProjectToBuild Include="$(RepoRoot)eng\dcppack\**\*.csproj" />
55
<ProjectToBuild Include="$(RepoRoot)eng\dashboardpack\**\*.csproj" />
66
<ProjectToBuild Include="$(RepoRoot)playground\**\*.csproj" />
7-
<ProjectToBuild Include="$(RepoRoot)tests\**\*.csproj" />
7+
<ProjectToBuild Include="$(RepoRoot)tests\**\*.csproj" Condition="'$(TestNoBuild)' != 'true'" />
88
</ItemGroup>
99

1010
<!-- When building from source, we want to use the live repo contents as opposed to cloning the repo. -->

‎tests/Aspire.EndToEnd.Tests/IntegrationServicesFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public IntegrationServicesFixture(IMessageSink diagnosticMessageSink)
3838
{
3939
_diagnosticMessageSink = diagnosticMessageSink;
4040
_testOutput = new TestOutputWrapper(messageSink: _diagnosticMessageSink);
41-
BuildEnvironment = new(useSystemDotNet: !TestsRunningOutsideOfRepo);
41+
BuildEnvironment = new(useSystemDotNet: true);
4242
if (TestsRunningOutsideOfRepo)
4343
{
4444
BuildEnvironment.EnvVars["TestsRunningOutsideOfRepo"] = "true";

‎tests/Aspire.Hosting.Tests/Health/ResourceHealthCheckServiceTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ await app.ResourceNotifications.PublishUpdateAsync(resource.Resource, s => s wit
137137
}
138138

139139
[Fact]
140+
[ActiveIssue("https://github.com/dotnet/aspire/issues/8103")]
140141
public async Task ResourcesWithHealthCheck_StopsAndRestartsMonitoringWithResource()
141142
{
142143
using var builder = TestDistributedApplicationBuilder.Create(testOutputHelper);

‎tests/Shared/GetTestProjects.proj

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<_TestProjectsToExclude Include="$(RepoRoot)tests\testproject\**\*Tests.csproj" />
2020
<_TestProjectsToExclude Include="$(RepoRoot)tests\TestingAppHost1\**\*Tests.csproj" />
2121

22+
<!-- This runs in a separate job -->
23+
<_TestProjectsToExclude Include="$(RepoRoot)tests\Aspire.EndToEnd.Tests\**\*Tests.csproj" />
2224
<!-- This runs in a separate job -->
2325
<_TestProjectsToExclude Include="$(RepoRoot)tests\Aspire.Templates.Tests\**\*Tests.csproj" />
2426

0 commit comments

Comments
 (0)
Please sign in to comment.