4
4
using System . Linq ;
5
5
using System . Runtime . InteropServices ;
6
6
using System . Threading . Tasks ;
7
- using JetBrains . Annotations ;
7
+
8
8
using Nuke . Common ;
9
9
using Nuke . Common . Execution ;
10
10
using Nuke . Common . IO ;
@@ -92,7 +92,7 @@ bool HasDesktopMsBuild
92
92
93
93
[ Solution ] readonly Solution Solution ;
94
94
95
- [ CanBeNull ] Dictionary < string , ( Solution Solution , bool UseDesktopMSBuild ) > SolutionsValue ;
95
+ Dictionary < string , ( Solution Solution , bool UseDesktopMSBuild ) > ? SolutionsValue ;
96
96
97
97
Dictionary < string , ( Solution Solution , bool UseDesktopMSBuild ) > Solutions
98
98
=> SolutionsValue ??= Projects . ProcessSolution ( Solution , FeatureSets , HasDesktopMsBuild ) ;
@@ -157,7 +157,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
157
157
"extension) to the AllowedExclusions array in the NUKE Build.cs file."
158
158
) ;
159
159
160
- missedOut . Add ( file ) ;
160
+ missedOut . Add ( Path . GetRelativePath ( RootDirectory , file ) ) ;
161
161
}
162
162
}
163
163
@@ -180,6 +180,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
180
180
(
181
181
( ) =>
182
182
{
183
+ var outputs = Enumerable . Empty < Output > ( ) ;
183
184
if ( ! HasProcessedSolutions )
184
185
{
185
186
var slnDir = Path . Combine ( Solution . Directory ! , "build" , "sln" ) ;
@@ -202,21 +203,27 @@ Dictionary<string, object> ProcessedMsbuildProperties
202
203
Logger . Info ( $ "Cleaning feature set \" { key } \" ({ sln } )") ;
203
204
if ( useDesktopMsBuild )
204
205
{
205
- MSBuild
206
+ outputs = outputs . Concat
206
207
(
207
- s => s . SetTargets ( "Clean" )
208
- . SetMaxCpuCount ( Environment . ProcessorCount )
209
- . SetProperties ( ProcessedMsbuildProperties )
210
- . SetTargetPath ( sln )
208
+ MSBuild
209
+ (
210
+ s => s . SetTargets ( "Clean" )
211
+ . SetMaxCpuCount ( Environment . ProcessorCount )
212
+ . SetProperties ( ProcessedMsbuildProperties )
213
+ . SetTargetPath ( sln )
214
+ )
211
215
) ;
212
216
}
213
217
else
214
218
{
215
- DotNetClean
219
+ outputs = outputs . Concat
216
220
(
217
- s => s . SetProject ( sln )
218
- . SetConfiguration ( Configuration )
219
- . SetProperties ( ProcessedMsbuildProperties )
221
+ DotNetClean
222
+ (
223
+ s => s . SetProject ( sln )
224
+ . SetConfiguration ( Configuration )
225
+ . SetProperties ( ProcessedMsbuildProperties )
226
+ )
220
227
) ;
221
228
}
222
229
}
@@ -228,12 +235,21 @@ Dictionary<string, object> ProcessedMsbuildProperties
228
235
229
236
Directory . CreateDirectory ( RootDirectory / "build" / "output_packages" ) ;
230
237
231
- var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid" ;
232
- using var process = RuntimeInformation . IsOSPlatform ( OSPlatform . Linux )
233
- ? StartProcess ( "bash" , "-c \" ./gradlew clean\" " , silkDroid )
234
- : StartProcess ( "cmd" , "/c \" .\\ gradlew clean\" " , silkDroid ) ;
235
- process . AssertZeroExitCode ( ) ;
236
- return process . Output ;
238
+ if ( FeatureSets . Any ( x => x . Equals ( "native" , StringComparison . OrdinalIgnoreCase ) ) )
239
+ {
240
+ var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid" ;
241
+ using var process = RuntimeInformation . IsOSPlatform ( OSPlatform . Linux )
242
+ ? StartProcess ( "bash" , "-c \" ./gradlew clean\" " , silkDroid )
243
+ : StartProcess ( "cmd" , "/c \" .\\ gradlew clean\" " , silkDroid ) ;
244
+ process . AssertZeroExitCode ( ) ;
245
+ outputs = outputs . Concat ( process . Output ) ;
246
+ }
247
+ else
248
+ {
249
+ Logger . Warn ( "Skipping gradlew clean as the \" native\" feature-set has not been specified." ) ;
250
+ }
251
+
252
+ return outputs ;
237
253
}
238
254
) ;
239
255
@@ -300,7 +316,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
300
316
s => s
301
317
. SetProjectFile ( sln )
302
318
. SetConfiguration ( Configuration )
303
- . SetNoRestore ( true )
319
+ . EnableNoRestore ( )
304
320
. SetProperties ( ProcessedMsbuildProperties )
305
321
) ;
306
322
}
@@ -357,6 +373,12 @@ Dictionary<string, object> ProcessedMsbuildProperties
357
373
(
358
374
( ) =>
359
375
{
376
+ if ( ! FeatureSets . Any ( x => x . Equals ( "native" , StringComparison . OrdinalIgnoreCase ) ) )
377
+ {
378
+ Logger . Warn ( "Skipping gradlew build as the \" native\" feature-set has not been specified." ) ;
379
+ return Enumerable . Empty < Output > ( ) ;
380
+ }
381
+
360
382
var sdl = RootDirectory / "build" / "submodules" / "SDL" ;
361
383
var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid" ;
362
384
var xcopy = new ( string , string ) [ ]
@@ -425,7 +447,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
425
447
s => s
426
448
. SetProject ( sln )
427
449
. SetConfiguration ( Configuration )
428
- . SetNoRestore ( true )
450
+ . EnableNoRestore ( )
429
451
. SetProperties ( ProcessedMsbuildProperties )
430
452
) ;
431
453
}
@@ -448,21 +470,25 @@ Dictionary<string, object> ProcessedMsbuildProperties
448
470
static IEnumerable < string > Packages => Directory . GetFiles ( PackageDirectory , "*.nupkg" )
449
471
. Where ( x => Path . GetFileName ( x ) . StartsWith ( "Silk.NET" ) || Path . GetFileName ( x ) . StartsWith ( "Ultz.Native" ) ) ;
450
472
451
- async Task PushPackages ( )
473
+ async Task < IEnumerable < Output > > PushPackages ( )
452
474
{
475
+ var outputs = Enumerable . Empty < Output > ( ) ;
453
476
const int rateLimit = 300 ;
454
477
if ( ! string . IsNullOrWhiteSpace ( SignUsername ) && ! string . IsNullOrWhiteSpace ( SignPassword ) )
455
478
{
456
479
var basePath = RootDirectory / "build" / "codesigning" ;
457
480
var execPath = basePath / "tool" / ( OperatingSystem . IsWindows ( ) ? "SignClient.exe" : "SignClient" ) ;
458
481
if ( ! File . Exists ( execPath ) )
459
482
{
460
- DotNetToolInstall ( s => s . SetToolInstallationPath ( basePath / "tool" ) . SetPackageName ( "SignClient" ) ) ;
483
+ outputs = outputs . Concat
484
+ (
485
+ DotNetToolInstall ( s => s . SetToolInstallationPath ( basePath / "tool" ) . SetPackageName ( "SignClient" ) )
486
+ ) ;
461
487
}
462
488
463
489
foreach ( var pkg in Packages )
464
490
{
465
- StartProcess
491
+ var proc = StartProcess
466
492
(
467
493
execPath ,
468
494
"sign " +
@@ -475,7 +501,10 @@ async Task PushPackages()
475
501
"--name \" Silk.NET\" " +
476
502
"--description \" Silk.NET\" " +
477
503
"--descriptionUrl \" https://github.com/dotnet/Silk.NET\" "
478
- ) . AssertZeroExitCode ( ) ;
504
+ ) ;
505
+
506
+ proc . AssertZeroExitCode ( ) ;
507
+ outputs = outputs . Concat ( proc . Output ) ;
479
508
}
480
509
}
481
510
@@ -484,11 +513,6 @@ async Task PushPackages()
484
513
. Select ( x => x . Select ( v => v . Value ) . ToList ( ) )
485
514
. ToList ( ) ;
486
515
var first = true ;
487
- var pushed = 0 ;
488
- var feed = NuGetInterface . OpenNuGetFeed ( NugetFeed , NugetUsername , NugetPassword ) ;
489
- var uploadResource = await NuGetInterface . GetUploadResourceAsync ( feed ) ;
490
- var symbolsResource = await NuGetInterface . GetSymbolsUploadResourceAsync ( feed ) ;
491
- var exceptions = new List < Exception > ( ) ;
492
516
Logger . Info ( $ "Searching for packages in \" { RootDirectory / "build" / "output_packages" } \" ...") ;
493
517
foreach ( var files in allFiles )
494
518
{
@@ -501,33 +525,33 @@ async Task PushPackages()
501
525
await Task . Delay ( TimeSpan . FromHours ( 1 ) ) ;
502
526
}
503
527
504
- foreach ( var file in files )
528
+ var srcSettings = new DotNetNuGetAddSourceSettings ( ) . SetName ( "Silk-PushPackages" ) . SetSource ( NugetFeed ) ;
529
+ if ( NugetUsername is not null || NugetPassword is not null )
505
530
{
506
- try
507
- {
508
- await NuGetInterface . UploadPackageAsync
509
- ( uploadResource , NugetNoServiceEndpoint , file , NugetApiKey , symbolsResource ) ;
510
- pushed ++ ;
511
- }
512
- catch ( Exception ex )
531
+ if ( NugetUsername is null || NugetPassword is null )
513
532
{
514
- if ( file . Contains ( ".Native." ) ) // native packages have their own update cycle
515
- {
516
- Logger . Warn ( ex ) ;
517
- }
518
- else
519
- {
520
- exceptions . Add ( new Exception ( $ "Failed to push package \" { file } \" ", ex ) ) ;
521
- }
533
+ ControlFlow . Fail
534
+ (
535
+ "Both \" NugetUsername\" and \" NugetPassword\" must be specified if either are used."
536
+ ) ;
522
537
}
538
+
539
+ srcSettings = srcSettings . SetUsername ( NugetUsername ) . SetPassword ( NugetPassword ) ;
523
540
}
524
- }
541
+
542
+ outputs = outputs . Concat ( DotNetNuGetAddSource ( srcSettings ) ) ;
525
543
526
- Logger . Success ( $ "Successfully pushed { pushed } packages.") ;
544
+ foreach ( var pushSettings in files . Select ( file => new DotNetNuGetPushSettings ( )
545
+ . SetNoServiceEndpoint ( NugetNoServiceEndpoint )
546
+ . EnableSkipDuplicate ( )
547
+ . SetTargetPath ( file ) ) )
548
+ {
549
+ outputs = outputs . Concat ( DotNetNuGetPush ( pushSettings ) ) ;
550
+ }
527
551
528
- if ( exceptions . Count > 0 )
529
- {
530
- throw new AggregateException ( exceptions ) ;
552
+ outputs = outputs . Concat ( DotNet ( $ "dotnet nuget remove source \" Silk-PushPackages\" ") ) ;
531
553
}
554
+
555
+ return outputs ;
532
556
}
533
557
}
0 commit comments