11using System ;
2- using System . Collections . Generic ;
32using System . Linq ;
43using Nuke . Common ;
4+ using Nuke . Common . CI . GitHubActions ;
55using Nuke . Common . Execution ;
66using Nuke . Common . IO ;
77using Nuke . Common . ProjectModel ;
1111using Nuke . Common . Tools . ReportGenerator ;
1212using Nuke . Common . Tools . Xunit ;
1313using Nuke . Common . Utilities . Collections ;
14- using static Nuke . Common . IO . FileSystemTasks ;
15- using static Nuke . Common . IO . PathConstruction ;
1614using static Nuke . Common . Tools . DotNet . DotNetTasks ;
1715using static Nuke . Common . Tools . ReportGenerator . ReportGeneratorTasks ;
1816
19- [ CheckBuildProjectConfigurations ]
2017[ UnsetVisualStudioEnvironmentVariables ]
18+ [ DotNetVerbosityMapping ]
2119class Build : NukeBuild
2220{
2321 /* Support plugins are available for:
@@ -28,19 +26,20 @@ class Build : NukeBuild
2826 */
2927 public static int Main ( ) => Execute < Build > ( x => x . Push ) ;
3028
31- [ Parameter ( "A branch specification such as develop or refs/pull/1775/merge" ) ]
32- readonly string BranchSpec ;
29+ GitHubActions GitHubActions => GitHubActions . Instance ;
3330
34- [ Parameter ( "An incrementing build number as provided by the build engine" ) ]
35- readonly string BuildNumber ;
31+ string BranchSpec => GitHubActions ? . Ref ;
32+
33+ string BuildNumber => GitHubActions ? . RunNumber . ToString ( ) ;
3634
3735 [ Parameter ( "The key to push to Nuget" ) ]
36+ [ Secret ]
3837 readonly string ApiKey ;
3938
4039 [ Solution ( GenerateProjects = true ) ]
4140 readonly Solution Solution ;
4241
43- [ GitVersion ( Framework = "net5 .0" ) ]
42+ [ GitVersion ( Framework = "net6 .0" ) ]
4443 readonly GitVersion GitVersion ;
4544
4645 AbsolutePath SourceDirectory => RootDirectory / "src" ;
@@ -54,9 +53,9 @@ class Build : NukeBuild
5453 Target Clean => _ => _
5554 . Executes ( ( ) =>
5655 {
57- SourceDirectory . GlobDirectories ( "**/bin" , "**/obj" ) . ForEach ( DeleteDirectory ) ;
58- TestsDirectory . GlobDirectories ( "**/bin" , "**/obj" ) . ForEach ( DeleteDirectory ) ;
59- EnsureCleanDirectory ( ArtifactsDirectory ) ;
56+ SourceDirectory . GlobDirectories ( "**/bin" , "**/obj" ) . ForEach ( path => path . DeleteDirectory ( ) ) ;
57+ TestsDirectory . GlobDirectories ( "**/bin" , "**/obj" ) . ForEach ( path => path . DeleteDirectory ( ) ) ;
58+ ArtifactsDirectory . CreateOrCleanDirectory ( ) ;
6059 } ) ;
6160
6261 Target CalculateNugetVersion => _ => _
@@ -75,7 +74,7 @@ class Build : NukeBuild
7574 Serilog . Log . Information ( "SemVer = {semver}" , SemVer ) ;
7675 } ) ;
7776
78- bool IsPullRequest => BranchSpec != null && BranchSpec . Contains ( "pull" , StringComparison . InvariantCultureIgnoreCase ) ;
77+ bool IsPullRequest => GitHubActions ? . IsPullRequest ?? false ;
7978
8079 Target Restore => _ => _
8180 . DependsOn ( Clean )
@@ -122,7 +121,7 @@ class Build : NukeBuild
122121
123122 DotNetTest ( s => s
124123 . SetProjectFile ( Solution . FluentAssertions_Json_Specs )
125- . SetFramework ( "netcoreapp3 .0" )
124+ . SetFramework ( "net8 .0" )
126125 . SetConfiguration ( "Debug" )
127126 . EnableNoBuild ( )
128127 . SetDataCollector ( "XPlat Code Coverage" )
@@ -134,7 +133,7 @@ class Build : NukeBuild
134133 . Executes ( ( ) =>
135134 {
136135 ReportGenerator ( s => s
137- . SetProcessToolPath ( ToolPathResolver . GetPackageExecutable ( "ReportGenerator" , "ReportGenerator.dll" , framework : "net5 .0" ) )
136+ . SetProcessToolPath ( NuGetToolPathResolver . GetPackageExecutable ( "ReportGenerator" , "ReportGenerator.dll" , framework : "net6 .0" ) )
138137 . SetTargetDirectory ( RootDirectory / "TestResults" / "reports" )
139138 . AddReports ( RootDirectory / "TestResults/**/coverage.cobertura.xml" )
140139 . AddReportTypes ( "HtmlInline_AzurePipelines_Dark" , "lcov" )
@@ -168,9 +167,9 @@ class Build : NukeBuild
168167 . OnlyWhenDynamic ( ( ) => IsTag )
169168 . Executes ( ( ) =>
170169 {
171- IReadOnlyCollection < string > packages = GlobFiles ( ArtifactsDirectory , "*.nupkg" ) ;
170+ var packages = ArtifactsDirectory . GlobFiles ( "*.nupkg" ) ;
172171
173- Assert . NotEmpty ( packages . ToList ( ) ) ;
172+ Assert . NotEmpty ( packages ) ;
174173
175174 DotNetNuGetPush ( s => s
176175 . SetApiKey ( ApiKey )
@@ -181,5 +180,5 @@ class Build : NukeBuild
181180 ( v , path ) => v . SetTargetPath ( path ) ) ) ;
182181 } ) ;
183182
184- bool IsTag => BranchSpec != null && BranchSpec . Contains ( "refs/tags" , StringComparison . InvariantCultureIgnoreCase ) ;
183+ bool IsTag => BranchSpec != null && BranchSpec . Contains ( "refs/tags" , StringComparison . OrdinalIgnoreCase ) ;
185184}
0 commit comments