forked from aspnet/Universe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.shade
414 lines (365 loc) · 12.8 KB
/
makefile.shade
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
var PROJECT='AspNet'
var VERSION='0.2.1'
use namespace='System'
use namespace='System.IO'
use namespace='System.Collections.Generic'
use namespace='System.Net'
use namespace='System.Linq'
use namespace='System.Text.RegularExpressions'
use import="BuildEnv"
functions
@{
static string BASE_DIR = Directory.GetCurrentDirectory();
static string TARGET_DIR = Path.Combine(BASE_DIR, "artifacts", "build");
static Dictionary<string, string> sources = new Dictionary<string, string>(){
// The repos list is topologically sorted based on build order
{"Configuration","1.0.0-alpha3"},
{"Caching","1.0.0-alpha3"},
{"DataCommon","1.0.0-alpha3"},
{"DataCommon.SQLite","1.0.0-alpha3"},
{"DataProtection","1.0.0-alpha3"},
{"DependencyInjection","1.0.0-alpha3"},
{"Options","1.0.0-alpha3"},
{"Logging","1.0.0-alpha3"},
{"Testing","1.0.0-alpha3"},
{"Diagnostics","1.0.0-alpha3"},
{"EntityFramework","7.0.0-alpha3"},
{"FileSystem","1.0.0-alpha3"},
{"WebSocketAbstractions","1.0.0-alpha3"},
{"HttpAbstractions","1.0.0-alpha3"},
{"Hosting","1.0.0-alpha3"},
/*{"Helios","1.0.0-alpha3"},*/
{"Identity","3.0.0-alpha3"},
{"Razor","4.0.0-alpha3"},
{"Routing","1.0.0-alpha3"},
{"Mvc","6.0.0-alpha3"},
{"Scaffolding","1.0.0-alpha3"},
{"Security","1.0.0-alpha3"},
{"SignalR-Server","3.0.0-alpha3"},
{"StaticFiles","1.0.0-alpha3"},
/*{"WebListener","1.0.0-alpha3"},*/
{"KestrelHttpServer","1.0.0-alpha3"},
{"WebSockets","1.0.0-alpha3"},
{"Entropy","1.0.0-alpha3"},
};
static string[] repos = sources.Keys.ToArray();
static string[] tags = sources.Values.ToArray();
static bool useHttps = UseHttps(BASE_DIR);
static string gitHubUriPrefix = useHttps ? "https://github.com/aspnet/" : "[email protected]:aspnet/";
}
@{
var kBuildVersion = Environment.GetEnvironmentVariable("K_BUILD_VERSION");
if (!string.IsNullOrEmpty(kBuildVersion))
{
VERSION += "-" + kBuildVersion;
}
else
{
VERSION += "-" + BuildNumber;
}
}
#default .compile
#pull .checkout
#compile .pull
#install .pull
#checkout
#pack
directory create='${TARGET_DIR}'
nuget-pack nuspecFile='${Path.Combine(BASE_DIR, "KoreBuild.nuspec")}' packageVersion='${VERSION}' outputDir='${TARGET_DIR}'
#pack-install .pack
nuget-local-publish sourcePackagesDir='${TARGET_DIR}'
#git-checkout target='checkout'
@{
foreach (var source in sources)
{
var repo = source.Key;
var tag = source.Value;
if(false == Directory.Exists(repo))
{
continue;
}
try
{
GitCommand(repo, "checkout " + tag);
}
catch
{
// If the release branch does not exist, create a new branch and reset origin/dev to it.
GitCommand(repo, "checkout " + "master");
}
}
}
#git-pull target='pull'
@{
foreach(var repo in repos)
{
CloneOrUpdate(repo);
}
}
#init
@{
var templatePath = Path.Combine(BASE_DIR, "build-template");
var templateFiles = Files.Include(templatePath + Path.DirectorySeparatorChar + "*.*").Select(Path.GetFileName).ToList();
foreach(var repo in repos)
{
foreach (string fileName in templateFiles)
{
var targetFile = Path.Combine(Directory.GetCurrentDirectory(), repo, fileName);
var sourceFile = Path.Combine(Directory.GetCurrentDirectory(), templatePath, fileName);
// Don't update the makefile
if(fileName.Equals("makefile.shake", StringComparison.OrdinalIgnoreCase) && File.Exists(targetFile))
{
continue;
}
if(!File.Exists(sourceFile) ||
(File.ReadAllText(sourceFile) != File.ReadAllText(targetFile)))
{
Log.Info("Updating " + fileName + " to " + repo);
File.Copy(sourceFile, targetFile, true);
}
}
}
}
#update-release
-// Merge dev branch to release
@{
foreach (var repo in GetAllRepos())
{
CloneOrUpdate(repo);
try
{
GitCommand(repo, "checkout release");
}
catch
{
// If the release branch does not exist, create a new branch and reset origin/dev to it.
GitCommand(repo, "checkout origin/dev -b release");
}
GitCommand(repo, "merge origin/dev");
GitCommand(repo, "push origin release");
}
}
#reset-master
-// Resets master branch to release
for each='var repo in GetAllRepos()'
-CloneOrUpdate(repo);
var gitFolder = '${repo}'
git gitCommand='fetch origin'
git gitCommand='checkout origin/release -B master'
#push-master
-// Resets master branch to release
for each='var repo in GetAllRepos()'
var gitFolder = '${repo}'
git gitCommand='push origin master:master -f'
#only-compile target='compile'
@{
var failed = new Dictionary<string, Exception>();
foreach(var repo in repos)
{
try
{
Log.Info(string.Format("Building {0}", repo));
if (IsMono)
{
Exec("build.sh", "compile", repo);
}
else
{
Exec("build.cmd", "compile", repo);
}
Log.Info(string.Format("Build {0} succeeded", repo));
}
catch(Exception ex)
{
Log.Warn(string.Format("Build {0} failed: {1}", repo, ex.Message));
failed[repo] = ex;
}
}
foreach(var repo in repos)
{
Exception ex;
if (failed.TryGetValue(repo, out ex))
{
Log.Warn(string.Format("Build {0} failed: {1}", repo, ex.Message));
}
else
{
Log.Info(string.Format("Build {0} succeeded", repo));
}
}
}
#only-install target='install'
@{
foreach(var repo in repos)
{
if (IsMono)
{
Exec("build.sh", "install", repo);
}
else
{
Exec("build.cmd", "install", repo);
}
}
}
#run-snapshot-manager
@{
Exec(@".nuget\nuget.exe", @"restore -out packages tools\TCDependencyManager\packages.config", "");
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var msbuildPath = Path.Combine(programFiles, "MSBuild", "12.0", "Bin", "MsBuild.exe");
Exec(msbuildPath, "TCDependencyManager.csproj", @"tools\TCDependencyManager");
Exec(@"tools\TCDependencyManager\bin\Debug\TCDependencyManager.exe", "", "");
}
#git-status decription='Show status of repos known by Universe'
@{
foreach(var repo in repos)
{
GitStatus(repo);
}
}
#git-clean decription='REMOVE ALL CHANGES to the working directory'
@{
Console.WriteLine("This runs `git clean -xfd` in all non-Universe repos.");
Console.WriteLine("This should REMOVE ALL CHANGES to the working directory.");
Console.Write("***** Are you sure? ***** (Y or anything else)? ");
if (Console.ReadLine() != "Y")
{
throw new Exception("git-clean cancelled");
}
foreach(var repo in repos)
{
GitClean(repo);
}
}
macro name='GitCheckout' gitTag='string'
git-checkout
macro name='GitPull' gitUri='string' gitBranch='string' gitFolder='string'
git-pull
macro name='GitClone' gitUri='string' gitBranch='string'
git-clone
macro name='GitConfig' gitOptionName='string' gitOptionValue='string' gitFolder='string'
git-config
macro name='GitStatus' gitFolder='string'
git gitCommand='status'
macro name='GitClean' gitFolder='string'
git gitCommand='clean -xdf'
macro name='GitCommand' gitFolder='string' gitCommand='string'
git
macro name='Exec' program='string' commandline='string' workingdir='string'
exec
functions
@{
static bool UseHttps(string directory)
{
var filename = Path.Combine(directory, ".git", "config");
if (!File.Exists(filename))
{
Console.WriteLine("Unable to find '{0}' file", filename);
return false;
}
var url = ReadOriginUrl(filename);
return IsHttpsUrl(url);
}
// Perform equivalent of `git config remote.origin.url` but directly
// read config file to get value.
static string ReadOriginUrl(string filename)
{
// Subsection portion of configuration name is case-sensitive; rest
// of name is case-insensitive.
var beginOriginSection = new Regex(@"^\[(?i:remote) ""origin""\]\s*$");
var beginSection = new Regex(@"^\[");
var urlLine = new Regex(@"^\s+url = (\S+)\s*$", RegexOptions.IgnoreCase);
var inRemoteOriginSection = false;
foreach (var line in File.ReadAllLines(filename))
{
if (beginOriginSection.IsMatch(line))
{
inRemoteOriginSection = true;
continue;
}
if (inRemoteOriginSection)
{
if (beginSection.IsMatch(line))
{
// Read through the section without finding URL line.
break;
}
var match = urlLine.Match(line);
if (match.Success && match.Groups.Count == 2 && match.Groups[1].Success)
{
return match.Groups[1].Value;
}
}
}
Console.WriteLine("Unable to parse '{0}' file", filename);
return null;
}
static bool IsHttpsUrl(string url)
{
if (string.IsNullOrEmpty(url))
{
return false;
}
return url.StartsWith("https://", System.StringComparison.OrdinalIgnoreCase);
}
static bool IsAccessible(string key)
{
var req = WebRequest.CreateHttp("https://github.com/aspnet/" + key);
req.Method = "HEAD";
try
{
using (req.GetResponse());
}
catch (WebException ex)
{
if (ex.Response != null &&
((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
{
return false;
}
// Ignore any other exception. They should surface as part of git clone with well-known messages.
}
return true;
}
IEnumerable<string> GetAllRepos()
{
var nonDefaultRepos = new[]
{
"KRuntime",
"Claims",
"DataAnnotations",
"SqlClient",
"MusicStore"
};
return Enumerable.Concat(repos, nonDefaultRepos);
}
void CloneOrUpdate(string repo)
{
var repoUrl = gitHubUriPrefix + repo + ".git";
if(Directory.Exists(repo))
{
GitPull(repoUrl, "dev", repo);
}
else
{
if (useHttps &&
!IsAccessible(repo))
{
Log.Warn(string.Format("The repo at '{0}' is not accessible. If you do not have access to this repository, skip the git prompt" +
" for credentials to skip cloning this repository. To avoid this prompt, re-clone the Universe repository over ssh.",
repoUrl));
}
try
{
GitClone(repoUrl, "dev");
}
catch (Exception ex)
{
Log.Warn(string.Format("Unable to clone repository at '{0}': {1}", repoUrl, ex.Message));
return;
}
GitConfig("bugtraq.url", "http://github.com/aspnet/" + repo + "/issues/%BUGID%", repo);
GitConfig("bugtraq.logregex", @"#(\d+)", repo);
}
}
}