1+ #addin "nuget:?package=Cake.FileHelpers"
12#addin "nuget:?package=Cake.Git"
23#addin "nuget:?package=Cake.Incubator"
34#tool "nuget:?package=GitVersion.CommandLine"
45#tool "nuget:?package=xunit.runner.console"
56#load buildhelpers . cake
67
8+ using System . Text . RegularExpressions ;
9+
710var target = Argument ( "target" , "Default" ) ;
811var configuration = Argument ( "configuration" , "Release" ) ;
912
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+ } ;
1335
14- var solutionFile = solutionDirectory + File ( "CSharpDriver.sln" ) ;
1536var gitVersion = GitVersion ( ) ;
1637
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" ) ;
3448
3549Task ( "BuildNet45" )
3650 . Does ( ( ) =>
@@ -39,7 +53,22 @@ Task("BuildNet45")
3953 GlobalAssemblyInfo . OverwriteGlobalAssemblyInfoFile ( Context , solutionDirectory , configuration , gitVersion ) ;
4054 DotNetBuild ( solutionFile , settings => settings
4155 . 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+ }
4372 } )
4473 . Finally ( ( ) =>
4574 {
@@ -55,15 +84,35 @@ Task("BuildNetStandard15")
5584 {
5685 Configuration = configuration
5786 } ) ;
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+ }
58101 } )
59102 . Finally ( ( ) =>
60103 {
61104 GlobalAssemblyInfo . RestoreGlobalAssemblyInfoFile ( Context , solutionDirectory ) ;
62105 } ) ;
63106
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" ) ;
67116
68117Task ( "TestNet45" )
69118 . IsDependentOn ( "BuildNet45" )
@@ -82,7 +131,7 @@ Task("TestNetStandard15")
82131 . IsDependentOn ( "BuildNetStandard15" )
83132 . Does ( ( ) =>
84133 {
85- var testsDirectory = solutionDirectory + Directory ( "tests" ) ;
134+ var testsDirectory = solutionDirectory . Combine ( "tests" ) ;
86135 var testProjectNames = new [ ]
87136 {
88137 "MongoDB.Bson.Tests.Dotnet" ,
@@ -93,8 +142,8 @@ Task("TestNetStandard15")
93142 } ;
94143 foreach ( var testProjectName in testProjectNames )
95144 {
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" ) ;
98147 var testSettings = new DotNetCoreTestSettings ( ) ;
99148 var xunitSettings = new XUnit2Settings
100149 {
@@ -105,85 +154,174 @@ Task("TestNetStandard15")
105154 }
106155 } ) ;
107156
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" ) ;
117160
118161Task ( "ApiDocs" )
162+ . IsDependentOn ( "BuildNet45" )
119163 . Does ( ( ) =>
120164 {
121- var tempDirectory = artifactsDirectory + Directory ( "tmp" ) ;
122- EnsureDirectoryExists ( tempDirectory ) ;
123- CleanDirectory ( tempDirectory ) ;
165+ EnsureDirectoryExists ( docsApiOutputDirectory ) ;
166+ CleanDirectory ( docsApiOutputDirectory ) ;
124167
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
129170 MSBuild ( shfbprojFile , new MSBuildSettings
130171 {
131172 Configuration = "Release"
132173 }
133- . WithProperty ( "OutputPath" , tempDirectory )
174+ . WithProperty ( "OutputPath" , docsApiOutputDirectory . ToString ( ) )
134175 . WithProperty ( "CleanIntermediate" , "True" )
135176 . WithProperty ( "Preliminary" , preliminary ? "True" : "False" )
136- . WithProperty ( "HelpFileVersion" , helpFileVersion )
177+ . WithProperty ( "HelpFileVersion" , gitVersion . MajorMinorPatch )
137178 ) ;
138179
139- // DeleteDirectory(tempDirectory , recursive: true);
180+ // DeleteDirectory(docsApiOutputDirectory , recursive: true);
140181 } ) ;
141182
142183Task ( "RefDocs" )
143184 . Does ( ( ) =>
144185 {
145- var hugoDirectory = toolsDirectory + Directory ( "Hugo" ) ;
186+ var hugoDirectory = toolsDirectory . Combine ( "Hugo" ) ;
146187 EnsureDirectoryExists ( hugoDirectory ) ;
147188 CleanDirectory ( hugoDirectory ) ;
148189
149190 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" ) ;
151192 DownloadFile ( url , zipFile ) ;
152193 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" ) ;
154195
155- var landingDirectory = solutionDirectory + Directory ( "docs" ) + Directory ( "landing" ) ;
196+ var landingDirectory = solutionDirectory . Combine ( "docs" ) . Combine ( "landing" ) ;
156197 var processSettings = new ProcessSettings
157198 {
158199 WorkingDirectory = landingDirectory
159200 } ;
160201 StartProcess ( hugoExe , processSettings ) ;
161202
162- var referenceDirectory = solutionDirectory + Directory ( "docs" ) + Directory ( "reference" ) ;
203+ var referenceDirectory = solutionDirectory . Combine ( "docs" ) . Combine ( "reference" ) ;
163204 processSettings = new ProcessSettings
164205 {
165206 WorkingDirectory = referenceDirectory
166207 } ;
167208 StartProcess ( hugoExe , processSettings ) ;
168209
169- var tempDirectory = artifactsDirectory + Directory ( "tmp ") ;
210+ var tempDirectory = artifactsDirectory . Combine ( "RefDocs ") ;
170211 EnsureDirectoryExists ( tempDirectory ) ;
171212 CleanDirectory ( tempDirectory ) ;
172213
173- var landingPublicDirectory = landingDirectory + Directory ( "public" ) ;
214+ var landingPublicDirectory = landingDirectory . Combine ( "public" ) ;
174215 CopyDirectory ( landingPublicDirectory , tempDirectory ) ;
175216
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 ) ;
179220
180- var referenceDocsZipFile = artifactsDirectory + File ( "RefDocs-" + gitVersion . SemVer + "-html.zip" ) ;
221+ var referenceDocsZipFile = artifactsDirectory . CombineWithFilePath ( "RefDocs-" + gitVersion . SemVer + "-html.zip" ) ;
181222 Zip ( tempDirectory , referenceDocsZipFile ) ;
182223
183224 DeleteDirectory ( tempDirectory , recursive : true ) ;
184225 } ) ;
185226
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+ } ) ;
188326
189327RunTarget ( target ) ;
0 commit comments