|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | +// ARGUMENTS |
| 3 | +/////////////////////////////////////////////////////////////////////////////// |
| 4 | + |
| 5 | +var target = Argument<string>("target", "Default"); |
| 6 | +var configuration = Argument<string>("configuration", "Release"); |
| 7 | + |
| 8 | +////////////////////////////////////////////////////////////////////// |
| 9 | +// EXTERNAL NUGET TOOLS |
| 10 | +////////////////////////////////////////////////////////////////////// |
| 11 | + |
| 12 | +#Tool "xunit.runner.console" |
| 13 | +#Tool "GitVersion.CommandLine" |
| 14 | + |
| 15 | +////////////////////////////////////////////////////////////////////// |
| 16 | +// EXTERNAL NUGET LIBRARIES |
| 17 | +////////////////////////////////////////////////////////////////////// |
| 18 | + |
| 19 | +#addin "System.Text.Json" |
| 20 | +using System.Text.Json; |
| 21 | + |
| 22 | +/////////////////////////////////////////////////////////////////////////////// |
| 23 | +// GLOBAL VARIABLES |
| 24 | +/////////////////////////////////////////////////////////////////////////////// |
| 25 | + |
| 26 | +var projectName = "Polly"; |
| 27 | + |
| 28 | +var solutions = GetFiles("./**/*.sln"); |
| 29 | +var solutionPaths = solutions.Select(solution => solution.GetDirectory()); |
| 30 | + |
| 31 | +var srcDir = Directory("./src"); |
| 32 | +var buildDir = Directory("./build"); |
| 33 | +var artifactsDir = Directory("./artifacts"); |
| 34 | +var testResultsDir = artifactsDir + Directory("test-results"); |
| 35 | + |
| 36 | +// NuGet |
| 37 | +var nuspecFilename = projectName + ".nuspec"; |
| 38 | +var nuspecSrcFile = srcDir + File(nuspecFilename); |
| 39 | +var nuspecDestFile = buildDir + File(nuspecFilename); |
| 40 | +var nupkgDestDir = artifactsDir + Directory("nuget-package"); |
| 41 | + |
| 42 | +var projectToNugetFolderMap = new Dictionary<string, string>() { |
| 43 | + { "Net35", "net35" }, |
| 44 | + { "Net40", "net40" }, |
| 45 | + { "Net45", "net45" }, |
| 46 | + { "Pcl", "portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS" } |
| 47 | +}; |
| 48 | + |
| 49 | +// Gitversion |
| 50 | +var gitVersionPath = ToolsExePath("GitVersion.exe"); |
| 51 | +Dictionary<string, object> gitVersionOutput; |
| 52 | + |
| 53 | +var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor; |
| 54 | + |
| 55 | +/////////////////////////////////////////////////////////////////////////////// |
| 56 | +// SETUP / TEARDOWN |
| 57 | +/////////////////////////////////////////////////////////////////////////////// |
| 58 | + |
| 59 | +Setup(() => |
| 60 | +{ |
| 61 | + |
| 62 | +}); |
| 63 | + |
| 64 | +Teardown(() => |
| 65 | +{ |
| 66 | + Information("Finished running tasks."); |
| 67 | +}); |
| 68 | + |
| 69 | +////////////////////////////////////////////////////////////////////// |
| 70 | +// PRIVATE TASKS |
| 71 | +////////////////////////////////////////////////////////////////////// |
| 72 | + |
| 73 | +Task("__Clean") |
| 74 | + .Does(() => |
| 75 | +{ |
| 76 | + CleanDirectories(new DirectoryPath[] { |
| 77 | + buildDir, |
| 78 | + artifactsDir, |
| 79 | + testResultsDir, |
| 80 | + nupkgDestDir |
| 81 | + }); |
| 82 | + |
| 83 | + foreach(var path in solutionPaths) |
| 84 | + { |
| 85 | + Information("Cleaning {0}", path); |
| 86 | + CleanDirectories(path + "/**/bin/" + configuration); |
| 87 | + CleanDirectories(path + "/**/obj/" + configuration); |
| 88 | + } |
| 89 | +}); |
| 90 | + |
| 91 | +Task("__RestoreNugetPackages") |
| 92 | + .Does(() => |
| 93 | +{ |
| 94 | + foreach(var solution in solutions) |
| 95 | + { |
| 96 | + Information("Restoring NuGet Packages for {0}", solution); |
| 97 | + NuGetRestore(solution); |
| 98 | + } |
| 99 | +}); |
| 100 | + |
| 101 | +Task("__UpdateAssemblyVersionInformation") |
| 102 | + .Does(() => |
| 103 | +{ |
| 104 | + |
| 105 | + var gitVersionSettings = new ProcessSettings() |
| 106 | + .SetRedirectStandardOutput(true) |
| 107 | + .WithArguments(args => args |
| 108 | + .Append("/updateassemblyinfo") |
| 109 | + .AppendQuoted(@".\src\GlobalAssemblyInfo.cs")); |
| 110 | + |
| 111 | + IEnumerable<string> outputLines; |
| 112 | + StartProcess(gitVersionPath, gitVersionSettings, out outputLines); |
| 113 | + |
| 114 | + var output = string.Join("\n", outputLines); |
| 115 | + gitVersionOutput = new JsonParser().Parse<Dictionary<string, object>>(output); |
| 116 | + |
| 117 | + Information("Updated GlobalAssemblyInfo"); |
| 118 | + Information("AssemblyVersion -> {0}", gitVersionOutput["AssemblySemVer"]); |
| 119 | + Information("AssemblyFileVersion -> {0}", gitVersionOutput["MajorMinorPatch"]); |
| 120 | + Information("AssemblyInformationalVersion -> {0}", gitVersionOutput["InformationalVersion"]); |
| 121 | +}); |
| 122 | + |
| 123 | +Task("__UpdateAppVeyorBuildNumber") |
| 124 | + .WithCriteria(() => isRunningOnAppVeyor) |
| 125 | + .Does(() => |
| 126 | +{ |
| 127 | + var fullSemVer = gitVersionOutput["FullSemVer"].ToString(); |
| 128 | + AppVeyor.UpdateBuildVersion(fullSemVer); |
| 129 | +}); |
| 130 | + |
| 131 | +Task("__BuildSolutions") |
| 132 | + .Does(() => |
| 133 | +{ |
| 134 | + foreach(var solution in solutions) |
| 135 | + { |
| 136 | + Information("Building {0}", solution); |
| 137 | + |
| 138 | + MSBuild(solution, settings => |
| 139 | + settings |
| 140 | + .SetConfiguration(configuration) |
| 141 | + .WithProperty("TreatWarningsAsErrors", "true") |
| 142 | + .UseToolVersion(MSBuildToolVersion.NET46) |
| 143 | + .SetVerbosity(Verbosity.Minimal) |
| 144 | + .SetNodeReuse(false)); |
| 145 | + } |
| 146 | +}); |
| 147 | + |
| 148 | +Task("__RunTests") |
| 149 | + .Does(() => |
| 150 | +{ |
| 151 | + XUnit2("./src/**/bin/" + configuration + "/*.Specs.dll", new XUnit2Settings { |
| 152 | + OutputDirectory = testResultsDir, |
| 153 | + XmlReportV1 = true |
| 154 | + }); |
| 155 | +}); |
| 156 | + |
| 157 | +Task("__CopyOutputToNugetFolder") |
| 158 | + .Does(() => |
| 159 | +{ |
| 160 | + foreach(var project in projectToNugetFolderMap.Keys) { |
| 161 | + var sourceDir = srcDir + Directory(projectName + "." + project) + Directory("bin") + Directory(configuration); |
| 162 | + var destDir = buildDir + Directory("lib") + Directory(projectToNugetFolderMap[project]); |
| 163 | + |
| 164 | + Information("Copying {0} -> {1}.", sourceDir, destDir); |
| 165 | + CopyDirectory(sourceDir, destDir); |
| 166 | + } |
| 167 | + |
| 168 | + CopyFile(nuspecSrcFile, nuspecDestFile); |
| 169 | +}); |
| 170 | + |
| 171 | +Task("__CreateNugetPackage") |
| 172 | + .Does(() => |
| 173 | +{ |
| 174 | + var nugetVersion = gitVersionOutput["NuGetVersion"].ToString(); |
| 175 | + |
| 176 | + Information("Building {0}.{1}.nupkg", projectName, nugetVersion); |
| 177 | + |
| 178 | + var nuGetPackSettings = new NuGetPackSettings { |
| 179 | + Id = "Polly", |
| 180 | + Title = "Polly", |
| 181 | + Version = nugetVersion, |
| 182 | + Symbols = true, |
| 183 | + OutputDirectory = nupkgDestDir |
| 184 | + }; |
| 185 | + |
| 186 | + NuGetPack(nuspecDestFile, nuGetPackSettings); |
| 187 | +}); |
| 188 | + |
| 189 | +////////////////////////////////////////////////////////////////////// |
| 190 | +// BUILD TASKS |
| 191 | +////////////////////////////////////////////////////////////////////// |
| 192 | + |
| 193 | +Task("Build") |
| 194 | + .IsDependentOn("__Clean") |
| 195 | + .IsDependentOn("__RestoreNugetPackages") |
| 196 | + .IsDependentOn("__UpdateAssemblyVersionInformation") |
| 197 | + .IsDependentOn("__UpdateAppVeyorBuildNumber") |
| 198 | + .IsDependentOn("__BuildSolutions") |
| 199 | + .IsDependentOn("__RunTests") |
| 200 | + .IsDependentOn("__CopyOutputToNugetFolder") |
| 201 | + .IsDependentOn("__CreateNugetPackage"); |
| 202 | + |
| 203 | +/////////////////////////////////////////////////////////////////////////////// |
| 204 | +// PRIMARY TARGETS |
| 205 | +/////////////////////////////////////////////////////////////////////////////// |
| 206 | + |
| 207 | +Task("Default") |
| 208 | + .IsDependentOn("Build"); |
| 209 | + |
| 210 | +/////////////////////////////////////////////////////////////////////////////// |
| 211 | +// EXECUTION |
| 212 | +/////////////////////////////////////////////////////////////////////////////// |
| 213 | + |
| 214 | +RunTarget(target); |
| 215 | + |
| 216 | +////////////////////////////////////////////////////////////////////// |
| 217 | +// HELPER FUNCTIONS |
| 218 | +////////////////////////////////////////////////////////////////////// |
| 219 | + |
| 220 | +string ToolsExePath(string exeFileName) { |
| 221 | + var exePath = System.IO.Directory.GetFiles(@".\Tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault(); |
| 222 | + return exePath; |
| 223 | +} |
0 commit comments