33
33
GenerateReleaseWorkflow ( component ) ;
34
34
}
35
35
36
+ GenerateUploadTestResultsWorkflow ( ) ;
37
+
38
+
36
39
void GenerateCiWorkflow ( Component component )
37
40
{
38
- var workflow = new Workflow ( $ " { component . Name } /ci" ) ;
41
+ var workflow = new Workflow ( component . CiWorkflowName ) ;
39
42
var paths = new [ ]
40
43
{
41
44
$ ".github/workflows/{ component . Name } -**",
@@ -76,9 +79,11 @@ void GenerateCiWorkflow(Component component)
76
79
77
80
foreach ( var testProject in component . Tests )
78
81
{
79
- job . StepTestAndReport ( component . Name , testProject ) ;
82
+ job . StepTest ( component . Name , testProject ) ;
80
83
}
81
84
85
+ job . StepUploadTestResultsAsArtifact ( component ) ;
86
+
82
87
job . StepToolRestore ( ) ;
83
88
84
89
foreach ( var project in component . Projects )
@@ -100,7 +105,7 @@ void GenerateCiWorkflow(Component component)
100
105
101
106
void GenerateReleaseWorkflow ( Component component )
102
107
{
103
- var workflow = new Workflow ( $ " { component . Name } /release" ) ;
108
+ var workflow = new Workflow ( component . ReleaseWorkflowName ) ;
104
109
105
110
workflow . On
106
111
. WorkflowDispatch ( )
@@ -166,14 +171,49 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
166
171
WriteWorkflow ( workflow , fileName ) ;
167
172
}
168
173
174
+ void GenerateUploadTestResultsWorkflow ( )
175
+ {
176
+ var workflow = new Workflow ( "generate-test-reports" ) ;
177
+ workflow . On
178
+ . WorkflowRun ( )
179
+ . Workflows ( components . Select ( x => x . CiWorkflowName ) . ToArray ( ) )
180
+ . Types ( "completed" ) ;
181
+
182
+ var job = workflow
183
+ . Job ( "report" )
184
+ . Name ( "report" )
185
+ . RunsOn ( GitHubHostedRunners . UbuntuLatest ) ;
186
+
187
+ job . Permissions (
188
+ actions : Permission . Read ,
189
+ contents : Permission . Read ,
190
+ checks : Permission . Write ,
191
+ packages : Permission . Write ) ;
192
+
193
+ foreach ( var component in components )
194
+ {
195
+ foreach ( var testProject in component . Tests )
196
+ {
197
+ job . StepGenerateReportFromTestArtifact ( component , testProject ) ;
198
+ }
199
+ }
200
+
201
+ var fileName = $ "generate-test-reports";
202
+ WriteWorkflow ( workflow , fileName ) ;
203
+ }
204
+
169
205
void WriteWorkflow ( Workflow workflow , string fileName )
170
206
{
171
207
var filePath = $ "../workflows/{ fileName } .yml";
172
208
workflow . WriteYaml ( filePath ) ;
173
209
Console . WriteLine ( $ "Wrote workflow to { filePath } ") ;
174
210
}
175
211
176
- record Component ( string Name , string [ ] Projects , string [ ] Tests , string TagPrefix ) ;
212
+ record Component ( string Name , string [ ] Projects , string [ ] Tests , string TagPrefix )
213
+ {
214
+ public string CiWorkflowName => $ "{ Name } /ci";
215
+ public string ReleaseWorkflowName => $ "{ Name } /release";
216
+ }
177
217
178
218
public static class StepExtensions
179
219
{
@@ -190,28 +230,43 @@ public static void StepSetupDotNet(this Job job)
190
230
public static Step IfRefMain ( this Step step )
191
231
=> step . If ( "github.ref == 'refs/heads/main'" ) ;
192
232
193
- public static Job RunEitherOnBranchOrAsPR ( this Job job )
194
- => job . If (
195
- "(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || (github.event_name == 'push')" ) ;
196
-
197
- public static void StepTestAndReport ( this Job job , string componentName , string testProject )
233
+ public static void StepTest ( this Job job , string componentName , string testProject )
198
234
{
199
235
var path = $ "test/{ testProject } ";
200
- var logFileName = "Tests .trx";
236
+ var logFileName = $ " { testProject } .trx";
201
237
var flags = $ "--logger \" console;verbosity=normal\" " +
202
238
$ "--logger \" trx;LogFileName={ logFileName } \" " +
203
239
$ "--collect:\" XPlat Code Coverage\" ";
204
240
job . Step ( )
205
241
. Name ( $ "Test - { testProject } ")
206
242
. Run ( $ "dotnet test -c Release { path } { flags } ") ;
207
243
244
+ }
245
+
246
+ internal static void StepUploadTestResultsAsArtifact ( this Job job , Component component )
247
+ {
248
+ job . Step ( )
249
+ . Name ( $ "Test report")
250
+ . If ( "success() || failure()" )
251
+ . Uses ( "actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882" ) // 4.4.3
252
+ . With (
253
+ ( "name" , "test-results" ) ,
254
+ ( "path" , string . Join ( Environment . NewLine , component . Tests
255
+ . Select ( testProject => $ "{ component . Name } /test/{ testProject } /TestResults/{ testProject } .trx") ) ) ,
256
+ ( "retention-days" , "5" ) ) ;
257
+ }
258
+
259
+ internal static void StepGenerateReportFromTestArtifact ( this Job job , Component component , string testProject )
260
+ {
261
+ var path = $ "test/{ testProject } ";
208
262
job . Step ( )
209
- . Name ( $ "Test report - { testProject } ")
263
+ . Name ( $ "Test report - { component . Name } - { testProject } ")
210
264
. Uses ( "dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5" ) // v1.9.1
211
- . If ( "github.event_name == 'push' && (success() || failure()) ")
265
+ . If ( $ "event.workflow.name == '{ component . CiWorkflowName } ' ")
212
266
. With (
267
+ ( "artifact" , "test-results" ) ,
213
268
( "name" , $ "Test Report - { testProject } ") ,
214
- ( "path" , $ "{ componentName } / { path } /TestResults/ { logFileName } ") ,
269
+ ( "path" , $ "{ testProject } .trx ") ,
215
270
( "reporter" , "dotnet-trx" ) ,
216
271
( "fail-on-error" , "true" ) ,
217
272
( "fail-on-empty" , "true" ) ) ;
@@ -272,7 +327,7 @@ public static void StepUploadArtifacts(this Job job, string componentName)
272
327
var path = $ "{ componentName } /artifacts/*.nupkg";
273
328
job . Step ( )
274
329
. Name ( "Upload Artifacts" )
275
- . IfRefMain ( )
330
+ . IfGithubEventIsPush ( )
276
331
. Uses ( "actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882" ) // 4.4.3
277
332
. With (
278
333
( "name" , "artifacts" ) ,
0 commit comments