forked from fluentassertions/fluentassertions.analyzers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
146 lines (124 loc) · 4.22 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
#tool "nuget:?package=GitVersion.CommandLine"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var buildDir = Directory("./artifacts");
var solutionFile = File("./src/FluentAssertions.Analyzers.sln");
var testCsproj = File("./src/FluentAssertions.Analyzers.Tests/FluentAssertions.Analyzers.Tests.csproj");
var nuspecFile = File("./src/FluentAssertions.Analyzers/FluentAssertions.Analyzers.nuspec");
var version = GetCurrentVersion(Context);
var testResults = MakeAbsolute(buildDir + File("./testResults.trx"));
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Update-Version")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
version += $"-preview{AppVeyor.Environment.Build.Number}";
Information($"Version: {version}");
});
Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(solutionFile);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreBuild(solutionFile, new DotNetCoreBuildSettings
{
Configuration = configuration,
OutputDirectory = buildDir
});
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
DotNetCoreTest(testCsproj, new DotNetCoreTestSettings
{
Filter = "TestCategory=Completed",
Configuration = configuration,
ArgumentCustomization = builder => builder.Append($"--logger \"trx;LogFileName={testResults}\"")
});
})
.Finally(() => {
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadTestResults(testResults, AppVeyorTestResultsType.MSTest);
}
});
Task("Pack")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
var nuGetPackSettings = new NuGetPackSettings
{
OutputDirectory = buildDir,
Version = version
};
NuGetPack(nuspecFile, nuGetPackSettings);
});
Task("Publish-NuGet")
.IsDependentOn("Pack")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.WithCriteria(HasEnvironmentVariable("NUGET_API_KEY"))
.WithCriteria(HasEnvironmentVariable("NUGET_API_URL"))
.Does(() =>
{
var apiKey = EnvironmentVariable("NUGET_API_KEY");
var apiUrl = EnvironmentVariable("NUGET_API_URL");
var nupkgFile = File($"{buildDir}/FluentAssertions.Analyzers.{version}.nupkg");
Information($"Publishing nupkg file '{nupkgFile}'...");
NuGetPush(nupkgFile, new NuGetPushSettings
{
ApiKey = apiKey,
Source = apiUrl
});
});
Task("AppVeyor")
.IsDependentOn("Update-Version")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Pack")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
var nupkgFile = File($"{buildDir}/FluentAssertions.Analyzers.{version}.nupkg");
AppVeyor.UploadArtifact(nupkgFile, new AppVeyorUploadArtifactsSettings()
.SetArtifactType(AppVeyorUploadArtifactType.NuGetPackage));
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Pack");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);
string GetCurrentVersion(ICakeContext context)
{
return context.XmlPeek(nuspecFile, "nu:package/nu:metadata/nu:version", new XmlPeekSettings
{
Namespaces = new Dictionary<string, string>
{
["nu"] = "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
}
});
}