2
2
using System . Linq ;
3
3
using Nuke . Common ;
4
4
using Nuke . Common . CI ;
5
+ using Nuke . Common . CI . GitHubActions ;
5
6
using Nuke . Common . Execution ;
6
7
using Nuke . Common . Git ;
7
8
using Nuke . Common . IO ;
17
18
18
19
[ CheckBuildProjectConfigurations ]
19
20
[ ShutdownDotNetAfterServerBuild ]
21
+ [ GitHubActions ( "continous-integration" ,
22
+ GitHubActionsImage . UbuntuLatest ,
23
+ AutoGenerate = true ,
24
+ OnPushBranches = new [ ] { "master" } ,
25
+ OnPullRequestBranches = new [ ] { "*" } ,
26
+ InvokedTargets = new [ ] { nameof ( ContinousIntegration ) } ,
27
+ ImportSecrets = new [ ] { nameof ( NugetApiKey ) }
28
+ ) ]
20
29
class Build : NukeBuild
21
30
{
22
31
/// Support plugins are available for:
23
32
/// - JetBrains ReSharper https://nuke.build/resharper
24
33
/// - JetBrains Rider https://nuke.build/rider
25
34
/// - Microsoft VisualStudio https://nuke.build/visualstudio
26
35
/// - Microsoft VSCode https://nuke.build/vscode
27
-
28
- public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
36
+ public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
29
37
30
38
[ Parameter ( "Configuration to build - Default is 'Debug' (local) or 'Release' (server)" ) ]
31
39
readonly Configuration Configuration = IsLocalBuild ? Configuration . Debug : Configuration . Release ;
32
40
41
+ [ Parameter ] string NugetApiUrl = "https://api.nuget.org/v3/index.json" ; //default
42
+ [ Parameter ] string NugetApiKey ;
43
+
33
44
[ Solution ] readonly Solution Solution ;
34
45
[ GitRepository ] readonly GitRepository GitRepository ;
35
46
[ GitVersion ( Framework = "netcoreapp3.1" ) ] readonly GitVersion GitVersion ;
36
47
37
48
AbsolutePath SourceDirectory => RootDirectory / "src" ;
38
49
AbsolutePath TestsDirectory => RootDirectory / "tests" ;
39
50
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts" ;
51
+ AbsolutePath NugetDestinationDirectory => ArtifactsDirectory / "nuget" ;
52
+ AbsolutePath TestsResultDirectory => ArtifactsDirectory / "tests" ;
40
53
41
54
Target Clean => _ => _
42
55
. Before ( Restore )
43
56
. Executes ( ( ) =>
44
- {
45
- SourceDirectory . GlobDirectories ( "**/bin" , "**/obj" ) . ForEach ( DeleteDirectory ) ;
46
- TestsDirectory . GlobDirectories ( "**/bin" , "**/obj" ) . ForEach ( DeleteDirectory ) ;
47
- EnsureCleanDirectory ( ArtifactsDirectory ) ;
48
- } ) ;
57
+ {
58
+ SourceDirectory . GlobDirectories ( "**/bin" , "**/obj" )
59
+ . ForEach ( DeleteDirectory ) ;
60
+ TestsDirectory . GlobDirectories ( "**/bin" , "**/obj" )
61
+ . ForEach ( DeleteDirectory ) ;
62
+ EnsureCleanDirectory ( ArtifactsDirectory ) ;
63
+ }
64
+ ) ;
49
65
50
66
Target Restore => _ => _
51
67
. Executes ( ( ) =>
52
- {
53
- DotNetRestore ( s => s
54
- . SetProjectFile ( Solution ) ) ;
55
- } ) ;
68
+ {
69
+ DotNetRestore ( s => s
70
+ . SetProjectFile ( Solution )
71
+ ) ;
72
+ }
73
+ ) ;
56
74
57
75
Target Compile => _ => _
58
76
. DependsOn ( Restore )
59
77
. Executes ( ( ) =>
60
- {
61
- DotNetBuild ( s => s
62
- . SetProjectFile ( Solution )
63
- . SetConfiguration ( Configuration )
64
- . SetAssemblyVersion ( GitVersion . AssemblySemVer )
65
- . SetFileVersion ( GitVersion . AssemblySemFileVer )
66
- . SetInformationalVersion ( GitVersion . InformationalVersion )
67
- . EnableNoRestore ( ) ) ;
68
- } ) ;
78
+ {
79
+ DotNetBuild ( s => s
80
+ . SetProjectFile ( Solution )
81
+ . SetConfiguration ( Configuration )
82
+ . SetAssemblyVersion ( GitVersion . AssemblySemVer )
83
+ . SetFileVersion ( GitVersion . AssemblySemFileVer )
84
+ . SetInformationalVersion ( GitVersion . InformationalVersion )
85
+ . EnableNoRestore ( )
86
+ ) ;
87
+ }
88
+ ) ;
89
+
90
+ Target Test => _ => _
91
+ . DependsOn ( Compile )
92
+ . Executes ( ( ) =>
93
+ {
94
+ DotNetTest ( s => s
95
+ . SetProjectFile ( TestsDirectory )
96
+ . SetConfiguration ( Configuration )
97
+ . EnableNoBuild ( )
98
+ . EnableNoRestore ( )
99
+ . SetResultsDirectory ( TestsResultDirectory )
100
+ ) ;
101
+ }
102
+ ) ;
103
+
104
+ Target Pack => _ => _
105
+ . DependsOn ( Compile )
106
+ . Executes ( ( ) =>
107
+ {
108
+ DotNetPack ( s => s
109
+ . SetProject ( Solution )
110
+ . SetConfiguration ( Configuration )
111
+ . EnableNoBuild ( )
112
+ . EnableNoRestore ( )
113
+ . SetVersion ( GitVersion . NuGetVersionV2 )
114
+ . SetOutputDirectory ( NugetDestinationDirectory )
115
+ ) ;
116
+ }
117
+ ) ;
118
+
119
+ Target Deploy => _ => _
120
+ . DependsOn ( Pack )
121
+ . OnlyWhenStatic ( ( ) => GitRepository . Branch == "refs/heads/master" )
122
+ . Requires ( ( ) => NugetApiUrl )
123
+ . Requires ( ( ) => NugetApiKey )
124
+ . Requires ( ( ) => Configuration . Equals ( Configuration . Release ) )
125
+ . Executes ( ( ) =>
126
+ {
127
+ GlobFiles ( NugetDestinationDirectory , "*.nupkg" )
128
+ . NotEmpty ( )
129
+ . Where ( x => ! x . EndsWith ( "symbols.nupkg" ) )
130
+ . ForEach ( x =>
131
+ {
132
+ DotNetNuGetPush ( s => s
133
+ . SetSource ( NugetApiUrl )
134
+ . SetApiKey ( NugetApiKey )
135
+ . SetSkipDuplicate ( true )
136
+ ) ;
137
+ }
138
+ ) ;
139
+ }
140
+ ) ;
69
141
70
- }
142
+ Target ContinousIntegration => _ => _
143
+ . DependsOn ( Deploy ) ;
144
+ }
0 commit comments