-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
147 lines (121 loc) · 4.08 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
#addin "Cake.GitVersioning&version=3.1.74"
#addin "Cake.Figlet&version=1.3.1"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
DotNetCoreBuildSettings dotNetCoreBuildSettings;
DotNetCoreMSBuildSettings msBuildSettings;
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var artifactsDir = Directory(Argument("artifactsDir", EnvironmentVariable("BUILD_ARTIFACTDIR") ?? "./artifacts"));
var testResultDir = artifactsDir + Directory("test-results");
var gitVersion = GitVersioningGetVersion();
Setup(context =>
{
Information(Figlet("dng.Syndication"));
Information("Is Windows {0}", IsRunningOnWindows());
msBuildSettings = new DotNetCoreMSBuildSettings()
.SetInformationalVersion(gitVersion.AssemblyInformationalVersion.ToString())
.SetFileVersion(gitVersion.AssemblyFileVersion.ToString())
.SetVersion(gitVersion.Version.ToString())
.WithProperty("PackageVersion", gitVersion.Version.ToString());
dotNetCoreBuildSettings = new DotNetCoreBuildSettings
{
Configuration = configuration,
MSBuildSettings = msBuildSettings
};
});
Teardown(context =>
{
Information("Finished running tasks ✔");
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("dotnet-info")
.Does(() =>
{
Information("dotnet --info");
StartProcess("dotnet", new ProcessSettings { Arguments = "--info" });
});
Task("Clean")
.Does(() =>
{
CleanDirectories("./src/**/obj");
CleanDirectories("./src/**/bin");
CleanDirectories("./tests/**/bin");
CleanDirectories("./tests/**/obj");
CleanDirectory(artifactsDir);
CleanDirectory(testResultDir);
});
Task("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreRestore("./",new DotNetCoreRestoreSettings
{
Sources = new [] {
EnvironmentVariable("nuget-source") ?? "https://api.nuget.org/v3/index.json"
}
});
});
Task("Build")
.IsDependentOn("dotnet-info")
.IsDependentOn("Clean")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreBuild("./src/dng.Syndication.csproj", dotNetCoreBuildSettings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var projects = GetFiles("./tests/**/*.Tests.csproj");
foreach(var project in projects)
{
DotNetCoreTest (project.ToString(), new DotNetCoreTestSettings {
ArgumentCustomization = args =>
args.Append("--logger ")
.Append("trx;LogFileName=" +
System.IO.Path.Combine(
MakeAbsolute(Directory(artifactsDir)).FullPath,
project.GetFilenameWithoutExtension().FullPath + ".trx"))
});
}
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
DotNetCorePack("./src/dng.Syndication.csproj", new DotNetCorePackSettings
{
Configuration = "Release",
OutputDirectory = artifactsDir,
NoBuild = true,
MSBuildSettings = msBuildSettings
});
});
Task("PushNuget")
.IsDependentOn("Pack")
.Does(() =>
{
var nugetApiKey = EnvironmentVariable("nuget-apikey") ?? "";
var nugetApiServer = EnvironmentVariable("nuget-server") ?? "";
if (string.IsNullOrEmpty(nugetApiKey))
throw new InvalidOperationException("Could not resolve Nuget API key.");
if (string.IsNullOrEmpty(nugetApiServer))
throw new InvalidOperationException("Could not resolve Nuget Server.");
var packages = GetFiles("./artifacts/*.nupkg");
foreach(var package in packages)
{
NuGetPush(package, new NuGetPushSettings {
ApiKey = nugetApiKey,
Source = nugetApiServer
});
}
});
Task("Default").IsDependentOn("Test");
RunTarget(target);