-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
137 lines (113 loc) · 3.74 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
#tool "nuget:?package=xunit.runner.console&version=2.2.0"
var target = Argument("Target", "Default");
var configuration = Argument("Configuration", "Release");
var version = EnvironmentVariable("BUILD_NUMBER") ?? Argument("buildVersion", "0.0.0");
var nugetApiKey = EnvironmentVariable("NUGET_API_KEY") ?? "";
Information($"Running target {target} in configuration {configuration} with version {version}");
var packageDirectory = Directory("./dist_package");
// Deletes the contents of the Artifacts folder if it contains anything from a previous build.
Task("Clean")
.Does(() =>
{
CleanDirectory(packageDirectory);
DotNetCoreClean("./");
});
// Run dotnet restore to restore all package references.
Task("Restore")
.Does(() =>
{
var settings = new DotNetCoreRestoreSettings{
};
DotNetCoreRestore("./", settings);
});
Task("GenerateVersionFile")
.Does(() =>
{
var file = "./src/Hammock/AssemblyInfo.cs";
CreateAssemblyInfo(file, new AssemblyInfoSettings {
Product = "Hammock",
Version = version,
FileVersion = version,
InformationalVersion = version,
});
});
// Build using the build configuration specified as an argument.
Task("Build")
.Does(() =>
{
DotNetCoreBuild(".",
new DotNetCoreBuildSettings()
{
Configuration = configuration,
NoRestore = true
});
});
Task("Test")
.Does(() =>
{
var projects = GetFiles("./tests/Hammock.Tests/Hammock.Tests.csproj");
var settings = new DotNetCoreTestSettings
{
NoBuild = true,
NoRestore = true,
Configuration = configuration,
};
foreach(var project in projects)
{
Information("Testing project " + project);
DotNetCoreTest(project.FullPath, settings);
}
});
Task("BuildPackages")
.Does(()=>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
NoBuild = true,
OutputDirectory = packageDirectory,
ArgumentCustomization = args => args
.Append($"/p:PackageVersion={version}")
};
DotNetCorePack("./src/Hammock/Hammock.csproj", settings);
});
Task("PushPackages")
.Does(() => {
var package = $"./{packageDirectory}/hammock.core.{version}.nupkg";
if (! System.IO.File.Exists(package))
{
Information($"File {package} doesn't exist");
}
if ( !String.IsNullOrEmpty(nugetApiKey))
{
var settings = new DotNetCoreNuGetPushSettings
{
ApiKey = nugetApiKey,
Source = "https://www.nuget.org/api/v2/package"
};
Information($"Pushing package {package}");
DotNetCoreNuGetPush($"{package}", settings);
}
else
{
Information($"No Nuget keys found. Skipping package {package}");
}
});
// A meta-task that runs all the steps to Build and Test the app
Task("BuildAndTest")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("GenerateVersionFile")
.IsDependentOn("Build")
.IsDependentOn("Test");
// The default task to run if none is explicitly specified. In this case, we want
// to run everything starting from Clean, all the way up to Publish.
Task("Default")
.IsDependentOn("BuildAndTest");
Task("CI")
.IsDependentOn("GenerateVersionFile")
.IsDependentOn("Build")
//.IsDependentOn("Test")
.IsDependentOn("BuildPackages");
// Executes the task specified in the target argument.
RunTarget(target);