-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
88 lines (73 loc) · 3.11 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
// Target - The task you want to start. Runs the Default task if not specified.
var target = Argument("Target", "Default");
// Configuration - The build configuration (Debug/Release) to use.
// 1. If command line parameter parameter passed, use that.
// 2. Otherwise if an Environment variable exists, use that.
var configuration =
HasArgument("Configuration") ? Argument<string>("Configuration") :
EnvironmentVariable("Configuration") != null ? EnvironmentVariable("BuildNumber") : "Release";
// The build number to use in the version number of the built NuGet packages.
// There are multiple ways this value can be passed, this is a common pattern.
// 1. If command line parameter parameter passed, use that.
// 2. Otherwise if running on AppVeyor, get it's build number.
// 3. Otherwise if running on Travis CI, get it's build number.
// 4. Otherwise if an Environment variable exists, use that.
// 5. Otherwise default the build number to 0.
var buildNumberInt =
HasArgument("BuildNumber") ? Argument<int>("BuildNumber") :
AppVeyor.IsRunningOnAppVeyor ? AppVeyor.Environment.Build.Number :
TravisCI.IsRunningOnTravisCI ? TravisCI.Environment.Build.BuildNumber :
EnvironmentVariable("BuildNumber") != null ? int.Parse(EnvironmentVariable("BuildNumber")) : 0;
var buildNumber = buildNumberInt.ToString("D4");
var buildVersion = "1.0.0";
var buildType = (AppVeyor.IsRunningOnAppVeyor || TravisCI.IsRunningOnTravisCI) ? "ci-" : "local-";
buildType = buildType + buildNumber;
var tagName = EnvironmentVariable("APPVEYOR_REPO_TAG_NAME");
if (tagName != null) {
// On AppVeyor
buildVersion = tagName.Substring(1);
if (!tagName.Contains("-")) {
// Building a full release
buildType = "";
} else {
buildVersion = buildVersion.Substring(0, (tagName.IndexOf("-") - 1));
buildType = tagName.Substring(tagName.IndexOf("-") + 1);
}
}
string msBuildVersionArgs = "/p:VersionPrefix=\"" + buildVersion + "\" /p:VersionSuffix=\"" + buildType + "\"";
Console.WriteLine("BuildNumber: " + msBuildVersionArgs);
var artifactsDirectory = Directory("./artifacts");
var packagesDirectory = Directory("./packages");
var nuspecFile = GetFiles("./**/*.nuspec").First().ToString();
var nuspecContent = string.Empty;
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDirectory);
DeleteDirectories(GetDirectories("**/bin"), true);
DeleteDirectories(GetDirectories("**/obj"), true);
});
Task("Version")
.IsDependentOn("Clean")
.Does(() =>
{
nuspecContent = System.IO.File.ReadAllText(nuspecFile);
string version = buildVersion + "-" + buildType;
System.IO.File.WriteAllText(nuspecFile, nuspecContent.Replace("****", version));
Information("Version set to " + version);
});
Task("Pack")
.IsDependentOn("Version")
.Does(() =>
{
NuGetPack(
nuspecFile,
new NuGetPackSettings()
{
OutputDirectory = artifactsDirectory
});
System.IO.File.WriteAllText(nuspecFile, nuspecContent);
});
Task("Default")
.IsDependentOn("Pack");
RunTarget(target);