1- using System ;
21using System . Collections . Generic ;
2+ using System . Diagnostics . CodeAnalysis ;
33using System . Linq ;
44using Nuke . Common ;
55using Nuke . Common . CI ;
6- using Nuke . Common . CI . AppVeyor ;
6+ using Nuke . Common . CI . GitHubActions ;
77using Nuke . Common . Git ;
88using Nuke . Common . IO ;
99using Nuke . Common . ProjectModel ;
10- using Nuke . Common . Tooling ;
1110using Nuke . Common . Tools . Codecov ;
1211using Nuke . Common . Tools . Coverlet ;
1312using Nuke . Common . Tools . DotNet ;
1413using Nuke . Common . Tools . GitVersion ;
15- using Nuke . Common . Tools . NuGet ;
1614using Nuke . Common . Tools . ReportGenerator ;
15+ using Nuke . Common . Utilities ;
1716using Nuke . Common . Utilities . Collections ;
1817using static Nuke . Common . Tools . Codecov . CodecovTasks ;
1918using static Nuke . Common . Tools . DotNet . DotNetTasks ;
20- using static Nuke . Common . Tools . NuGet . NuGetTasks ;
2119using static Nuke . Common . Tools . ReportGenerator . ReportGeneratorTasks ;
2220
23- // ReSharper disable AllUnderscoreLocalParameterName
24-
25- [ ShutdownDotNetAfterServerBuild ]
26- [ AppVeyor (
27- AppVeyorImage . VisualStudio2022 ,
28- InvokedTargets =
29- [
30- nameof ( UploadCodecov ) ,
31- nameof ( PushNuGet ) ,
32- nameof ( PushMyGet ) ,
33- ] ) ]
34- [ AppVeyorSecret ( "MYGET_API_KEY" , "78qy8e6pKfJlQV7RAG5tJOWegzXpjASkUs3aFdVBoPYA5gi6+mWdjbuAmNa5OQPe" ) ]
35- [ AppVeyorSecret ( "NUGET_API_KEY" , "aMbj+EdePo74elFCi6lrQZcO81mru5j8cqD5FxGoDBWgXFFHwok/z4B+BtS4H1Sw" ) ]
36- [ AppVeyorSecret ( "CODECOV_TOKEN" , "3FxtGPNTgZyQGToJBaH68/oIjptV79CcViR9mHt2aOKGh3++oKTehBIuPSb7oYCE" ) ]
21+ [ SuppressMessage ( "ReSharper" , "UnusedMember.Local" ) ]
3722class Build : NukeBuild
3823{
3924 public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
@@ -48,7 +33,7 @@ class Build : NukeBuild
4833 [ Solution ] readonly Solution Solution ;
4934 [ GitRepository ] readonly GitRepository GitRepository ;
5035 [ GitVersion ] readonly GitVersion GitVersion ;
51- [ CI ] readonly AppVeyor AppVeyor ;
36+ [ CI ] readonly GitHubActions GitHubActions ;
5237
5338 static AbsolutePath SourceDirectory => RootDirectory / "src" ;
5439 static AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts" ;
@@ -63,14 +48,23 @@ class Build : NukeBuild
6348 . Before ( Compile )
6449 . Executes ( ( ) =>
6550 {
51+ ArtifactsDirectory . CreateOrCleanDirectory ( ) ;
52+
6653 SourceDirectory
6754 . GlobDirectories ( "**/bin" , "**/obj" )
6855 . ForEach ( path => path . DeleteDirectory ( ) ) ;
56+ } ) ;
6957
70- ArtifactsDirectory . CreateOrCleanDirectory ( ) ;
58+ Target Restore => _ => _
59+ . Executes ( ( ) =>
60+ {
61+ DotNetRestore ( s => s
62+ . SetProjectFile ( Solution )
63+ . EnableLockedMode ( ) ) ;
7164 } ) ;
7265
7366 Target Compile => _ => _
67+ . DependsOn ( Restore )
7468 . Executes ( ( ) =>
7569 {
7670 DotNetBuild ( s => s
@@ -79,7 +73,8 @@ class Build : NukeBuild
7973 . SetAssemblyVersion ( GitVersion . AssemblySemVer )
8074 . SetFileVersion ( GitVersion . AssemblySemFileVer )
8175 . SetInformationalVersion ( GitVersion . InformationalVersion )
82- . EnableTreatWarningsAsErrors ( ) ) ;
76+ . EnableTreatWarningsAsErrors ( )
77+ . EnableNoRestore ( ) ) ;
8378 } ) ;
8479
8580 Target Test => _ => _
@@ -89,15 +84,18 @@ class Build : NukeBuild
8984 CoverageDirectory . CreateOrCleanDirectory ( ) ;
9085 TestResultFolders . ForEach ( directory => directory . DeleteDirectory ( ) ) ;
9186
92- DotNetTest ( s => s
93- . SetConfiguration ( Configuration )
94- . EnableNoRestore ( )
95- . EnableNoBuild ( )
96- . SetDataCollector ( "XPlat Code Coverage" )
97- . SetCoverletOutputFormat ( CoverletOutputFormat . cobertura )
98- . CombineWith ( TestProjects , ( ss , project ) => ss
99- . SetProjectFile ( project ) ) ,
100- degreeOfParallelism : Environment . ProcessorCount ) ;
87+ foreach ( var project in TestProjects )
88+ {
89+ DotNetTest ( s => s
90+ . SetProjectFile ( project )
91+ . SetConfiguration ( Configuration )
92+ . SetDataCollector ( "XPlat Code Coverage" )
93+ . SetCoverletOutputFormat ( CoverletOutputFormat . cobertura )
94+ . EnableNoRestore ( )
95+ . EnableNoBuild ( )
96+ . When ( GitHubActions != null , ss => ss
97+ . SetLoggers ( "GitHubActions" ) ) ) ;
98+ }
10199
102100 ReportGenerator ( s => s
103101 . SetReports ( CoverageResults )
@@ -121,36 +119,38 @@ class Build : NukeBuild
121119
122120 DotNetPack ( s => s
123121 . SetConfiguration ( Configuration )
124- . EnableNoRestore ( )
125- . EnableNoBuild ( )
126122 . SetOutputDirectory ( ArtifactsDirectory )
127- . SetVersion ( GitVersion . SemVer ) ) ;
123+ . SetVersion ( GitVersion . SemVer )
124+ . EnableNoRestore ( )
125+ . EnableNoBuild ( ) ) ;
128126 } ) ;
129127
130128 Target PushMyGet => _ => _
131129 . DependsOn ( Package )
132130 . OnlyWhenStatic ( ( ) => IsServerBuild && GitRepository . IsOnMainBranch ( ) )
133131 . Executes ( ( ) =>
134132 {
135- NuGetPush ( s => s
136- . SetSource ( "https://www.myget.org/F/baunegaard/api/v2/package" )
137- . SetApiKey ( MyGetApiKey )
138- . CombineWith ( Artifacts , ( ss , artifact ) => ss
139- . SetTargetPath ( artifact ) ) ,
140- degreeOfParallelism : Environment . ProcessorCount ) ;
133+ foreach ( var artifact in Artifacts )
134+ {
135+ DotNetNuGetPush ( s => s
136+ . SetTargetPath ( artifact )
137+ . SetSource ( "https://www.myget.org/F/baunegaard/api/v2/package" )
138+ . SetApiKey ( MyGetApiKey ) ) ;
139+ }
141140 } ) ;
142141
143142 Target PushNuGet => _ => _
144143 . DependsOn ( Package )
145- . OnlyWhenStatic ( ( ) => IsServerBuild && AppVeyor . RepositoryTag )
144+ . OnlyWhenStatic ( ( ) => IsServerBuild && GitHubActions . RefType == "tag" )
146145 . Executes ( ( ) =>
147146 {
148- NuGetPush ( s => s
149- . SetSource ( "https://api.nuget.org/v3/index.json" )
150- . SetApiKey ( NuGetApiKey )
151- . CombineWith ( Artifacts , ( ss , artifact ) => ss
152- . SetTargetPath ( artifact ) ) ,
153- degreeOfParallelism : Environment . ProcessorCount ) ;
147+ foreach ( var artifact in Artifacts )
148+ {
149+ DotNetNuGetPush ( s => s
150+ . SetTargetPath ( artifact )
151+ . SetSource ( "https://api.nuget.org/v3/index.json" )
152+ . SetApiKey ( NuGetApiKey ) ) ;
153+ }
154154 } ) ;
155155
156156 Target UploadCodecov => _ => _
0 commit comments