-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.cake
152 lines (127 loc) · 4.55 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
#addin nuget:?package=Cake.Git
#load "./buildConfig.cake"
var config = BuildConfig.Create(Context, BuildSystem);
void DotNetCoreTestGlob(string glob)
{
var directories = GetFiles(glob + "*.Tests/project.json");
foreach(var directory in directories)
{
Information("Found directory {0}", directory);
var directoryName = directory.GetDirectory().Segments.Last();
var resultsFile = "./artifacts/testResults-" + directoryName + ".xml";
var arg = string.Format("-xml \"{0}\"", resultsFile);
var settings = new DotNetCoreTestSettings(){
ArgumentCustomization = args => args.Append(arg)
};
DotNetCoreTest(directory.FullPath, settings);
}
}
bool IsTestable(string path)
{
var projectFile = path + "\\project.json";
return System.IO.File.Exists(projectFile);
}
Setup(context => {
Information("Preparing to build version {0}:", config.SemVer);
});
Task(BuildTasks.UpdateVersion)
.Does(() => {
var files = GetFiles("./**/project.json");
foreach(var file in files)
{
Information("Bumping version: {0}", file);
var path = file.ToString();
var trg = new StringBuilder();
var regExVersion = new System.Text.RegularExpressions.Regex("\"version\":(\\s)?\"\\d.\\d.\\d-\\*\",");
using (var src = System.IO.File.OpenRead(path))
{
using (var reader = new StreamReader(src))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if(line == null)
continue;
line = regExVersion.Replace(line, string.Format("\"version\": \"{0}-*\",", config.Version));
trg.AppendLine(line);
}
}
}
System.IO.File.WriteAllText(path, trg.ToString());
}
});
Task(BuildTasks.UpdateAppVeyor)
.WithCriteria(() => config.IsCiBuild)
.Does(() => {
AppVeyor.UpdateBuildVersion(config.SemVer +"+" + AppVeyor.Environment.Build.Number);
});
Task(BuildTasks.Clean)
.Does(() => {
CleanDirectory(config.ArtifactsDir);
// CleanDirectory("./**/bin/");
// CleanDirectory("./**/obj/");
});
Task(BuildTasks.Build)
.IsDependentOn(BuildTasks.Clean)
.IsDependentOn(BuildTasks.UpdateVersion)
.Does(() => {
DotNetCoreRestore();
var buildSettings = new DotNetCoreBuildSettings(){
Configuration = config.Configuration,
VersionSuffix = config.Suffix,
NoIncremental = true,
};
DotNetCoreBuild(config.SrcDir + "**/project.json");
DotNetCoreBuild(config.TestDir + "**/project.json");
});
Task(BuildTasks.Test)
.IsDependentOn(BuildTasks.Build)
.Does(() => {
DotNetCoreTestGlob(config.TestDir);
});
Task(BuildTasks.Package)
.IsDependentOn(BuildTasks.Test)
.Does(() =>{
var settings = new DotNetCorePackSettings {
Configuration = config.Configuration,
OutputDirectory = config.ArtifactsDir,
VersionSuffix = config.Suffix
};
DotNetCorePack(config.SrcDir + "FluentModelBuilder", settings);
DotNetCorePack(config.SrcDir + "FluentModelBuilder.Relational", settings);
});
Task(BuildTasks.UploadArtifacts)
.IsDependentOn(BuildTasks.Package)
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
var artifacts = GetFiles(config.ArtifactsDir + "*.nupkg");
AppVeyor.AddInformationalMessage("Uploading artifacts");
foreach(var artifact in artifacts.Select(x => x.ToString()))
{
var fileInfo = System.IO.Path.GetFileName(artifact);
Information("Adding " + fileInfo);
AppVeyor.UploadArtifact(artifact, settings => settings.SetArtifactType(AppVeyorUploadArtifactType.NuGetPackage));
}
}
);
Task(BuildTasks.UploadTestResults)
.IsDependentOn(BuildTasks.UpdateAppVeyor)
.IsDependentOn(BuildTasks.Test)
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() => {
var testResults = GetFiles(config.ArtifactsDir + "testResults*.xml");
foreach(var result in testResults)
{
AppVeyor.UploadTestResults(result, AppVeyorTestResultsType.XUnit);
}
});
Task(BuildTasks.Publish)
.IsDependentOn(BuildTasks.UploadTestResults)
.IsDependentOn(BuildTasks.UploadArtifacts)
.Does(() => {
Information("Published");
});
Task(BuildTasks.Default)
.IsDependentOn(BuildTasks.Test);
RunTarget(config.Target);