1
+ #addin "nuget:?package=Cake.FileHelpers"
1
2
#addin "nuget:?package=Cake.Git"
2
3
#addin "nuget:?package=Cake.Incubator"
3
4
#tool "nuget:?package=GitVersion.CommandLine"
4
5
#tool "nuget:?package=xunit.runner.console"
5
6
#load buildhelpers . cake
6
7
8
+ using System . Text . RegularExpressions ;
9
+
7
10
var target = Argument ( "target" , "Default" ) ;
8
11
var configuration = Argument ( "configuration" , "Release" ) ;
9
12
10
- var solutionDirectory = Directory ( "./" ) ;
11
- var artifactsDirectory = solutionDirectory + Directory ( "artifacts" ) ;
12
- var toolsDirectory = solutionDirectory + Directory ( "Tools" ) ;
13
+ var solutionDirectory = MakeAbsolute ( Directory ( "./" ) ) ;
14
+ var artifactsDirectory = solutionDirectory . Combine ( "artifacts" ) ;
15
+ var artifactsBinDirectory = artifactsDirectory . Combine ( "bin" ) ;
16
+ var artifactsBinNet45Directory = artifactsBinDirectory . Combine ( "net45" ) ;
17
+ var artifactsBinNetStandard15Directory = artifactsBinDirectory . Combine ( "netstandard1.5" ) ;
18
+ var artifactsPackagesDirectory = artifactsDirectory . Combine ( "packages" ) ;
19
+ var docsDirectory = solutionDirectory . Combine ( "Docs" ) ;
20
+ var docsApiDirectory = docsDirectory . Combine ( "Api" ) ;
21
+ var docsApiOutputDirectory = docsApiDirectory . Combine ( "output" ) ;
22
+ var srcDirectory = solutionDirectory . Combine ( "src" ) ;
23
+ var testsDirectory = solutionDirectory . Combine ( "tests" ) ;
24
+ var toolsDirectory = solutionDirectory . Combine ( "Tools" ) ;
25
+
26
+ var solutionFile = solutionDirectory . CombineWithFilePath ( "CSharpDriver.sln" ) ;
27
+ var srcProjectNames = new [ ]
28
+ {
29
+ "MongoDB.Bson" ,
30
+ "MongoDB.Driver.Core" ,
31
+ "MongoDB.Driver" ,
32
+ "MongoDB.Driver.Legacy" ,
33
+ "MongoDB.Driver.GridFS"
34
+ } ;
13
35
14
- var solutionFile = solutionDirectory + File ( "CSharpDriver.sln" ) ;
15
36
var gitVersion = GitVersion ( ) ;
16
37
17
- Task ( "EchoGitVersion" )
18
- . Does ( ( ) =>
19
- {
20
- Information ( "AssemblySemVer = {0}" , gitVersion . AssemblySemVer ) ;
21
- Information ( "CommitsSinceVersionSource = {0}" , gitVersion . CommitsSinceVersionSource ) ;
22
- Information ( "FullSemVer = {0}" , gitVersion . FullSemVer ) ;
23
- Information ( "InformationalVersion = {0}" , gitVersion . InformationalVersion ) ;
24
- Information ( "LegacySemVer = {0}" , gitVersion . LegacySemVer ) ;
25
- Information ( "NuGetVersion = {0}" , gitVersion . NuGetVersion ) ;
26
- Information ( "NuGetVersionV2 = {0}" , gitVersion . NuGetVersionV2 ) ;
27
- Information ( "Patch = {0}" , gitVersion . Patch ) ;
28
- Information ( "PreReleaseLabel = {0}" , gitVersion . PreReleaseLabel ) ;
29
- Information ( "PreReleaseNumber = {0}" , gitVersion . PreReleaseNumber ) ;
30
- Information ( "PreReleaseTag = {0}" , gitVersion . PreReleaseTag ) ;
31
- Information ( "PreReleaseTagWithDash = {0}" , gitVersion . PreReleaseTagWithDash ) ;
32
- Information ( "SemVer = {0}" , gitVersion . SemVer ) ;
33
- } ) ;
38
+ Task ( "Default" )
39
+ . IsDependentOn ( "TestAndPublish" ) ;
40
+
41
+ Task ( "TestAndPublish" )
42
+ . IsDependentOn ( "Test" )
43
+ . IsDependentOn ( "Publish" ) ;
44
+
45
+ Task ( "Build" )
46
+ . IsDependentOn ( "BuildNet45" )
47
+ . IsDependentOn ( "BuildNetStandard15" ) ;
34
48
35
49
Task ( "BuildNet45" )
36
50
. Does ( ( ) =>
@@ -39,7 +53,22 @@ Task("BuildNet45")
39
53
GlobalAssemblyInfo . OverwriteGlobalAssemblyInfoFile ( Context , solutionDirectory , configuration , gitVersion ) ;
40
54
DotNetBuild ( solutionFile , settings => settings
41
55
. SetConfiguration ( configuration )
42
- . SetVerbosity ( Verbosity . Minimal ) ) ;
56
+ . SetVerbosity ( Verbosity . Minimal )
57
+ . WithProperty ( "TargetFrameworkVersion" , "v4.5" ) ) ;
58
+
59
+ EnsureDirectoryExists ( artifactsBinNet45Directory ) ;
60
+ foreach ( var projectName in srcProjectNames )
61
+ {
62
+ var projectDirectory = srcDirectory . Combine ( projectName ) ;
63
+ var outputDirectory = projectDirectory . Combine ( "bin" ) . Combine ( configuration ) ;
64
+ foreach ( var extension in new [ ] { ".dll" , ".pdb" , ".xml" } )
65
+ {
66
+ var outputFileName = projectName + extension ;
67
+ var outputFile = outputDirectory . CombineWithFilePath ( outputFileName ) ;
68
+ var artifactFile = artifactsBinNet45Directory . CombineWithFilePath ( outputFileName ) ;
69
+ CopyFile ( outputFile , artifactFile ) ;
70
+ }
71
+ }
43
72
} )
44
73
. Finally ( ( ) =>
45
74
{
@@ -55,15 +84,35 @@ Task("BuildNetStandard15")
55
84
{
56
85
Configuration = configuration
57
86
} ) ;
87
+
88
+ EnsureDirectoryExists ( artifactsBinNetStandard15Directory ) ;
89
+ foreach ( var projectName in srcProjectNames )
90
+ {
91
+ var projectDirectory = srcDirectory . Combine ( projectName + ".Dotnet" ) ;
92
+ var outputDirectory = projectDirectory . Combine ( "bin" ) . Combine ( configuration ) . Combine ( "netstandard1.5" ) ;
93
+ foreach ( var extension in new [ ] { ".dll" , ".pdb" , ".xml" } )
94
+ {
95
+ var outputFileName = projectName + extension ;
96
+ var outputFile = outputDirectory . CombineWithFilePath ( outputFileName ) ;
97
+ var artifactFile = artifactsBinNetStandard15Directory . CombineWithFilePath ( outputFileName ) ;
98
+ CopyFile ( outputFile , artifactFile ) ;
99
+ }
100
+ }
58
101
} )
59
102
. Finally ( ( ) =>
60
103
{
61
104
GlobalAssemblyInfo . RestoreGlobalAssemblyInfoFile ( Context , solutionDirectory ) ;
62
105
} ) ;
63
106
64
- Task ( "Build" )
65
- . IsDependentOn ( "BuildNet45" )
66
- . IsDependentOn ( "BuildNetStandard15" ) ;
107
+ Task ( "Test" )
108
+ . IsDependentOn ( "TestWindows" ) ;
109
+
110
+ Task ( "TestWindows" )
111
+ . IsDependentOn ( "TestNet45" )
112
+ . IsDependentOn ( "TestNetStandard15" ) ;
113
+
114
+ Task ( "TestLinux" )
115
+ . IsDependentOn ( "TestNetStandard15" ) ;
67
116
68
117
Task ( "TestNet45" )
69
118
. IsDependentOn ( "BuildNet45" )
@@ -82,7 +131,7 @@ Task("TestNetStandard15")
82
131
. IsDependentOn ( "BuildNetStandard15" )
83
132
. Does ( ( ) =>
84
133
{
85
- var testsDirectory = solutionDirectory + Directory ( "tests" ) ;
134
+ var testsDirectory = solutionDirectory . Combine ( "tests" ) ;
86
135
var testProjectNames = new [ ]
87
136
{
88
137
"MongoDB.Bson.Tests.Dotnet" ,
@@ -93,8 +142,8 @@ Task("TestNetStandard15")
93
142
} ;
94
143
foreach ( var testProjectName in testProjectNames )
95
144
{
96
- var testProjectDirectory = testsDirectory + Directory ( testProjectName ) ;
97
- var testProjectFile = testProjectDirectory + File ( "project.json" ) ;
145
+ var testProjectDirectory = testsDirectory . Combine ( testProjectName ) ;
146
+ var testProjectFile = testProjectDirectory . CombineWithFilePath ( "project.json" ) ;
98
147
var testSettings = new DotNetCoreTestSettings ( ) ;
99
148
var xunitSettings = new XUnit2Settings
100
149
{
@@ -105,85 +154,174 @@ Task("TestNetStandard15")
105
154
}
106
155
} ) ;
107
156
108
- Task ( "TestWindows" )
109
- . IsDependentOn ( "TestNet45" )
110
- . IsDependentOn ( "TestNetStandard15" ) ;
111
-
112
- Task ( "TestLinux" )
113
- . IsDependentOn ( "TestNetStandard15" ) ;
114
-
115
- Task ( "Test" )
116
- . IsDependentOn ( "TestWindows" ) ;
157
+ Task ( "Docs" )
158
+ . IsDependentOn ( "ApiDocs" )
159
+ . IsDependentOn ( "RefDocs" ) ;
117
160
118
161
Task ( "ApiDocs" )
162
+ . IsDependentOn ( "BuildNet45" )
119
163
. Does ( ( ) =>
120
164
{
121
- var tempDirectory = artifactsDirectory + Directory ( "tmp" ) ;
122
- EnsureDirectoryExists ( tempDirectory ) ;
123
- CleanDirectory ( tempDirectory ) ;
165
+ EnsureDirectoryExists ( docsApiOutputDirectory ) ;
166
+ CleanDirectory ( docsApiOutputDirectory ) ;
124
167
125
- var apiDocsDirectory = solutionDirectory + Directory ( "Docs" ) + Directory ( "Api" ) ;
126
- var shfbprojFile = apiDocsDirectory + File ( "CSharpDriverDocs.shfbproj" ) ;
127
- var preliminary = true ;
128
- var helpFileVersion = "2.4.4" ; // should have build number?
168
+ var shfbprojFile = docsApiDirectory . CombineWithFilePath ( "CSharpDriverDocs.shfbproj" ) ;
169
+ var preliminary = false ; // TODO: compute
129
170
MSBuild ( shfbprojFile , new MSBuildSettings
130
171
{
131
172
Configuration = "Release"
132
173
}
133
- . WithProperty ( "OutputPath" , tempDirectory )
174
+ . WithProperty ( "OutputPath" , docsApiOutputDirectory . ToString ( ) )
134
175
. WithProperty ( "CleanIntermediate" , "True" )
135
176
. WithProperty ( "Preliminary" , preliminary ? "True" : "False" )
136
- . WithProperty ( "HelpFileVersion" , helpFileVersion )
177
+ . WithProperty ( "HelpFileVersion" , gitVersion . MajorMinorPatch )
137
178
) ;
138
179
139
- // DeleteDirectory(tempDirectory , recursive: true);
180
+ // DeleteDirectory(docsApiOutputDirectory , recursive: true);
140
181
} ) ;
141
182
142
183
Task ( "RefDocs" )
143
184
. Does ( ( ) =>
144
185
{
145
- var hugoDirectory = toolsDirectory + Directory ( "Hugo" ) ;
186
+ var hugoDirectory = toolsDirectory . Combine ( "Hugo" ) ;
146
187
EnsureDirectoryExists ( hugoDirectory ) ;
147
188
CleanDirectory ( hugoDirectory ) ;
148
189
149
190
var url = "https://github.com/spf13/hugo/releases/download/v0.13/hugo_0.13_windows_amd64.zip" ;
150
- var zipFile = hugoDirectory + File ( "hugo_0.13_windows_amd64.zip" ) ;
191
+ var zipFile = hugoDirectory . CombineWithFilePath ( "hugo_0.13_windows_amd64.zip" ) ;
151
192
DownloadFile ( url , zipFile ) ;
152
193
Unzip ( zipFile , hugoDirectory ) ;
153
- var hugoExe = hugoDirectory + File ( "hugo_0.13_windows_amd64.exe" ) ;
194
+ var hugoExe = hugoDirectory . CombineWithFilePath ( "hugo_0.13_windows_amd64.exe" ) ;
154
195
155
- var landingDirectory = solutionDirectory + Directory ( "docs" ) + Directory ( "landing" ) ;
196
+ var landingDirectory = solutionDirectory . Combine ( "docs" ) . Combine ( "landing" ) ;
156
197
var processSettings = new ProcessSettings
157
198
{
158
199
WorkingDirectory = landingDirectory
159
200
} ;
160
201
StartProcess ( hugoExe , processSettings ) ;
161
202
162
- var referenceDirectory = solutionDirectory + Directory ( "docs" ) + Directory ( "reference" ) ;
203
+ var referenceDirectory = solutionDirectory . Combine ( "docs" ) . Combine ( "reference" ) ;
163
204
processSettings = new ProcessSettings
164
205
{
165
206
WorkingDirectory = referenceDirectory
166
207
} ;
167
208
StartProcess ( hugoExe , processSettings ) ;
168
209
169
- var tempDirectory = artifactsDirectory + Directory ( "tmp ") ;
210
+ var tempDirectory = artifactsDirectory . Combine ( "RefDocs ") ;
170
211
EnsureDirectoryExists ( tempDirectory ) ;
171
212
CleanDirectory ( tempDirectory ) ;
172
213
173
- var landingPublicDirectory = landingDirectory + Directory ( "public" ) ;
214
+ var landingPublicDirectory = landingDirectory . Combine ( "public" ) ;
174
215
CopyDirectory ( landingPublicDirectory , tempDirectory ) ;
175
216
176
- var referencePublicDirectory = referenceDirectory + Directory ( "public" ) ;
177
- var referencePublicDestinationDirectory = tempDirectory + Directory ( gitVersion . Major + "." + gitVersion . Minor ) ;
178
- CopyDirectory ( referencePublicDirectory , referencePublicDestinationDirectory ) ;
217
+ var referencePublicDirectory = referenceDirectory . Combine ( "public" ) ;
218
+ var referencePublicVersionDirectory = tempDirectory . Combine ( gitVersion . Major + "." + gitVersion . Minor ) ;
219
+ CopyDirectory ( referencePublicDirectory , referencePublicVersionDirectory ) ;
179
220
180
- var referenceDocsZipFile = artifactsDirectory + File ( "RefDocs-" + gitVersion . SemVer + "-html.zip" ) ;
221
+ var referenceDocsZipFile = artifactsDirectory . CombineWithFilePath ( "RefDocs-" + gitVersion . SemVer + "-html.zip" ) ;
181
222
Zip ( tempDirectory , referenceDocsZipFile ) ;
182
223
183
224
DeleteDirectory ( tempDirectory , recursive : true ) ;
184
225
} ) ;
185
226
186
- Task ( "Default" )
187
- . IsDependentOn ( "Build" ) ;
227
+ Task ( "Package" )
228
+ . IsDependentOn ( "PackageReleaseZipFile" )
229
+ . IsDependentOn ( "PackageNugetPackages" ) ;
230
+
231
+ Task ( "PackageReleaseZipFile" )
232
+ . IsDependentOn ( "BuildNet45" )
233
+ . IsDependentOn ( "BuildNetStandard15" )
234
+ . IsDependentOn ( "ApiDocs" )
235
+ . Does ( ( ) =>
236
+ {
237
+ var assemblySemVer = gitVersion . AssemblySemVer ; // e.g. 2.4.4.0
238
+ var majorMinorBuild = Regex . Replace ( assemblySemVer , @"\.\d+$" , "" ) ; // e.g. 2.4.4
239
+
240
+ var stagingDirectoryName = "CSharpDriver-" + majorMinorBuild ;
241
+ var stagingDirectory = artifactsDirectory . Combine ( stagingDirectoryName ) ;
242
+ EnsureDirectoryExists ( stagingDirectory ) ;
243
+ CleanDirectory ( stagingDirectory ) ;
244
+
245
+ var stagingNet45Directory = stagingDirectory . Combine ( "net45" ) ;
246
+ CopyDirectory ( artifactsBinNet45Directory , stagingNet45Directory ) ;
247
+
248
+ var stagingNetStandard15Directory = stagingDirectory . Combine ( "netstandard1.5" ) ;
249
+ CopyDirectory ( artifactsBinNetStandard15Directory , stagingNetStandard15Directory ) ;
250
+
251
+ var chmFile = docsApiOutputDirectory . CombineWithFilePath ( "CSharpDriverDocs.chm" ) ;
252
+ var stagingChmFileName = stagingDirectoryName + ".chm" ;
253
+ var stagingChmFile = stagingDirectory . CombineWithFilePath ( stagingChmFileName ) ;
254
+ CopyFile ( chmFile , stagingChmFile ) ;
255
+
256
+ var licenseFile = solutionDirectory . CombineWithFilePath ( "license.txt" ) ;
257
+ var stagingLicenseFile = stagingDirectory . CombineWithFilePath ( "license.txt" ) ;
258
+ CopyFile ( licenseFile , stagingLicenseFile ) ;
259
+
260
+ var releaseNotesFileName = "Release Notes v" + majorMinorBuild + ".md" ;
261
+ var releaseNotesDirectory = solutionDirectory . Combine ( "Release Notes" ) ;
262
+ var releaseNotesFile = releaseNotesDirectory . CombineWithFilePath ( releaseNotesFileName ) ;
263
+ var stagingDirectoryReleaseNotesFile = stagingDirectory . CombineWithFilePath ( releaseNotesFileName ) ;
264
+ CopyFile ( releaseNotesFile , stagingDirectoryReleaseNotesFile ) ;
265
+
266
+ var zipFileName = stagingDirectoryName + ".zip" ;
267
+ var zipFile = artifactsDirectory . CombineWithFilePath ( zipFileName ) ;
268
+ Zip ( stagingDirectory , zipFile ) ;
269
+
270
+ DeleteDirectory ( stagingDirectory , recursive : true ) ;
271
+ } ) ;
272
+
273
+ Task ( "PackageNugetPackages" )
274
+ . IsDependentOn ( "BuildNet45" )
275
+ . IsDependentOn ( "BuildNetStandard15" )
276
+ . Does ( ( ) =>
277
+ {
278
+ EnsureDirectoryExists ( artifactsPackagesDirectory ) ;
279
+ CleanDirectory ( artifactsPackagesDirectory ) ;
280
+
281
+ var packageVersion = gitVersion . MajorMinorPatch ;
282
+
283
+ var nuspecFiles = GetFiles ( "./Build/*.nuspec" ) ;
284
+ foreach ( var nuspecFile in nuspecFiles )
285
+ {
286
+ var tempNuspecFilename = nuspecFile . GetFilenameWithoutExtension ( ) . ToString ( ) + "." + packageVersion + ".nuspec" ;
287
+ var tempNuspecFile = artifactsPackagesDirectory . CombineWithFilePath ( tempNuspecFilename ) ;
288
+
289
+ CopyFile ( nuspecFile , tempNuspecFile ) ;
290
+ ReplaceTextInFiles ( tempNuspecFile . ToString ( ) , "@driverPackageVersion@" , packageVersion ) ;
291
+ ReplaceTextInFiles ( tempNuspecFile . ToString ( ) , "@solutionDirectory@" , solutionDirectory . FullPath ) ;
292
+
293
+ NuGetPack ( tempNuspecFile , new NuGetPackSettings
294
+ {
295
+ OutputDirectory = artifactsPackagesDirectory ,
296
+ Symbols = true
297
+ } ) ;
298
+
299
+ // DeleteFile(tempNuspecFile);
300
+ }
301
+ } ) ;
302
+
303
+ Task ( "Publish" )
304
+ . IsDependentOn ( "PublishToGithub" )
305
+ . IsDependentOn ( "PublishToMyget" ) ;
306
+
307
+ Task ( "PublishToGithub" )
308
+ . IsDependentOn ( "PackageReleaseZipFile" )
309
+ . Does ( ( ) =>
310
+ {
311
+ // publishing to github is done manually
312
+ } ) ;
313
+
314
+ Task ( "PublishToMyget" )
315
+ . IsDependentOn ( "PackageNugetPackages" )
316
+ . Does ( ( ) =>
317
+ {
318
+ Console . WriteLine ( "PublishToMyget is not implemented." ) ;
319
+ } ) ;
320
+
321
+ Task ( "DumpGitVersion" )
322
+ . Does ( ( ) =>
323
+ {
324
+ Information ( gitVersion . Dump ( ) ) ;
325
+ } ) ;
188
326
189
327
RunTarget ( target ) ;
0 commit comments