-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
190 lines (157 loc) · 5.36 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
#!/usr/bin/env cake
// Required namespaces
using System;
// Tools and addins
#tool nuget:?package=NUnit.ConsoleRunner&version=3.12.0
#addin nuget:?package=Cake.Coverlet&version=2.5.4
#addin nuget:?package=Cake.ExtendedNuGet&version=4.0.2
#addin nuget:?package=Cake.GitVersioning&version=3.4.244
#addin nuget:?package=Cake.Git&version=1.0.1
// Parameters and arguments
readonly string task = Argument("task", "Build");
readonly string projectName = Argument("projectName", "Float.TinCan.ActivityLibrary");
readonly string configuration = Argument("configuration", "Debug");
readonly Uri nugetUrl = Argument<Uri>("nugetUrl", null);
readonly string nugetToken = Argument("nugetToken", string.Empty);
// Derived global parameters
readonly var root = MakeAbsolute(new DirectoryPath("./"));
readonly var isReleaseBuild = configuration == "Release";
readonly var netAssemblyInfoLocation = File($"./{projectName}/Properties/AssemblyInfo.cs");
readonly var testProjectName = $"{projectName}.Tests";
readonly var solution = $"{projectName}.sln";
readonly var project = new
{
Main = $"./{projectName}/{projectName}.csproj",
Test = $"./{testProjectName}/{testProjectName}.csproj",
};
// Parameters to be defined later
var assemblyVersion = "0.0.0.0";
var packageVersion = "0.0.0.0-feat";
// Tasks
Task("Clean")
.Does(() =>
{
CleanDirectories(GetDirectories("./.vs"));
CleanDirectories(GetDirectories("./**/obj"));
CleanDirectories(GetDirectories("./**/bin"));
});
Task("RestorePackages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solution);
});
Task("GitVersion")
.Does(() =>
{
var gitVersion = GitVersioningGetVersion();
assemblyVersion = $"{gitVersion.AssemblyVersion}";
packageVersion = $"{gitVersion.NuGetPackageVersion}";
Information($"Assembly version: {assemblyVersion}");
Information($"NuGet version: {packageVersion}");
Information($"Informational version: {gitVersion.AssemblyInformationalVersion}");
var visible = isReleaseBuild
? new string[] {}
: new [] { testProjectName };
CreateAssemblyInfo(netAssemblyInfoLocation, new AssemblyInfoSettings
{
Version = $"{gitVersion.AssemblyVersion}",
FileVersion = $"{gitVersion.AssemblyFileVersion}",
InformationalVersion = $"{gitVersion.AssemblyInformationalVersion}",
ComVisible = true,
InternalsVisibleTo = visible,
CustomAttributes = new []
{
new AssemblyInfoCustomAttribute
{
NameSpace = "System.Resources",
Name = "NeutralResourcesLanguage",
Value = "en",
},
},
});
});
Task("Build")
.IsDependentOn("GitVersion")
.Does(() =>
{
DotNetCoreBuild(project.Main, new DotNetCoreBuildSettings
{
Configuration = configuration,
NoIncremental = true,
NoRestore = true,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetVersion(packageVersion)
});
});
Task("Test")
.IsDependentOn("Build")
.WithCriteria(!isReleaseBuild)
.Does(() =>
{
var testSettings = new DotNetCoreTestSettings
{
Loggers = new[] { "nunit" },
};
var coverletSettings = new CoverletSettings
{
CollectCoverage = true,
CoverletOutputFormat = CoverletOutputFormat.opencover,
};
DotNetCoreTest(project.Test, testSettings, coverletSettings);
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
DotNetCorePack(project.Main, new DotNetCorePackSettings
{
Configuration = configuration,
NoBuild = true,
NoRestore = true,
IncludeSymbols = true,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetVersion(packageVersion)
});
var packPath = File($"./{projectName}/bin/{configuration}/netstandard2.0/{projectName}.dll");
var packHash = CalculateFileHash(packPath).ToHex();
var packSize = $"{FileSize(packPath)}";
Information($" Assembly hash: {packHash}");
Information($" Assembly size: {packSize} bytes");
});
Task("Deploy")
.IsDependentOn("Test")
.IsDependentOn("Pack")
.Does(() =>
{
if (!HasArgument("nugetUrl"))
{
throw new Exception("--nugetUrl is required.");
}
if (!HasArgument("nugetToken"))
{
throw new Exception("--nugetToken is required.");
}
if (!(GetFiles($"./{projectName}/bin/{configuration}/*[!symbols].nupkg").First() is FilePath packageFile))
{
throw new Exception("Unable to find NuGet package file.");
}
var packageId = GetNuGetPackageId(packageFile);
var packageVer = GetNuGetPackageVersion(packageFile);
Information("Publishing NuGet Package");
Information($"Package ID: {packageId}");
Information($"Package Version: {packageVer}");
PublishNuGets(
nugetUrl.AbsoluteUri,
nugetToken,
new PublishNuGetsSettings
{
},
new []
{
$"{packageFile}",
}
);
});
// Run
RunTarget(task);