11using System ;
22using System . IO ;
3+ using System . Linq ;
34using Microsoft . AspNetCore . StaticFiles ;
45using NuGet . Versioning ;
56using Nuke . Common ;
67using Nuke . Common . CI . GitHubActions ;
78using Nuke . Common . Execution ;
9+ using Nuke . Common . Git ;
810using Nuke . Common . IO ;
911using Nuke . Common . ProjectModel ;
1012using Nuke . Common . Tooling ;
1113using Nuke . Common . Tools . DotNet ;
1214using Nuke . Common . Tools . GitHub ;
15+ using Nuke . Common . Utilities . Collections ;
1316using Octokit ;
17+ using Serilog ;
1418using static Nuke . Common . IO . FileSystemTasks ;
1519
1620[ GitHubActions (
17- "build " ,
21+ "test " ,
1822 GitHubActionsImage . UbuntuLatest ,
1923 AutoGenerate = false ,
2024 FetchDepth = 0 ,
21- OnPushBranches = new [ ] { "main" , "develop" } ,
22- InvokedTargets = new [ ] { nameof ( Test ) } ,
25+ OnPushBranches = new [ ] { "**" } ,
26+ InvokedTargets = new [ ] { nameof ( Test ) } ,
2327 EnableGitHubToken = true ,
24- ImportSecrets = new [ ] { nameof ( NuGetApiKey ) } ) ]
28+ ImportSecrets = new [ ] { nameof ( NuGetApiKey ) } ) ]
29+ [ GitHubActions (
30+ "release" ,
31+ GitHubActionsImage . UbuntuLatest ,
32+ AutoGenerate = false ,
33+ FetchDepth = 0 ,
34+ OnPushTags = new [ ] { "v[0-9]+.[0-9]+.[0-9]+" } ,
35+ InvokedTargets = new [ ] { nameof ( Pack ) } ,
36+ EnableGitHubToken = true ,
37+ ImportSecrets = new [ ] { nameof ( NuGetApiKey ) } ) ]
2538class Build : NukeBuild
2639{
27- public static int Main ( ) => Execute < Build > ( x => x . Test ) ;
40+ public static int Main ( ) => Execute < Build > ( x => x . Pack ) ;
2841
2942 [ Parameter ( "Configuration to build - Default is 'Debug' (local) or 'Release' (server)" ) ] readonly Configuration Configuration = IsLocalBuild ? Configuration . Debug : Configuration . Release ;
3043
3144 // [Parameter] readonly string GitHubAccessToken;
32-
45+
3346 [ Parameter ( "NuGet API Key" ) , Secret ] readonly string NuGetApiKey ;
3447
3548 [ Solution ( GenerateProjects = true ) ] readonly Solution Solution ;
@@ -40,47 +53,44 @@ class Build : NukeBuild
4053
4154 SemanticVersion PackageVersion ;
4255
43- // [Parameter("The branch or tag name on which the build is executed (GitLab)")] readonly string CI_COMMIT_REF_NAME = string.Empty;
44-
45- // bool IsOnMasterBranch => CI_COMMIT_REF_NAME == "master";
46- // bool IsOnDevelopBranch => CI_COMMIT_REF_NAME == "develop";
47-
48- // bool IsOnVersionTag => Helper.IsValidVersionTag(CI_COMMIT_REF_NAME, out SemanticVersion _);
56+ [ GitRepository ]
57+ readonly GitRepository GitRepository ;
4958
5059 Target Clean => _ => _
5160 . Executes ( ( ) =>
5261 {
5362 EnsureCleanDirectory ( PackOutputPath ) ;
54- // DotNetTasks.DotNetClean(s => s.SetProject(Solution));
55- DotNetTasks . DotNetClean ( ) ;
63+ DotNetTasks . DotNetClean ( s => s
64+ . SetProject ( Solution ) ) ;
5665 } ) ;
5766
5867 Target Compile => _ => _
5968 . DependsOn ( Clean )
6069 . Executes ( ( ) =>
6170 {
62- // DotNetTasks.DotNetBuild(s => s.SetProjectFile(Solution.VoxReader));
63- DotNetTasks . DotNetBuild ( s => s . SetConfiguration ( Configuration ) ) ;
71+ DotNetTasks . DotNetBuild ( s => s
72+ . SetProjectFile ( Solution )
73+ . SetConfiguration ( Configuration ) ) ;
6474 } ) ;
6575
6676 Target Test => _ => _
6777 . DependsOn ( Compile )
6878 . Executes ( ( ) =>
6979 {
70- // DotNetTasks.DotNetTest(s => s.SetProcessWorkingDirectory(RootDirectory));
71- DotNetTasks . DotNetTest ( s => s . SetConfiguration ( Configuration ) . SetLoggers ( "trx;logfilename=test-results.trx" ) ) ;
80+ DotNetTasks . DotNetTest ( s => s
81+ . SetProjectFile ( Solution )
82+ . SetConfiguration ( Configuration )
83+ . SetLoggers ( "trx;logfilename=test-results.trx" ) ) ;
7284 } ) ;
7385
74- // Target ExtractVersionFromTag => _ => _
75- // .Executes(() =>
76- // {
77- // bool success = Helper.IsValidVersionTag(CI_COMMIT_REF_NAME, out PackageVersion);
78- //
79- // if (!success)
80- // Logger.Normal($"Could not extract version from '{CI_COMMIT_REF_NAME}'");
81- //
82- // Logger.Info($"Package Version: {PackageVersion.ToString()}");
83- // });
86+ Target Pack => _ => _
87+ . DependsOn ( Test )
88+ . OnlyWhenStatic ( ( ) => GitRepository . CurrentCommitHasVersionTag ( ) )
89+ // .OnlyWhenStatic(() => Configuration == Configuration.Release)
90+ . Executes ( ( ) =>
91+ {
92+ Log . Information ( "Version: {Version}" , GitRepository . GetLatestVersionTag ( ) ) ;
93+ } ) ;
8494
8595 // Target Pack => _ => _
8696 // .DependsOn(Test)
0 commit comments