This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
219 lines (183 loc) · 8.21 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
/* ----------------------------------------------------------------------------
* Build script for Log-Reader
* ----------------------------------------------------------------------------
* This script uses environment variables. To run correctly, this script needs
* these variables to be set:
* - CAKE_PUBLIC_GITHUB_TOKEN - Github token of the LogReader repository
* - CAKE_PUBLIC_GITHUB_USERNAME - Github username with R/W for LogReader repository
*/
///////////////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
///////////////////////////////////////////////////////////////////////////////
#tool vswhere
#tool GitVersion.CommandLine
#tool xunit.runner.console
#tool gitreleasemanager
#addin Cake.Figlet
#addin Cake.Powershell
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var repoName = "LogReader";
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release").ToLower();
var verbosity = Argument("verbosity", Verbosity.Minimal);
/* This list contains the path of the assets to release.
* It is cleared and filled into task "Zip" and used into
* the task "Release-GitHub".
*/
var assets = new List<string>();
///////////////////////////////////////////////////////////////////////////////
// PREPARATION
///////////////////////////////////////////////////////////////////////////////
//Files & directories
var solution = "./src/Probel.LogReader.sln";
var publishDir = "./Publish/";
var inno_setup = "./setup.iss";
var binDirectory = $"./src/Probel.LogReader/bin/{configuration}/";
var binPluginDir = $"./src/plugins/Probel.LogReader.Plugins.{{0}}/bin/{configuration}/";
GitVersion gitVersion = GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json,
UpdateAssemblyInfo = true,
UpdateAssemblyInfoFilePath = "./src/Version.cs",
});
var branchName = gitVersion.BranchName;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
if(!IsRunningOnWindows())
{
throw new NotImplementedException($"{repoName} should only run on Windows");
}
Information(Figlet($"Probel {repoName}"));
Information("Configuration : {0}", configuration);
Information("Branch : {0}", branchName);
Information("Informational Version: {0}", gitVersion.InformationalVersion);
Information("SemVer Version: {0}", gitVersion.SemVer);
Information("AssemblySemVer Version: {0}", gitVersion.AssemblySemVer);
Information("AssemblySemFileVer Version: {0}", gitVersion.AssemblySemFileVer);
Information("MajorMinorPatch Version: {0}", gitVersion.MajorMinorPatch);
Information("NuGet Version: {0}", gitVersion.NuGetVersion);
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("info")
.Does(()=> {
/*Does nothing but specifying information of the build*/
});
Task("Clean")
.Does(()=> {
var dirToDelete = GetDirectories("./**/obj")
.Concat(GetDirectories("./**/bin"))
.Concat(GetDirectories("./**/Publish"));
DeleteDirectories(dirToDelete, new DeleteDirectorySettings{ Recursive = true, Force = true});
});
Task("Restore")
.Does(() => {
NuGetRestore(solution);
});
Task("Build")
.Does(() => {
var msBuildSettings = new MSBuildSettings {
Verbosity = verbosity,
Configuration = configuration
};
MSBuild(solution, msBuildSettings
.WithProperty("Description", "A simple log-reader.")
);
});
Task("Unit-Test")
.Does(() => {
var testPrj = "./src/tests/Probel.LogReader.Tests/Probel.LogReader.Tests.csproj";
DotNetCoreTest(testPrj);
});
Task("Zip")
.Does(()=> {
var zipName = publishDir + "/logreader." + gitVersion.SemVer + ".bin.zip";
Information("Zip : {0}: ", zipName);
Information("Bin dir : {0}", binDirectory);
EnsureDirectoryExists(Directory(publishDir));
Zip(binDirectory, zipName);
var dir = new DirectoryInfo(binDirectory + @"/../../../plugins/");
foreach(var d in dir.GetDirectories())
{
var pluginBin = d.FullName + @"\bin\Release\";
var dest = publishDir + "/" + d.Name.Replace("Probel.LogReader.Plugins.","plugin-") + "-" + gitVersion.SemVer + ".bin.zip";
assets.Add(dest);
Information("Zipping plugin: {0}", dest);
Information(" pluginBin : {0}", pluginBin);
Information(" dest : {0}", dest);
Zip(pluginBin, dest);
}
});
Task("Inno-Setup")
.Does(() => {
var path = MakeAbsolute(Directory(binDirectory)).FullPath + "\\";
var pluginDir = MakeAbsolute(Directory(binPluginDir)).FullPath + "\\";
var plugins = new string[] { "csv", "text", "oracle", "mssql", "iis", "sqlite" };
var i = 0;
Information("Bin path : {0}: ", path);
Information("Plugin path: {0}: ", pluginDir);
InnoSetup(inno_setup, new InnoSetupSettings {
OutputDirectory = publishDir,
Defines = new Dictionary<string, string> {
{ "MyAppVersion", gitVersion.SemVer },
{ "BinDirectory", path },
{ "CsvPluginDir", String.Format(pluginDir, plugins[i++]) },
{ "TextPluginDir", String.Format(pluginDir, plugins[i++]) },
{ "OraclePluginDir", String.Format(pluginDir, plugins[i++]) },
{ "MsSqlPluginDir", String.Format(pluginDir, plugins[i++]) },
{ "IISPluginDir", String.Format(pluginDir, plugins[i++]) },
{ "SQLitePluginDir", String.Format(pluginDir, plugins[i++]) },
}
});
});
Task("Chocolatey")
.Does(()=>{
//https://github.com/SharpeRAD/Cake.Powershell#usage
StartPowershellScript("./build-package.ps1", new PowershellSettings()
.UseWorkingDirectory("./chocolatey")
.WithArguments(args => {
args.Append("configuration", configuration);
args.Append("version", gitVersion.MajorMinorPatch);
})
);
});
Task("Release-GitHub")
.Does(()=>{
//https://stackoverflow.com/questions/42761777/hide-services-passwords-in-cake-build
var token = EnvironmentVariable("CAKE_PUBLIC_GITHUB_TOKEN");
var owner = EnvironmentVariable("CAKE_PUBLIC_GITHUB_USERNAME");
var stg = new GitReleaseManagerCreateSettings
{
Milestone = "V" + gitVersion.MajorMinorPatch,
Name = gitVersion.SemVer,
Prerelease = gitVersion.SemVer.Contains("alpha"),
Assets = publishDir + "/logreader." + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/logreader." + gitVersion.SemVer + ".setup.exe,"
+ publishDir + "/plugin-oracle-" + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/plugin-mssql-" + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/plugin-csv-" + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/plugin-text-" + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/plugin-iis-" + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/plugin-debug-" + gitVersion.SemVer + ".bin.zip,"
+ publishDir + "/plugin-sqlite-" + gitVersion.SemVer + ".bin.zip"
};
GitReleaseManagerCreate(token, owner, "log-reader", stg);
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Unit-Test")
.IsDependentOn("Zip")
.IsDependentOn("Inno-Setup")
.IsDependentOn("Chocolatey");
Task("Github")
.IsDependentOn("Default")
.IsDependentOn("Release-GitHub");
RunTarget(target);