-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathbuild.cake
166 lines (136 loc) · 5.83 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
///////////////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
///////////////////////////////////////////////////////////////////////////////
#module nuget:?package=Cake.DotNetTool.Module&version=0.5.0
#tool dotnet:?package=GitVersion.Tool&version=5.6.3
#tool xunit.runner.console&version=2.4.1
#tool vswhere&version=2.8.4
#addin nuget:?package=Cake.Figlet&version=1.4.0
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var verbosity = Argument("verbosity", Verbosity.Minimal);
///////////////////////////////////////////////////////////////////////////////
// PREPARATION
///////////////////////////////////////////////////////////////////////////////
var repoName = "SimpleMusicPlayer";
var isLocal = BuildSystem.IsLocalBuild;
// Set build version
if (isLocal == false || verbosity == Verbosity.Verbose)
{
GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.BuildServer });
}
GitVersion gitVersion = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json });
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var branchName = gitVersion.BranchName;
var isDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", branchName);
var isReleaseBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);
var isTagged = AppVeyor.Environment.Repository.Tag.IsTag;
var latestInstallationPath = VSWhereLatest(new VSWhereLatestSettings { IncludePrerelease = true });
var msBuildPath = latestInstallationPath.Combine("./MSBuild/Current/Bin");
var msBuildPathExe = msBuildPath.CombineWithFilePath("./MSBuild.exe");
if (FileExists(msBuildPathExe) == false)
{
throw new NotImplementedException("You need at least Visual Studio 2019 to build this project.");
}
// Directories and Paths
var solution = "./src/SimpleMusicPlayer.sln";
var publishDir = "./Publish";
var testResultsDir = Directory("./TestResults");
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
if (!IsRunningOnWindows())
{
throw new NotImplementedException($"{repoName} will only build on Windows because it's not possible to target WPF and Windows Forms from UNIX.");
}
Information(Figlet(repoName));
Information("Informational Version: {0}", gitVersion.InformationalVersion);
Information("SemVer Version: {0}", gitVersion.SemVer);
Information("AssemblySemVer Version: {0}", gitVersion.AssemblySemVer);
Information("MajorMinorPatch Version: {0}", gitVersion.MajorMinorPatch);
Information("NuGet Version: {0}", gitVersion.NuGetVersion);
Information("IsLocalBuild : {0}", isLocal);
Information("Branch : {0}", branchName);
Information("Configuration : {0}", configuration);
Information("MSBuildPath : {0}", msBuildPath);
});
Teardown(ctx =>
{
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.ContinueOnError()
.Does(() =>
{
var directoriesToDelete = GetDirectories("./**/obj")
.Concat(GetDirectories("./**/bin"))
.Concat(GetDirectories("./**/Publish"));
DeleteDirectories(directoriesToDelete, new DeleteDirectorySettings { Recursive = true, Force = true });
});
Task("Restore")
.Does(() =>
{
NuGetRestore(solution, new NuGetRestoreSettings { MSBuildPath = msBuildPath.ToString() });
});
Task("Build")
.Does(() =>
{
var msBuildSettings = new MSBuildSettings {
Verbosity = verbosity
, ToolPath = msBuildPathExe
, Configuration = configuration
, ArgumentCustomization = args => args.Append("/m").Append("/nr:false") // The /nr switch tells msbuild to quite once it’s done
, BinaryLogger = new MSBuildBinaryLogSettings() { Enabled = isLocal }
};
MSBuild(solution, msBuildSettings
.SetMaxCpuCount(0)
.WithProperty("Version", isReleaseBranch ? gitVersion.MajorMinorPatch : gitVersion.NuGetVersion)
.WithProperty("AssemblyVersion", gitVersion.AssemblySemVer)
.WithProperty("FileVersion", gitVersion.AssemblySemFileVer)
.WithProperty("InformationalVersion", gitVersion.InformationalVersion)
);
});
Task("Zip")
.Does(() =>
{
EnsureDirectoryExists(Directory(publishDir));
Zip("./src/SimpleMusicPlayer/bin/" + configuration, publishDir + $"/SimpleMusicPlayer-{configuration}-v{gitVersion.NuGetVersion}.zip");
});
Task("Tests")
.ContinueOnError()
.Does(() =>
{
CleanDirectory(testResultsDir);
var settings = new DotNetCoreTestSettings
{
Configuration = configuration,
NoBuild = true,
NoRestore = true,
Logger = "trx",
ResultsDirectory = testResultsDir,
Verbosity = DotNetCoreVerbosity.Normal
};
DotNetCoreTest("./src/SimpleMusicPlayer.Tests/SimpleMusicPlayer.Tests.csproj", settings);
});
///////////////////////////////////////////////////////////////////////////////
// TASK TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Tests");
Task("appveyor")
.IsDependentOn("Default")
.IsDependentOn("Zip");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);