-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
build.cake
243 lines (203 loc) · 7.74 KB
/
build.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#addin "Cake.FileHelpers&version=4.0.1"
#addin "Cake.Git&version=1.0.0"
#tool "nsis&version=2.51.0"
#tool "nuget:?package=OpenCover&version=4.7.1221"
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.15.0"
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
#tool nuget:?package=vswhere&version=2.8.4
public FilePath LatestMSBuildPath { get; private set; }
LatestMSBuildPath = GetLatestMSBuildPath();
private FilePath GetLatestMSBuildPath()
{
var latestMSBuildPath = VSWhereLatest(new VSWhereLatestSettings { Products = "*", Requires = "Microsoft.Component.MSBuild"});
return new FilePath($"{latestMSBuildPath}\\MSBuild\\Current\\Bin\\MSBuild.exe");
}
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
var system = Argument<string>("system", System.Environment.OSVersion.Platform.ToString().StartsWith("Win") ? "win" : "mac");
var netcoreTargetFramework = Argument<string>("targetFrameworkNetCore", "netcoreapp3.1");
var netcoreTargetRuntime = Argument<string>("netcoreTargetRuntime", system=="win" ? "win-x64" : "osx-x64");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var _solution = $"./RepoZ.{system}.sln";
var _appVersion = "";
var _outputDir = Directory($"_output");
var _assemblyDir = Directory($"_output/{system}/Assemblies");
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
EnsureDirectoryExists(_outputDir);
CleanDirectory(_outputDir);
EnsureDirectoryExists(_assemblyDir);
CleanDirectory(_assemblyDir);
});
Task("Clean")
.Description("Cleans all directories that are used during the build process.")
.Does(() =>
{
CleanDirectories("./**/bin/" + configuration);
CleanDirectories("./**/obj/" + configuration);
});
Task("Restore")
.Description("Restores all the NuGet packages that are used by the specified solution.")
.Does(() =>
{
Information("Restoring {0}...", _solution);
NuGetRestore(_solution);
});
Task("SetVersion")
.IsDependentOn("Restore")
.Does(() =>
{
var gitVersion = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfo = true
});
var commits = GitLog(".", int.MaxValue);
_appVersion = $"{gitVersion.Major}.{gitVersion.Minor}";
var buildNumber = commits.Count.ToString();
var fullVersion = gitVersion.AssemblySemVer;
Information($"AppVersion:\t{_appVersion}");
Information($"FullVersion:\t{fullVersion}");
Information($"Build {buildNumber} (= number of commits in git history)");
ReplaceRegexInFiles("./**/AssemblyInfo.*", "(?<=AssemblyBuildDate\\(\")([0-9\\-\\:T]+)(?=\"\\))", DateTime.Now.ToString("s"));
ReplaceRegexInFiles("./**/*.csproj", "(?<=<ReleaseVersion>).*?(?=</ReleaseVersion>)", _appVersion);
ReplaceRegexInFiles("./**/*.csproj", "(?<=<Version>).*?(?=</Version>)", fullVersion);
// update Apple versions
ReplaceRegexInFiles("**/Info.plist", "(?<=<key>CFBundleShortVersionString</key>\\n*\\s*<string>).*?(?=</string>)", _appVersion);
ReplaceRegexInFiles("**/Info.plist", "(?<=<key>CFBundleVersion</key>\\n*\\s*<string>).*?(?=</string>)", buildNumber);
});
Task("Build")
.Description("Builds all the different parts of the project.")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("SetVersion")
.Does(() =>
{
// build the solution
Information("Building {0}", _solution);
MSBuild(_solution, settings =>
{
settings.ToolPath = LatestMSBuildPath;
settings.SetPlatformTarget(PlatformTarget.MSIL)
// .UseToolVersion(MSBuildToolVersion.VS2022)
.WithProperty("TreatWarningsAsErrors","true")
.WithTarget("Build")
.SetConfiguration(configuration);
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
if (system == "mac")
return;
var assemblies = new[]
{
$"./Tests/bin/{configuration}/Tests.dll",
$"./Specs/bin/{configuration}/Specs.dll"
};
var testResultsFile = MakeAbsolute(File($"{_outputDir}/TestResults.xml")).FullPath;
var testCoverageFile = MakeAbsolute(File($"{_outputDir}/TestCoverage.xml")).FullPath;
Information("Test results xml: " + testResultsFile);
Information("Test coverage xml: " + testCoverageFile);
var openCoverSettings = new OpenCoverSettings()
.WithFilter("+[*]*")
.WithFilter("-[Specs]*")
.WithFilter("-[Tests]*")
.WithFilter("-[FluentAssertions*]*")
.WithFilter("-[Moq*]*")
.WithFilter("-[LibGit2Sharp*]*");
openCoverSettings.ReturnTargetCodeOffset = 0;
var nunitSettings = new NUnit3Settings
{
Results = new[]
{
new NUnit3Result { FileName = testResultsFile }
},
NoHeader = true,
Configuration = "Default"
};
OpenCover(tool => tool.NUnit3(assemblies, nunitSettings),
new FilePath(testCoverageFile),
openCoverSettings
);
});
Task("Publish")
.IsDependentOn("Build")
.IsDependentOn("Test")
.Does(() =>
{
// copy RepoZ main app files
CopyFiles($"RepoZ.App.{system}/bin/" + configuration + "/**/*", _assemblyDir, true);
// publish netcore apps
var settings = new DotNetCorePublishSettings
{
Framework = netcoreTargetFramework,
Configuration = configuration,
Runtime = netcoreTargetRuntime,
SelfContained = true
};
DotNetCorePublish("./grr/grr.csproj", settings);
DotNetCorePublish("./grrui/grrui.csproj", settings);
// on macOS, we need to put the "tools" grr & grrui to another location, so deploy them to a subfolder here.
// the RepoZ.app file has to be copied to "Applications" whereas the tools might go to "Application Support".
if (system == "mac")
{
_assemblyDir = Directory($"{_assemblyDir}/RepoZ-CLI");
EnsureDirectoryExists(_assemblyDir);
}
CopyFiles($"grr/bin/{configuration}/{netcoreTargetFramework}/{netcoreTargetRuntime}/publish/*", _assemblyDir, true);
CopyFiles($"grrui/bin/{configuration}/{netcoreTargetFramework}/{netcoreTargetRuntime}/publish/*", _assemblyDir, true);
foreach (var extension in new string[]{"pdb", "config", "xml"})
DeleteFiles(_assemblyDir.Path + "/*." + extension);
});
Task("CompileSetup")
.IsDependentOn("Publish")
.Does(() =>
{
if (system == "win")
{
// NSIS Windows Setup
MakeNSIS("_setup/RepoZ.nsi", new MakeNSISSettings
{
Defines = new Dictionary<string, string>
{
{ "PRODUCT_VERSION", _appVersion }
}
});
// Chocolatey
ReplaceTextInFiles("_setup/choco/RepoZ.nuspec", "{PRODUCT_VERSION}", _appVersion);
ReplaceTextInFiles("_setup/choco/tools/chocolateyinstall.ps1", "{PRODUCT_VERSION}", _appVersion);
var settings = new ChocolateyPackSettings()
{
OutputDirectory = _outputDir,
Authors = { "Andreas Wäscher" },
Tags = { "repoz", "git", "repository", "development", "foss", "utilities", "productivity" },
Version = _appVersion
};
ChocolateyPack("_setup/choco/RepoZ.nuspec", settings);
}
else
{
// update the pkgproj file and run packagesbuild
ReplaceTextInFiles("_setup/RepoZ.pkgproj", "{PRODUCT_VERSION}", _appVersion);
StartProcess("packagesbuild", "--verbose _setup/RepoZ.pkgproj");
}
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.Description("This is the default task which will be ran if no specific target is passed in.")
.IsDependentOn("CompileSetup");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);