-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.cake
156 lines (135 loc) · 4.75 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
var target = Argument<string>("Target", "Default");
var configuration = Argument<string>("Configuration", "Release");
bool publishWithoutBuild = Argument<bool>("PublishWithoutBuild", false);
string nugetPrereleaseTextPart = Argument<string>("PrereleaseText", "alpha");
var artifactsDirectory = Directory("./artifacts");
var samplesDirectory = Directory("./samples");
string testResultDir = "./temp/";
var isRunningOnBuildServer = !BuildSystem.IsLocalBuild;
var msBuildSettings = new DotNetCoreMSBuildSettings();
if (HasArgument("PrereleaseNumber"))
{
msBuildSettings.WithProperty("PrereleaseNumber", Argument<string>("PrereleaseNumber"));
msBuildSettings.WithProperty("VersionSuffix", nugetPrereleaseTextPart + Argument<string>("PrereleaseNumber"));
}
if (HasArgument("VersionPrefix"))
{
msBuildSettings.WithProperty("VersionPrefix", Argument<string>("VersionPrefix"));
}
Task("Clean-Artifacts")
.Does(() =>
{
CleanDirectory(artifactsDirectory);
});
Task("Build")
.Does(() =>
{
var dotNetCoreSettings = new DotNetCoreBuildSettings()
{
Configuration = configuration,
MSBuildSettings = msBuildSettings
};
DotNetCoreBuild("Cmdty.TimeSeries.sln", dotNetCoreSettings);
});
Task("Test-C#")
.IsDependentOn("Build")
.Does(() =>
{
Information("Cleaning test output directory");
CleanDirectory(testResultDir);
var projects = GetFiles("./tests/**/*.Test.csproj");
foreach(var project in projects)
{
Information("Testing project " + project);
DotNetCoreTest(
project.ToString(),
new DotNetCoreTestSettings()
{
ArgumentCustomization = args=>args.Append($"/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura"),
Logger = "trx",
ResultsDirectory = testResultDir,
Configuration = configuration,
NoBuild = true
});
}
});
Task("Build-Samples")
.Does(() =>
{
var dotNetCoreSettings = new DotNetCoreBuildSettings()
{
Configuration = configuration,
};
DotNetCoreBuild("samples/Cmdty.TimeSeries.Samples.sln", dotNetCoreSettings);
});
Task("Verify-TryDotNetDocs")
.IsDependentOn("Build-Samples")
.Does(() =>
{
StartProcessThrowOnError("dotnet", $"try verify {samplesDirectory}");
});
private void StartProcessThrowOnError(string applicationName, params string[] processArgs)
{
var argsBuilder = new ProcessArgumentBuilder();
foreach(string processArg in processArgs)
{
argsBuilder.Append(processArg);
}
int exitCode = StartProcess(applicationName, new ProcessSettings {Arguments = argsBuilder});
if (exitCode != 0)
throw new ApplicationException($"Starting {applicationName} in new process returned non-zero exit code of {exitCode}");
}
using System.Reflection;
private string GetAssemblyVersion(string configuration, string workingDirectory)
{
// TODO find better way of doing this!
string assemblyPath = System.IO.Path.Combine(workingDirectory, "src", "Cmdty.TimeSeries", "bin", configuration, "netstandard2.0", "Cmdty.TimeSeries.dll");
Assembly assembly = Assembly.LoadFrom(assemblyPath);
string productVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;
return productVersion;
}
Task("Pack-NuGet")
.IsDependentOn("Build-Samples")
.IsDependentOn("Test-C#")
.IsDependentOn("Clean-Artifacts")
.Does(() =>
{
var dotNetPackSettings = new DotNetCorePackSettings()
{
Configuration = configuration,
OutputDirectory = artifactsDirectory,
NoRestore = true,
MSBuildSettings = msBuildSettings
};
DotNetCorePack("src/Cmdty.TimeSeries/Cmdty.TimeSeries.csproj", dotNetPackSettings);
});
private string GetEnvironmentVariable(string envVariableName)
{
string envVariableValue = EnvironmentVariable(envVariableName);
if (string.IsNullOrEmpty(envVariableValue))
throw new ApplicationException($"Environment variable '{envVariableName}' has not been set.");
return envVariableValue;
}
var publishNuGetTask = Task("Publish-NuGet")
.Does(() =>
{
string nugetApiKey = GetEnvironmentVariable("NUGET_API_KEY");
var nupkgPath = GetFiles(artifactsDirectory.ToString() + "/*.nupkg").Single();
NuGetPush(nupkgPath, new NuGetPushSettings
{
ApiKey = nugetApiKey,
Source = "https://api.nuget.org/v3/index.json"
});
});
if (!publishWithoutBuild)
{
publishNuGetTask.IsDependentOn("Pack-NuGet");
}
else
{
Information("Publishing without first building as PublishWithoutBuild variable set to true.");
}
Task("Default")
.IsDependentOn("Verify-TryDotNetDocs")
.IsDependentOn("Pack-NuGet");
RunTarget(target);