-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.cake
114 lines (99 loc) · 3.01 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
// Install addins.
#addin "nuget:https://www.nuget.org/api/v2?package=Newtonsoft.Json&version=9.0.1"
//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var versionSuffix = Argument("versionSuffix", "alpha");
string version = "0.1.0";
string fullVersion = string.Empty;
//////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
var APPVEYOR_BUILD_NUMBER = (context.EnvironmentVariable("APPVEYOR_BUILD_NUMBER") ?? "9999");
fullVersion = version + "-alpha-" + String.Format("{0:0000}", int.Parse(APPVEYOR_BUILD_NUMBER));
if(AppVeyor.IsRunningOnAppVeyor)
{
//Update build version
AppVeyor.UpdateBuildVersion(fullVersion);
}
Information("Building version {0} of OTA-Library.", fullVersion);
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(()=>
{
CleanDirectories("./build");
CleanDirectories("**/bin");
CleanDirectories("**/obj");
});
Task("Patch-Project-Json")
.IsDependentOn("Clean")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.Does(()=>
{
var projects = GetFiles("./**/project.json");
foreach(var project in projects)
{
var content = System.IO.File.ReadAllText(project.FullPath, Encoding.UTF8);
var node = Newtonsoft.Json.Linq.JObject.Parse(content);
if(node["version"] != null)
{
node["version"].Replace(fullVersion);
System.IO.File.WriteAllText(project.FullPath, node.ToString(), Encoding.UTF8);
};
}
});
Task("Package-Restore")
.IsDependentOn("Patch-Project-Json")
.Does(() =>
{
var projects = GetFiles("./**/project.json");
foreach(var project in projects)
{
DotNetCoreRestore(project.GetDirectory().FullPath);
}
});
Task("Build")
.IsDependentOn("Package-Restore")
.Does(() =>
{
var projects = GetFiles("./**/*.xproj");
foreach(var project in projects)
{
DotNetCoreBuild(project.GetDirectory().FullPath, new DotNetCoreBuildSettings {
Configuration = configuration
});
}
});
Task("Check-Build-Folder-Exists")
.IsDependentOn("Build")
.Does(() =>
{
EnsureDirectoryExists("./build");
});
Task("Create-NuGet-Packages")
.IsDependentOn("Check-Build-Folder-Exists")
.Does(() =>
{
DotNetCorePack("./src/OTA-Library", new DotNetCorePackSettings {
Configuration = configuration,
OutputDirectory = "./build",
NoBuild = true
});
});
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Create-NuGet-Packages")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UploadArtifact("./build/OTA-Library." + fullVersion + ".nupkg");
});
Task("Default")
.IsDependentOn("Upload-AppVeyor-Artifacts");
RunTarget(target);