2323 On = new [ ] { GitHubActionsTrigger . WorkflowDispatch } ,
2424 InvokedTargets = new [ ] { nameof ( Pack ) , nameof ( PublishToGitHubNuget ) } ,
2525 EnableGitHubToken = true
26- ) ]
26+ ) ]
2727[ GitHubActions (
2828 "Build main and publish to nuget" ,
2929 GitHubActionsImage . UbuntuLatest ,
3030 OnPushBranches = new [ ] { "main" } ,
3131 InvokedTargets = new [ ]
32- { nameof ( Clean ) , nameof ( Compile ) , nameof ( Pack ) , nameof ( PublishToGitHubNuget ) , nameof ( Publish ) } ,
32+ {
33+ nameof ( Clean ) ,
34+ nameof ( Compile ) ,
35+ nameof ( Pack ) ,
36+ nameof ( PublishToGitHubNuget ) ,
37+ nameof ( Publish ) ,
38+ } ,
3339 ImportSecrets = new [ ] { nameof ( NuGetApiKey ) } ,
3440 EnableGitHubToken = true
35- ) ]
41+ ) ]
3642class Build : NukeBuild
3743{
3844 readonly AbsolutePath ArtifactsDirectory = RootDirectory / "artifacts" ;
3945
4046 [ Parameter ( "Configuration to build - Default is 'Debug' (local) or 'Release' (server)" ) ]
41- readonly Configuration Configuration = IsLocalBuild ? Configuration . Debug : Configuration . Release ;
47+ readonly Configuration Configuration = IsLocalBuild
48+ ? Configuration . Debug
49+ : Configuration . Release ;
4250
43- [ LatestNuGetVersion (
44- "DotnetDispatcher" ,
45- IncludePrerelease = false ) ]
51+ [ LatestNuGetVersion ( "DotnetDispatcher" , IncludePrerelease = false ) ]
4652 readonly NuGetVersion DotnetDispatcherVersion ;
4753
48- [ Parameter ] [ Secret ] readonly string NuGetApiKey ;
54+ [ Parameter ]
55+ [ Secret ]
56+ readonly string NuGetApiKey ;
4957
50- [ GitRepository ] readonly GitRepository Repository ;
58+ [ GitRepository ]
59+ readonly GitRepository Repository ;
5160
52- [ Solution ( GenerateProjects = true ) ] readonly Solution Solution ;
61+ [ Solution ( GenerateProjects = true ) ]
62+ readonly Solution Solution ;
5363 GitHubActions GitHubActions => GitHubActions . Instance ;
5464
55- Target Clean => _ => _
56- . Before ( Restore )
57- . Executes ( ( ) =>
58- {
59- ArtifactsDirectory . CreateOrCleanDirectory ( ) ;
60- } ) ;
61-
62- Target Restore => _ => _
63- . Executes ( ( ) =>
64- {
65- DotNetRestore ( _ => _
66- . SetProjectFile ( Solution )
67- ) ;
68- } ) ;
69-
70- Target Compile => _ => _
71- . DependsOn ( Restore )
72- . Executes ( ( ) =>
73- {
74- DotNetBuild ( _ => _
75- . SetProjectFile ( Solution )
76- . SetConfiguration ( Configuration )
77- ) ;
78- } ) ;
79-
80- Target Test => _ => _
81- . DependsOn ( Compile )
82- . Executes ( ( ) =>
83- {
84- DotNetTest ( _ => _
85- . SetProjectFile ( Solution )
86- . SetConfiguration ( Configuration )
87- . SetNoBuild ( true )
88- . SetNoRestore ( true )
89- . SetVerbosity ( DotNetVerbosity . normal )
90- ) ;
91- } ) ;
92-
93- Target Pack => _ => _
94- . DependsOn ( Test )
95- . DependsOn ( Clean )
96- . Produces ( ArtifactsDirectory / "*.nupkg" )
97- . Executes ( ( ) =>
98- {
99- var newMajor = 0 ;
100- var newMinor = 8 ;
101- var newPatch = DotnetDispatcherVersion ? . Patch ?? 0 + 1 ;
102-
103- if ( DotnetDispatcherVersion != null )
65+ Target Clean =>
66+ _ =>
67+ _ . Before ( Restore )
68+ . Executes ( ( ) =>
69+ {
70+ ArtifactsDirectory . CreateOrCleanDirectory ( ) ;
71+ } ) ;
72+
73+ Target Restore =>
74+ _ =>
75+ _ . Executes ( ( ) =>
10476 {
105- if ( newMajor > DotnetDispatcherVersion . Major )
77+ DotNetRestore ( _ => _ . SetProjectFile ( Solution ) ) ;
78+ } ) ;
79+
80+ Target Compile =>
81+ _ =>
82+ _ . DependsOn ( Restore )
83+ . Executes ( ( ) =>
84+ {
85+ DotNetBuild ( _ => _ . SetProjectFile ( Solution ) . SetConfiguration ( Configuration ) ) ;
86+ } ) ;
87+
88+ Target Test =>
89+ _ =>
90+ _ . DependsOn ( Compile )
91+ . Executes ( ( ) =>
92+ {
93+ DotNetTest ( _ =>
94+ _ . SetProjectFile ( Solution )
95+ . SetConfiguration ( Configuration )
96+ . SetNoBuild ( true )
97+ . SetNoRestore ( true )
98+ . SetVerbosity ( DotNetVerbosity . normal )
99+ ) ;
100+ } ) ;
101+
102+ Target Pack =>
103+ _ =>
104+ _ . DependsOn ( Test )
105+ . DependsOn ( Clean )
106+ . Produces ( ArtifactsDirectory / "*.nupkg" )
107+ . Executes ( ( ) =>
108+ {
109+ var newMajor = 0 ;
110+ var newMinor = 8 ;
111+ var newPatch = DotnetDispatcherVersion ? . Patch ?? 0 + 1 ;
112+
113+ if ( DotnetDispatcherVersion != null )
114+ {
115+ if ( newMajor > DotnetDispatcherVersion . Major )
116+ {
117+ newMinor = 0 ;
118+ newPatch = 0 ;
119+ }
120+ else if ( newMinor > DotnetDispatcherVersion . Minor )
121+ {
122+ newPatch = 0 ;
123+ }
124+ }
125+
126+ var newVersion = new NuGetVersion (
127+ newMajor ,
128+ newMinor ,
129+ newPatch ,
130+ Repository . IsOnMainOrMasterBranch ( )
131+ ? null
132+ : $ "preview{ GitHubActions ? . RunNumber ?? 0 } "
133+ ) ;
134+
135+ DotNetPack ( _ =>
136+ _ . SetConfiguration ( Configuration )
137+ . SetOutputDirectory ( ArtifactsDirectory )
138+ . SetNoBuild ( true )
139+ . SetNoRestore ( true )
140+ . SetVersion ( newVersion . ToString ( ) )
141+ . SetVerbosity ( DotNetVerbosity . normal )
142+ . SetProject ( Solution . src . DotnetDispatcher )
143+ ) ;
144+ } ) ;
145+
146+ Target Publish =>
147+ _ =>
148+ _ . DependsOn ( Pack )
149+ . Consumes ( Pack )
150+ . Requires ( ( ) => NuGetApiKey )
151+ . Executes ( ( ) =>
106152 {
107- newMinor = 0 ;
108- newPatch = 0 ;
109- }
110- else if ( newMinor > DotnetDispatcherVersion . Minor )
153+ DotNetNuGetPush ( _ =>
154+ _ . SetTargetPath ( ArtifactsDirectory / "*.nupkg" )
155+ . SetSource ( "https://api.nuget.org/v3/index.json" )
156+ . SetApiKey ( NuGetApiKey )
157+ ) ;
158+ } ) ;
159+
160+ Target PublishToGitHubNuget =>
161+ _ =>
162+ _ . DependsOn ( Pack )
163+ . Consumes ( Pack )
164+ . Executes ( ( ) =>
111165 {
112- newPatch = 0 ;
113- }
114- }
115-
116- var newVersion = new NuGetVersion ( newMajor , newMinor , newPatch ,
117- Repository . IsOnMainOrMasterBranch ( ) ? null : $ "preview{ GitHubActions ? . RunNumber ?? 0 } ") ;
118-
119- DotNetPack ( _ => _
120- . SetConfiguration ( Configuration )
121- . SetOutputDirectory ( ArtifactsDirectory )
122- . SetNoBuild ( true )
123- . SetNoRestore ( true )
124- . SetVersion ( newVersion . ToString ( ) )
125- . SetVerbosity ( DotNetVerbosity . normal )
126- . SetProject ( Solution . src . DotnetDispatcher )
127- ) ;
128- } ) ;
129-
130- Target Publish => _ => _
131- . DependsOn ( Pack )
132- . Consumes ( Pack )
133- . Requires ( ( ) => NuGetApiKey )
134- . Executes ( ( ) =>
135- {
136- DotNetNuGetPush ( _ => _
137- . SetTargetPath ( ArtifactsDirectory / "*.nupkg" )
138- . SetSource ( "https://api.nuget.org/v3/index.json" )
139- . SetApiKey ( NuGetApiKey )
140- ) ;
141- } ) ;
142-
143- Target PublishToGitHubNuget => _ => _
144- . DependsOn ( Pack )
145- . Consumes ( Pack )
146- . Executes ( ( ) =>
147- {
148- DotNetNuGetPush ( _ => _
149- . SetTargetPath ( ArtifactsDirectory / "*.nupkg" )
150- . SetSource ( "https://nuget.pkg.github.com/psimsa/index.json" )
151- . SetApiKey ( GitHubActions . Token )
152- ) ;
153- } ) ;
166+ DotNetNuGetPush ( _ =>
167+ _ . SetTargetPath ( ArtifactsDirectory / "*.nupkg" )
168+ . SetSource ( "https://nuget.pkg.github.com/psimsa/index.json" )
169+ . SetApiKey ( GitHubActions . Token )
170+ ) ;
171+ } ) ;
154172
155173 /// Support plugins are available for:
156174 /// - JetBrains ReSharper https://nuke.build/resharper
157175 /// - JetBrains Rider https://nuke.build/rider
158176 /// - Microsoft VisualStudio https://nuke.build/visualstudio
159177 /// - Microsoft VSCode https://nuke.build/vscode
160178 public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
161- }
179+ }
0 commit comments