-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
146 lines (134 loc) · 4.04 KB
/
build.cake
File metadata and controls
146 lines (134 loc) · 4.04 KB
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
#addin Cake.Git
var packageVersion = "1.0.3";
var target = Argument("target", "Default");
var mygetApiKey = Argument<string>("mygetApiKey", null);
var nugetApiKey = Argument<string>("nugetApiKey", null);
var currentBranch = Argument<string>("currentBranch", GitBranchCurrent("./").FriendlyName);
var buildNumber = Argument<string>("buildNumber", null);
var pullRequestTitle = Argument<string>("pullRequestTitle", null);
var configuration = "Release";
var isPullRequestBuild = !string.IsNullOrWhiteSpace(pullRequestTitle);
Task("PrintEnvironment")
.Does(() =>
{
foreach(var envVar in EnvironmentVariables())
{
Information("{0}: \"{1}\"", envVar.Key, envVar.Value);
}
});
Task("PatchVersion")
.Does(() =>
{
if (isPullRequestBuild)
{
Information("Pull request build. Skipping version patching.");
return;
}
var versionSuffix = "";
if (currentBranch != "master") {
if (buildNumber != null) {
versionSuffix += "-build" + buildNumber.PadLeft(5, '0');
}
versionSuffix += "-" + currentBranch;
if (versionSuffix.Length > 20) {
versionSuffix = versionSuffix.Substring(0, 20);
}
packageVersion += versionSuffix;
}
Information("Version: " + packageVersion);
foreach(var proj in GetFiles("src/**/*.csproj"))
{
Information("Patching " + proj);
XmlPoke(proj, "/Project/PropertyGroup/Version", packageVersion);
}
});
Task("Restore")
.Does(() =>
{
DotNetCoreRestore();
});
Task("Build")
.Does(() =>
{
DotNetCoreBuild("Mutopic.sln", new DotNetCoreBuildSettings
{
Configuration = configuration,
});
});
Task("UnitTest")
.Does(() =>
{
foreach(var proj in GetFiles("tests/**/*.Tests.csproj"))
{
if (IsRunningOnWindows())
{
DotNetCoreTest(proj.ToString(), new DotNetCoreTestSettings
{
NoBuild = true,
Configuration = configuration
});
}
else // dotnet test cannot run full framework tests on mac so ignore them
{
DotNetCoreTest(proj.ToString(), new DotNetCoreTestSettings
{
NoBuild = true,
Framework = "netcoreapp2.0",
Configuration = configuration
});
}
}
});
Task("Pack")
.Does(() =>
{
if (isPullRequestBuild)
{
Information("Pull request build. Skipping NuGet packing.");
return;
}
foreach(var proj in GetFiles("src/**/*.csproj"))
{
DotNetCorePack(proj.ToString(), new DotNetCorePackSettings
{
OutputDirectory = "out",
Configuration = configuration,
NoBuild = true,
});
}
});
Task("Push")
.Does(() =>
{
if (isPullRequestBuild)
{
Information("Pull request build. Skipping NuGet push.");
return;
}
var nuGetPushSettings = new NuGetPushSettings
{
Source = "https://www.nuget.org/api/v2/package",
ApiKey = nugetApiKey
};
var pkgs = GetFiles("out/*.nupkg");
if (currentBranch == "master")
{
Information("Master build. Publishing to NuGet.");
foreach(var pkg in pkgs)
{
NuGetPush(pkg, nuGetPushSettings);
}
}
else
{
Information("Non-master build. Not publishing to NuGet. Current branch: " + currentBranch);
}
});
Task("Default")
// .IsDependentOn("PrintEnvironment")
.IsDependentOn("PatchVersion")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("UnitTest")
.IsDependentOn("Pack");
RunTarget(target);