-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
222 lines (181 loc) · 7.61 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
/* ----------------------------------------------------------------------------
* Build script for Lanceur Bis
* ----------------------------------------------------------------------------
* This script uses environment variables. To run correctly, this script needs
* these variables to be set:
* - CAKE_PUBLIC_GITHUB_TOKEN - Github token of the repository
* - CAKE_PUBLIC_GITHUB_USERNAME - Github username with R/W for LogReader repository
*/
///////////////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
///////////////////////////////////////////////////////////////////////////////
#tool nuget:?package=vswhere&version=3.0.1
#tool nuget:?package=GitVersion.CommandLine&version=5.12.0
///////////////////////////////////////////////////////////////////////////////
/// USINGS & NAMESPACES
///////////////////////////////////////////////////////////////////////////////
#r "Spectre.Console"
using Spectre.Console
///////////////////////////////////////////////////////////////////////////////
// PREPARATION
///////////////////////////////////////////////////////////////////////////////
var solution = "./Lanceur.sln";
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var repoName = "lanceur-bis";
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release").ToLower();
var verbosity = Argument("verbosity", Verbosity.Minimal);
var binDirectory = $"./src/UI/Lanceur.Ui.WPF/bin/{configuration}/net8.0-windows10.0.19041.0/";
var setupIconFile = $"./src/UI/Lanceur.Ui.WPF/Assets/appIcon.ico";
var publishDir = "./Publish";
var inno_setup = "./setup.iss";
GitVersion gitVersion;
string zipName;
string innoSetupName;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// https://gitversion.net/docs/usage/cli/arguments
// https://cakebuild.net/api/Cake.Core.Tooling/ToolSettings/50AAB3A8
gitVersion = GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json,
Verbosity = GitVersionVerbosity.Verbose,
ArgumentCustomization = args => args.Append("/updateprojectfiles")
});
var branchName = gitVersion.BranchName;
zipName = new FilePath(publishDir + "/Lanceur." + gitVersion.SemVer + ".bin.zip").FullPath;
innoSetupName = new FilePath(publishDir + "/Lanceur." + gitVersion.SemVer + ".setup.exe").FullPath;
if(!IsRunningOnWindows())
{
throw new NotImplementedException($"{repoName} should only run on Windows");
}
AnsiConsole.Write(
new FigletText($"{repoName}")
.LeftJustified()
.Color(Color.Red));
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(()=> {
Information("Cleaning files...");
var dirToDelete = GetDirectories("./**/obj")
.Concat(GetDirectories("./**/bin"))
.Concat(GetDirectories("./**/Output"))
.Concat(GetDirectories("./**/Publish"));
DeleteDirectories(dirToDelete, new DeleteDirectorySettings{ Recursive = true, Force = true});
DotNetTool(
solution,
"clean"
);
});
Task("restore")
.Does(()=>{
DotNetTool(
solution,
"restore"
);
});
Task("build")
.Does(() => {
DotNetTool(
solution,
"build",
"--no-restore -c release"
);
});
Task("test")
.Does(()=>{
DotNetTool(
solution,
"test",
"--no-restore --no-build -c release"
);
});
Task("zip")
.Does(()=> {
var path = MakeAbsolute(Directory(binDirectory));
Information("Bin path : {0}", path);
Information("Output dir : {0}", zipName);
EnsureDirectoryExists(Directory(publishDir));
Zip(path, zipName);
});
Task("inno-setup")
.Does(() => {
var path = MakeAbsolute(Directory(binDirectory));
Information("Bin path : {0}", path);
Information("Output dir : {0}", publishDir);
Information("MyAppVersion : {0}", gitVersion?.SemVer ?? "<NULL>");
Information("BinDirectory : {0}", path?.FullPath ?? "<NULL>");
Information("SetupIconFile : {0}", setupIconFile ?? "<NULL>");
InnoSetup(inno_setup, new InnoSetupSettings {
OutputDirectory = publishDir,
Defines = new Dictionary<string, string> {
{ "MyAppVersion", gitVersion.SemVer },
{ "BinDirectory", path.FullPath + "/" },
{ "SetupIconFile", setupIconFile },
}
});
});
///////////////////////////////////////////////////////////////////////////////
// BATCHES
///////////////////////////////////////////////////////////////////////////////
Task("relnote")
.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 fZip = MakeAbsolute(File(zipName));
var fInn = MakeAbsolute(File(innoSetupName));
var assets = $"{fZip},{fInn}";
var alphaVersions = new[] { "alpha", "beta" };
var isPrerelease = alphaVersions.Any(x => gitVersion.SemVer.ToLower().Contains(x));
if(isPrerelease) { Information("This is a prerelease"); }
Information("Has token : {0}", !string.IsNullOrEmpty(token));
Information("Has owner : {0}", !string.IsNullOrEmpty(owner));
Information("Zip : {0}", fZip);
Information("Inno setup : {0}", fInn);
var parameters = $"create --token {token} -o {owner} -r {repoName} " +
$"--milestone {gitVersion.MajorMinorPatch} --name {gitVersion.SemVer} " +
$"{(isPrerelease ? "--pre" : "")} " +
$"--targetDirectory {Environment.CurrentDirectory} " +
$"--assets {assets}"
// + "--debug --verbose"
;
DotNetTool(
solution,
"gitreleasemanager",
parameters
);
});
Task("default")
.IsDependentOn("clean")
.IsDependentOn("restore")
.IsDependentOn("build")
.IsDependentOn("test");
Task("bin")
.IsDependentOn("default")
.IsDependentOn("zip")
.IsDependentOn("inno-setup");
Task("github")
.IsDependentOn("bin")
.IsDependentOn("relnote");
RunTarget(target);