This repository has been archived by the owner on Apr 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.cake
204 lines (168 loc) · 6.48 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Arguments
var target = Argument<string>("target", "Default");
var version = Argument<string>("targetversion", null);
var nugetapikey = Argument<string>("apikey", "");
var nogit = Argument<bool>("nogit", false);
var source = Argument<string>("source", null);
var BASE_GITHUB_PATH = "git@github.com:NancyFx";
var WORKING_DIRECTORY = "Working";
var SUB_PROJECTS = new List<string>{
"Nancy",
"Nancy.Bootstrappers.Autofac",
"Nancy.Bootstrappers.Ninject",
"Nancy.Bootstrappers.StructureMap",
"Nancy.Bootstrappers.Unity",
"Nancy.Bootstrappers.Windsor",
"Nancy.Serialization.ProtBuf",
"Nancy.Serialization.ServiceStack",
"Nancy.Serialization.JsonNet"
};
Task("Package-Nuget")
.Does(() =>
{
SUB_PROJECTS.ForEach(project => {
LogInfo("Packaging Nuget for : "+ project);
var path = GetProjectDirectory(project, WORKING_DIRECTORY) + "/build.cake";
var settings = GetCakeSettings(Context, new Dictionary<string, string> {
{"target", "Package-NuGet"}
});
CakeExecuteScript(path, settings);
});
});
Task("Publish-NuGet")
.Does(() =>
{
if(string.IsNullOrWhiteSpace(nugetapikey)){
throw new CakeException("No NuGet API key provided.");
}
SUB_PROJECTS.ForEach(project => {
LogInfo("Packaging Nuget for : "+ project);
var path = GetProjectDirectory(project, WORKING_DIRECTORY) + "/build.cake";
var settings = GetCakeSettings(Context, new Dictionary<string, string> {
{"target", "Publish-NuGet"},
{"apikey", nugetapikey},
{"source", source}
});
CakeExecuteScript(path, settings);
});
});
Task("Update-Projects")
.Description("Updates all sub project submodules")
.Does(() =>
{
SUB_PROJECTS.Skip(1).ToList().ForEach(project => {
LogInfo(string.Format("Updating: {0} to v{1}", project, version));
var dir = GetProjectDirectory(project,WORKING_DIRECTORY);
PrepSubModules(dir, nogit);
ExecuteGit(dir + "/dependencies/Nancy", "fetch --tags", nogit);
ExecuteGit(dir + "/dependencies/Nancy", string.Format("checkout v{0}", version), nogit);
ExecuteGit(dir, string.Format("commit -am \"Updated submodule to v{0}\"", version), nogit);
ExecuteGit(dir, string.Format("tag -a v{0} -m \"Tagged v{0}\"", version), nogit);
});
});
Task("Get-Projects")
.Description("Creates the working directory and gets projects from GitHub")
.IsDependentOn("Clean")
.Does(() =>
{
CreateDirectory(WORKING_DIRECTORY);
LogInfo("Getting projects from github account: "+BASE_GITHUB_PATH);
SUB_PROJECTS.ForEach(project => {
LogInfo("Getting " + project + " from github");
StartProcess("git", new ProcessSettings {
Arguments = string.Format("clone --recursive {0} {1}/{2}", GetProjectGitUrl(project, BASE_GITHUB_PATH), WORKING_DIRECTORY,project)
});
});
});
Task("Test-Projects")
.Description("Tests all projects")
.Does(() =>
{
SUB_PROJECTS.ForEach(project => {
LogInfo("Running test for : " + project);
var path = GetProjectDirectory(project, WORKING_DIRECTORY) + "/build.cake";
var settings = GetCakeSettings(Context, new Dictionary<string, string> {
{"target", "Test"}
});
CakeExecuteScript(path, settings);
});
});
Task("Clean")
.Description("Cleans up (deletes!) the working directory")
.Does(() =>
{
CleanDirectory("./" + WORKING_DIRECTORY);
});
Task("Prepare-Release")
.IsDependentOn("Get-Projects")
.IsDependentOn("Prepare-Release-Nancy")
.IsDependentOn("Update-Projects")
.Does(() =>
{
LogInfo("Preparing release for " + version);
});
Task("Prepare-Release-Nancy")
.Description("Sets the Nancy version that all sub repos depend on")
.Does(() =>
{
var path = GetProjectDirectory("Nancy", WORKING_DIRECTORY) + "/build.cake";
var settings = GetCakeSettings(Context, new Dictionary<string, string> {
{"target", "Prepare-Release"},
{"targetversion", version},
{"nogit", nogit.ToString()}
});
CakeExecuteScript(path, settings);
});
Task("Default")
.IsDependentOn("Get-Projects")
.IsDependentOn("Test-Projects");
Task("Push-SubProjects")
.Does(() => {
SUB_PROJECTS.Skip(1).ToList().ForEach(project => {
LogInfo(string.Format("Updating: {0}", project));
ExecuteGit(GetProjectDirectory(project, WORKING_DIRECTORY), "push origin master", nogit);
ExecuteGit(GetProjectDirectory(project, WORKING_DIRECTORY), "push --tags", nogit);
});
});
RunTarget(target);
public string GetProjectGitUrl(string project, string url)
{
return string.Format("{0}/{1}", url, project);
}
public string GetProjectDirectory(string project, string dir)
{
return string.Format("./{0}/{1}", dir, project);
}
public void LogInfo(string message)
{
Information(logAction => logAction(message));
}
public void ExecuteGit(string workingDir, string command, bool nogit)
{
LogInfo(" - git " + command + " (" + workingDir + ")");
if (!nogit)
{
StartProcess("git", new ProcessSettings {
Arguments = string.Format("{0}", command),
WorkingDirectory = workingDir
});
}
}
public void PrepSubModules(string workingDir, bool nogit)
{
ExecuteGit(workingDir, "submodule init", nogit);
ExecuteGit(workingDir, "submodule update", nogit);
}
public CakeSettings GetCakeSettings(ICakeContext context, IDictionary<string, string> arguments = null)
{
var settings = new CakeSettings { Arguments = arguments };
if (context.Environment.Runtime.IsCoreClr)
{
var cakePath = System.IO.Path
.Combine(Context.Environment.ApplicationRoot.FullPath, "Cake.dll")
.Substring(Context.Environment.WorkingDirectory.FullPath.Length + 1);
settings.ToolPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
settings.ArgumentCustomization = args => string.Concat(cakePath, " ", args.Render());
}
return settings;
}