forked from nunit/nunit.analyzers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
218 lines (179 loc) · 6.73 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
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
var targetFramework = Argument("targetFramework", "netstandard2.0");
//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////
var isNetstandard16Build = targetFramework == "netstandard1.6";
var isNetstandard20Build = targetFramework == "netstandard2.0";
var version = isNetstandard20Build
? "3.10.0"
: "2.10.0";
var isAppveyor = BuildSystem.IsRunningOnAppVeyor;
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
var packageVersion = version;
var packageVersionString = version + dbgSuffix;
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
// Directories
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var SRC_DIR = PROJECT_DIR + "src/";
var PACKAGE_DIR = PROJECT_DIR + "package/" + configuration;
var ANALYZERS_TESTS_OUTPUT_DIR = SRC_DIR + "nunit.analyzers.tests/bin/";
var ANALYZERS_OUTPUT_DIR = SRC_DIR + "nunit.analyzers/bin/";
// Solution
var SOLUTION_FILE = PROJECT_DIR + "src/nunit.analyzers.sln";
// Projects
var ANALYZER_PROJECT = SRC_DIR + "nunit.analyzers/nunit.analyzers.csproj";
var TEST_PROJECT = SRC_DIR + "nunit.analyzers.tests/nunit.analyzers.tests.csproj";
// Package sources for nuget restore
var PACKAGE_SOURCE = new string[]
{
"https://www.nuget.org/api/v2",
};
//////////////////////////////////////////////////////////////////////
// SETUP AND TEARDOWN TASKS
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
if (BuildSystem.IsRunningOnAppVeyor)
{
var tag = AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
{
var tagName = tag.Name;
if (isNetstandard16Build && tagName.StartsWith("3"))
{
tagName = '2' + tagName.Substring(1);
}
packageVersion = tagName;
packageVersionString = tagName;
}
else
{
var buildNumber = AppVeyor.Environment.Build.Number.ToString("00000");
var branch = AppVeyor.Environment.Repository.Branch;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
packageVersion = version + "." + AppVeyor.Environment.Build.Number;
if (branch == "master" && !isPullRequest)
{
packageVersionString = version + "-dev-" + buildNumber + dbgSuffix;
}
else
{
var suffix = "-ci-" + buildNumber + dbgSuffix;
if (isPullRequest)
suffix += "-pr-" + AppVeyor.Environment.PullRequest.Number;
else if (AppVeyor.Environment.Repository.Branch.StartsWith("release", StringComparison.OrdinalIgnoreCase))
suffix += "-pre-" + buildNumber;
else
suffix += "-" + System.Text.RegularExpressions.Regex.Replace(branch, "[^0-9A-Za-z-]+", "-");
// Nuget limits "special version part" to 20 chars. Add one for the hyphen.
if (suffix.Length > 21)
suffix = suffix.Substring(0, 21);
packageVersionString = version + suffix;
}
}
AppVeyor.UpdateBuildVersion(packageVersionString);
}
// Executed BEFORE the first task.
Information("Building {0} version \"{1}\" / {2} of NUnit.Analyzers", configuration, packageVersion, packageVersionString);
});
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(ANALYZERS_TESTS_OUTPUT_DIR);
CleanDirectory(ANALYZERS_OUTPUT_DIR);
});
//////////////////////////////////////////////////////////////////////
// RESTORE NUGET PACKAGES
//////////////////////////////////////////////////////////////////////
Task("RestorePackages")
.Does(() =>
{
DotNetRestore(SOLUTION_FILE, new DotNetRestoreSettings
{
Sources = PACKAGE_SOURCE,
});
});
//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("RestorePackages")
.Does(() =>
{
DotNetBuild(ANALYZER_PROJECT, new DotNetBuildSettings
{
Configuration = configuration,
Verbosity = DotNetVerbosity.Minimal,
NoRestore = true,
MSBuildSettings = new DotNetMSBuildSettings
{
Version = packageVersion
}
});
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
DotNetTest(TEST_PROJECT, new DotNetTestSettings
{
Configuration = configuration,
Loggers = new string[] { "trx" },
VSTestReportPath = "TestResult.xml",
});
})
.Finally(() =>
{
if (AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadTestResults("TestResult.xml", AppVeyorTestResultsType.MSTest);
}
});
//////////////////////////////////////////////////////////////////////
// Pack
//////////////////////////////////////////////////////////////////////
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
NuGetPack("./src/nunit.analyzers/nunit.analyzers.nuspec", new NuGetPackSettings()
{
Version = packageVersionString,
OutputDirectory = PACKAGE_DIR + "/" + targetFramework,
Properties = new Dictionary<string, string>()
{
{"Configuration", configuration},
{"TargetFramework", targetFramework }
}
});
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Test");
Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Pack");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);