11name : Pull Request Tests
22
33permissions :
4- contents : read
5- checks : write
6- pull-requests : write
4+ contents : read
5+ checks : write
6+ pull-requests : write
77
88on :
9- pull_request :
10- branches : [main, dev]
11- types : [opened, synchronize, reopened]
12- paths :
13- - ' **.cs'
14- - ' **.csproj'
15- - ' **.xaml'
16- - ' **.vsct'
17- - ' **.vsixmanifest'
18- - ' .github/workflows/pr-tests.yml'
9+ pull_request :
10+ branches : [main, dev]
11+ types : [opened, synchronize, reopened]
12+ paths :
13+ - " **.cs"
14+ - " **.csproj"
15+ - " **.xaml"
16+ - " **.vsct"
17+ - " **.vsixmanifest"
18+ - " .github/workflows/pr-tests.yml"
1919
2020concurrency :
21- group : ${{ github.workflow }}-${{ github.ref }}
22- cancel-in-progress : true
21+ group : ${{ github.workflow }}-${{ github.ref }}
22+ cancel-in-progress : true
2323
2424env :
25- DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
26- DOTNET_CLI_TELEMETRY_OPTOUT : true
25+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
26+ DOTNET_CLI_TELEMETRY_OPTOUT : true
2727
2828jobs :
29- build-and-test :
30- runs-on : windows-latest
31- timeout-minutes : 30
32-
33- steps :
34- - name : Checkout code
35- uses : actions/checkout@v4
36- with :
37- fetch-depth : 0 # Needed for better caching
38-
39- - name : Setup MSBuild
40- uses : microsoft/setup-msbuild@v2
41-
42- - name : Setup NuGet
43- uses : NuGet/setup-nuget@v2
44-
45- # Improved caching with better key strategy
46- - name : Cache NuGet packages
47- uses : actions/cache@v4
48- with :
49- path : ~/.nuget/packages
50- key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
51- restore-keys : |
52- ${{ runner.os }}-nuget-
53-
54- # Restore once for the entire solution
55- - name : Restore NuGet packages
56- run : |
57- Write-Host "🔄 Restoring NuGet packages..."
58- nuget restore DataLayerGenerator.Extension/DataLayerGenerator.Extension.csproj
59- nuget restore DataLayerGenerator.Tests/DataLayerGenerator.Tests.csproj
60- shell : pwsh
61-
62- # Build Debug configuration (for tests)
63- - name : Build Solution (Debug)
64- run : |
65- Write-Host "🔨 Building Debug configuration..."
66- msbuild DataLayerGenerator.Extension/DataLayerGenerator.Extension.csproj /p:Configuration=Debug /v:minimal /m /warnaserror
67- msbuild DataLayerGenerator.Tests/DataLayerGenerator.Tests.csproj /p:Configuration=Debug /v:minimal /m /warnaserror
68- shell : pwsh
69-
70- - name : Setup VSTest
71- 72-
73- - name : Run Tests
74- timeout-minutes : 10
75- shell : pwsh
76- run : |
77- Write-Host "🧪 Running tests..."
78-
79- $testDll = Get-ChildItem -Path "DataLayerGenerator.Tests\bin\Debug" -Filter "DataLayerGenerator.Tests.dll" -Recurse | Select-Object -First 1
80-
81- if ($null -eq $testDll) {
82- Write-Host "❌ Test DLL not found!"
83- exit 1
84- }
85-
86- Write-Host "✅ Found test DLL at: $($testDll.FullName)"
87-
88- # Run tests with detailed logging
89- vstest.console.exe $testDll.FullName `
90- /logger:trx `
91- /logger:"console;verbosity=normal" `
92- /ResultsDirectory:TestResults `
93- /Parallel
94-
95- # Simplified test results - just use artifacts
96- - name : Upload Test Results
97- uses : actions/upload-artifact@v4
98- if : always()
99- with :
100- name : test-results
101- path : TestResults/*.trx
102- retention-days : 7
103-
104- - name : Test Summary
105- if : always()
106- timeout-minutes : 2
107- shell : pwsh
108- run : |
109- $trxFiles = Get-ChildItem -Path TestResults -Filter *.trx -Recurse
110-
111- if ($trxFiles.Count -eq 0) {
112- Write-Host "❌ No test results found!"
113- exit 1
114- }
115-
116- foreach ($trxFile in $trxFiles) {
117- [xml]$trx = Get-Content $trxFile.FullName
118- $summary = $trx.TestRun.ResultSummary
119- $counters = $summary.Counters
120-
121- $total = [int]$counters.total
122- $passed = [int]$counters.passed
123- $failed = [int]$counters.failed
124- $skipped = [int]$counters.total - [int]$counters.executed
125-
126- Write-Host ""
127- Write-Host "📊 Test Summary"
128- Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
129- Write-Host "✅ Passed: $passed"
130- Write-Host "❌ Failed: $failed"
131- Write-Host "⏭️ Skipped: $skipped"
132- Write-Host "📝 Total: $total"
133- Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
134-
135- # Output to GitHub Actions summary
136- echo "## 📊 Test Results" >> $env:GITHUB_STEP_SUMMARY
137- echo "" >> $env:GITHUB_STEP_SUMMARY
138- echo "| Metric | Count |" >> $env:GITHUB_STEP_SUMMARY
139- echo "|--------|-------|" >> $env:GITHUB_STEP_SUMMARY
140- echo "| ✅ Passed | $passed |" >> $env:GITHUB_STEP_SUMMARY
141- echo "| ❌ Failed | $failed |" >> $env:GITHUB_STEP_SUMMARY
142- echo "| ⏭️ Skipped | $skipped |" >> $env:GITHUB_STEP_SUMMARY
143- echo "| 📝 Total | $total |" >> $env:GITHUB_STEP_SUMMARY
144-
145- if ($failed -gt 0) {
146- Write-Host ""
147- Write-Host "❌ Tests Failed!"
148-
149- # Show failed tests
150- $failedTests = $trx.TestRun.Results.UnitTestResult | Where-Object { $_.outcome -eq "Failed" }
151- if ($failedTests) {
152- Write-Host ""
153- Write-Host "Failed Tests:"
154- foreach ($test in $failedTests) {
155- Write-Host " - $($test.testName)"
156- if ($test.Output.ErrorInfo.Message) {
157- Write-Host " Error: $($test.Output.ErrorInfo.Message)"
29+ build-and-test :
30+ runs-on : windows-latest
31+ timeout-minutes : 30
32+
33+ steps :
34+ - name : Checkout code
35+ uses : actions/checkout@v4
36+ with :
37+ fetch-depth : 0 # Needed for better caching
38+
39+ - name : Setup MSBuild
40+ uses : microsoft/setup-msbuild@v2
41+
42+ - name : Setup NuGet
43+ uses : NuGet/setup-nuget@v2
44+
45+ # Improved caching with better key strategy
46+ - name : Cache NuGet packages
47+ uses : actions/cache@v4
48+ with :
49+ path : ~/.nuget/packages
50+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
51+ restore-keys : |
52+ ${{ runner.os }}-nuget-
53+
54+ # Restore once for the entire solution
55+ - name : Restore NuGet packages
56+ run : |
57+ Write-Host "🔄 Restoring NuGet packages..."
58+ nuget restore DataLayerGenerator.Extension/DataLayerGenerator.Extension.csproj
59+ nuget restore DataLayerGenerator.Tests/DataLayerGenerator.Tests.csproj
60+ shell : pwsh
61+
62+ # Build Debug configuration (for tests)
63+ - name : Build Solution (Debug)
64+ run : |
65+ Write-Host "🔨 Building Debug configuration..."
66+ msbuild DataLayerGenerator.Extension/DataLayerGenerator.Extension.csproj /p:Configuration=Debug /v:minimal /m /warnaserror
67+ msbuild DataLayerGenerator.Tests/DataLayerGenerator.Tests.csproj /p:Configuration=Debug /v:minimal /m /warnaserror
68+ shell : pwsh
69+
70+ - name : Setup VSTest
71+ 72+
73+ - name : Run Tests
74+ timeout-minutes : 10
75+ shell : pwsh
76+ run : |
77+ Write-Host "🧪 Running tests..."
78+
79+ $testDll = Get-ChildItem -Path "DataLayerGenerator.Tests\bin\Debug" -Filter "DataLayerGenerator.Tests.dll" -Recurse | Select-Object -First 1
80+
81+ if ($null -eq $testDll) {
82+ Write-Host "❌ Test DLL not found!"
83+ exit 1
15884 }
159- }
160- }
161-
162- exit 1
163- } else {
164- Write-Host ""
165- Write-Host "✅ All Tests Passed!"
166- }
167- }
168-
169- # Build Release configuration
170- - name : Build Solution (Release)
171- run : |
172- Write-Host "🔨 Building Release configuration..."
173- msbuild DataLayerGenerator.Extension/DataLayerGenerator.Extension.csproj /p:Configuration=Release /v:minimal /m /warnaserror
174- shell : pwsh
175-
176- - name : Final Status
177- if : success()
178- run : |
179- Write-Host "✅ All checks passed successfully!"
180- echo "## ✅ Build and Test Successful" >> $env:GITHUB_STEP_SUMMARY
181- echo "" >> $env:GITHUB_STEP_SUMMARY
182- echo "All builds completed and all tests passed!" >> $env:GITHUB_STEP_SUMMARY
183- shell : pwsh
85+
86+ Write-Host "✅ Found test DLL at: $($testDll.FullName)"
87+
88+ # Run tests with detailed logging
89+ vstest.console.exe $testDll.FullName `
90+ /logger:trx `
91+ /logger:"console;verbosity=normal" `
92+ /ResultsDirectory:TestResults `
93+ /Parallel
94+
95+ # Simplified test results - just use artifacts
96+ - name : Upload Test Results
97+ uses : actions/upload-artifact@v4
98+ if : always()
99+ with :
100+ name : test-results
101+ path : TestResults/*.trx
102+ retention-days : 7
103+
104+ - name : Test Summary
105+ if : always()
106+ timeout-minutes : 2
107+ shell : pwsh
108+ run : |
109+ $trxFiles = Get-ChildItem -Path TestResults -Filter *.trx -Recurse
110+
111+ if ($trxFiles.Count -eq 0) {
112+ Write-Host "❌ No test results found!"
113+ exit 1
114+ }
115+
116+ foreach ($trxFile in $trxFiles) {
117+ [xml]$trx = Get-Content $trxFile.FullName
118+ $summary = $trx.TestRun.ResultSummary
119+ $counters = $summary.Counters
120+
121+ $total = [int]$counters.total
122+ $passed = [int]$counters.passed
123+ $failed = [int]$counters.failed
124+ $skipped = [int]$counters.total - [int]$counters.executed
125+
126+ Write-Host ""
127+ Write-Host "📊 Test Summary"
128+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
129+ Write-Host "✅ Passed: $passed"
130+ Write-Host "❌ Failed: $failed"
131+ Write-Host "⏭️ Skipped: $skipped"
132+ Write-Host "📝 Total: $total"
133+ Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
134+
135+ # Output to GitHub Actions summary
136+ echo "## 📊 Test Results" >> $env:GITHUB_STEP_SUMMARY
137+ echo "" >> $env:GITHUB_STEP_SUMMARY
138+ echo "| Metric | Count |" >> $env:GITHUB_STEP_SUMMARY
139+ echo "|--------|-------|" >> $env:GITHUB_STEP_SUMMARY
140+ echo "| ✅ Passed | $passed |" >> $env:GITHUB_STEP_SUMMARY
141+ echo "| ❌ Failed | $failed |" >> $env:GITHUB_STEP_SUMMARY
142+ echo "| ⏭️ Skipped | $skipped |" >> $env:GITHUB_STEP_SUMMARY
143+ echo "| 📝 Total | $total |" >> $env:GITHUB_STEP_SUMMARY
144+
145+ if ($failed -gt 0) {
146+ Write-Host ""
147+ Write-Host "❌ Tests Failed!"
148+
149+ # Show failed tests
150+ $failedTests = $trx.TestRun.Results.UnitTestResult | Where-Object { $_.outcome -eq "Failed" }
151+ if ($failedTests) {
152+ Write-Host ""
153+ Write-Host "Failed Tests:"
154+ foreach ($test in $failedTests) {
155+ Write-Host " - $($test.testName)"
156+ if ($test.Output.ErrorInfo.Message) {
157+ Write-Host " Error: $($test.Output.ErrorInfo.Message)"
158+ }
159+ }
160+ }
161+
162+ exit 1
163+ } else {
164+ Write-Host ""
165+ Write-Host "✅ All Tests Passed!"
166+ }
167+ }
168+
169+ # Build Release configuration
170+ - name : Build Solution (Release)
171+ run : |
172+ Write-Host "🔨 Building Release configuration..."
173+ msbuild DataLayerGenerator.Extension/DataLayerGenerator.Extension.csproj /p:Configuration=Release /v:minimal /m /warnaserror
174+ shell : pwsh
175+
176+ - name : Final Status
177+ if : success()
178+ run : |
179+ Write-Host "✅ All checks passed successfully!"
180+ echo "## ✅ Build and Test Successful" >> $env:GITHUB_STEP_SUMMARY
181+ echo "" >> $env:GITHUB_STEP_SUMMARY
182+ echo "All builds completed and all tests passed!" >> $env:GITHUB_STEP_SUMMARY
183+ shell : pwsh
0 commit comments