-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
build.cake
177 lines (139 loc) · 5.23 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
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var verbosityArg = Argument("verbosity", "Minimal");
var verbosity = Verbosity.Minimal;
//////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
//////////////////////////////////////////////////////////////////////
#addin nuget:?package=Cake.Figlet&version=1.2.0
#addin nuget:?package=Cake.Npx&version=1.3.0
#addin nuget:?package=SemanticVersioning&version=1.2.0
//////////////////////////////////////////////////////////////////////
// EXTERNAL SCRIPTS
//////////////////////////////////////////////////////////////////////
#load "./build/parameters.cake"
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
using System.Text.RegularExpressions;
var solutionName = "MvxScaffolding";
var solutionPathVsix = File("./MvxScaffolding.Vsix.sln");
var outputDirVsix = new DirectoryPath("./artifacts/Vsix");
var outputDirNuGet = new DirectoryPath("./artifacts/NuGet");
var nuspecFile = new FilePath("./nuspec/MvxScaffolding.Templates.nuspec");
var isRunningOnAzurePipelines = BuildSystem.IsRunningOnAzurePipelines ;
SemVer.Version versionInfo = null;
Information(Figlet(solutionName));
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();
string[] redirectedStandardOutput = null;
Npx("standard-version",
args => args.Append("--dry-run"),
out redirectedStandardOutput);
Regex regex = new Regex(@"(?<=\[).+?(?=\])");
Match match = regex.Match(redirectedStandardOutput[3]);
if (!match.Success)
throw new InvalidOperationException ("Can not parse a build version number.");
versionInfo = new SemVer.Version(match.Value);
Information("Building version {0}, ({1}, {2}) using version {3} of Cake.",
versionInfo.ToString(),
configuration,
target,
cakeVersion);
verbosity = (Verbosity) Enum.Parse(typeof(Verbosity), verbosityArg, true);
});
Teardown(ctx =>
{
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean").Does(() =>
{
Information("Cleaning common files...");
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
CleanDirectories(outputDirVsix.FullPath);
CleanDirectories(outputDirNuGet.FullPath);
EnsureDirectoryExists(outputDirVsix);
EnsureDirectoryExists(outputDirNuGet);
});
Task("Build-NuGet-Package").Does(() =>
{
var nuGetPackSettings = new NuGetPackSettings
{
OutputDirectory = outputDirNuGet,
Version = versionInfo.ToString()
};
NuGetPack(nuspecFile, nuGetPackSettings);
});
Task("Restore-NuGet-Packages").Does(() =>
{
Information("Restoring solution...");
NuGetRestore("./MvxScaffolding.Vsix.sln");
});
Task("Update-Manifest-Version").Does(() =>
{
var settings = new XmlPokeSettings
{
Namespaces = new Dictionary<string, string>
{
{"vsx", "http://schemas.microsoft.com/developer/vsx-schema/2011"}
}
};
XmlPoke("./src/MvxScaffolding.Vsix/source.extension.vsixmanifest", "/vsx:PackageManifest/vsx:Metadata/vsx:Identity/@Version",
versionInfo.ToString(), settings);
});
Task("Build-VSIX").Does(() =>
{
Information("Building solution...");
MSBuild(solutionPathVsix, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.UseToolVersion(MSBuildToolVersion.VS2019)
.WithProperty("TreatWarningsAsErrors","true")
.SetVerbosity(Verbosity.Quiet)
.WithTarget("Build")
.SetConfiguration(configuration));
});
Task("Post-Build").Does(() =>
{
Information("Moving to artifact directory...");
CopyFileToDirectory("./src/MvxScaffolding.Vsix/bin/Release/MvxScaffolding.Vsix.vsix", outputDirVsix);
MoveFile("./artifacts/Vsix/MvxScaffolding.Vsix.vsix", "./artifacts/Vsix/MvxScaffolding.vsix");
});
Task("Build-Release").Does(() =>
{
Information("Bumping version and updating changelog...");
Npx("standard-version");
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Build-NuGet-Package")
.IsDependentOn("Update-Manifest-Version")
.IsDependentOn("Build-VSIX")
.IsDependentOn("Post-Build")
.Does(() =>
{
});
Task("Release")
.IsDependentOn("Clean")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Build-NuGet-Package")
.IsDependentOn("Update-Manifest-Version")
.IsDependentOn("Build-VSIX")
.IsDependentOn("Post-Build")
.IsDependentOn("Build-Release")
.Does(() =>
{
});
RunTarget(target);