-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
106 lines (87 loc) · 2.98 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
#addin "nuget:?package=Cake.FileHelpers&version=3.1.0"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("Target", "Default");
var configuration = Argument("configuration", "Release");
var buildCounter = Argument("buildCounter", "0"); // "version" is reserved
//////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////
var artifactsDirectory = Directory("./artifacts");
var tempDirectory = Directory("./temp");
var semVer = FileReadText("./semver.txt");
var buildVersion = semVer.Contains("-")
? semVer + buildCounter
: semVer;
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
EnsureDirectoryExists(artifactsDirectory);
EnsureDirectoryExists(tempDirectory);
CleanDirectory(artifactsDirectory);
CleanDirectory(tempDirectory);
DotNetCoreClean("./src/Sifter", new DotNetCoreCleanSettings { Configuration = configuration });
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore();
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
RunProcess("dotnet", new ProcessSettings
{
WorkingDirectory = Directory("."),
Arguments = $@"build -c {configuration} --no-restore /p:Version={buildVersion}"
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
RunProcess("dotnet", new ProcessSettings
{
WorkingDirectory = Directory("./tests/Sifter.Tests"),
Arguments = $@"test -c {configuration} --no-build --no-restore /p:Version={buildVersion}"
});
});
Task("Pack")
.IsDependentOn("Test")
.Does(() =>
{
RunProcess("dotnet", new ProcessSettings
{
WorkingDirectory = Directory("."),
Arguments = $@"pack -c {configuration} -o ""{MakeAbsolute(artifactsDirectory).FullPath}"" --no-build /p:PackageVersion={buildVersion}"
});
});
//////////////////////////////////////////////////////////////////////
// TASK METHODS
//////////////////////////////////////////////////////////////////////
void RunProcess(string name, ProcessSettings settings)
{
var exitCode = StartProcess(name, settings);
if (exitCode != 0)
{
throw new InvalidOperationException($"Unexpected error code from {name}: {exitCode}");
}
}
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Pack");
Task("CommitTest")
.IsDependentOn("Test");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);