-
Notifications
You must be signed in to change notification settings - Fork 264
/
build.cake
executable file
·215 lines (195 loc) · 6.43 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
205
206
207
208
209
210
211
212
213
214
215
#tool nuget:?package=Codecov
#addin nuget:?package=Cake.Codecov&version=0.8.0
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
var rootPath = "./";
var srcPath = rootPath + "src/";
var contractPath = rootPath + "contract/";
var testPath = rootPath + "test/";
var distPath = rootPath + "aelf-node/";
var solution = rootPath + "AElf.All.sln";
var srcProjects = GetFiles(srcPath + "**/*.csproj");
var contractProjects = GetFiles(contractPath + "**/*.csproj");
Task("Clean")
.Description("clean up project cache")
.Does(() =>
{
DeleteFiles(distPath + "*.nupkg");
CleanDirectories(srcPath + "**/bin");
CleanDirectories(srcPath + "**/obj");
CleanDirectories(contractPath + "**/bin");
CleanDirectories(contractPath + "**/obj");
CleanDirectories(testPath + "**/bin");
CleanDirectories(testPath + "**/obj");
});
Task("Restore")
.Description("restore project dependencies")
.Does(() =>
{
var restoreSettings = new DotNetCoreRestoreSettings{
ArgumentCustomization = args => {
return args.Append("-v quiet");}
};
DotNetCoreRestore(solution,restoreSettings);
});
Task("Build")
.Description("Compilation project")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
var buildSetting = new DotNetCoreBuildSettings{
Configuration = configuration,
NoRestore = true,
ArgumentCustomization = args => {
return args.Append("/clp:ErrorsOnly")
.Append("/p:GeneratePackageOnBuild=false")
.Append("-v quiet");}
};
DotNetCoreBuild(solution, buildSetting);
});
Task("Build-Release")
.Description("Compilation project")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{ var versionPrefix = EnvironmentVariable("MYGET_VERSION_PREFIX");
var buildVersion = (DateTime.UtcNow.Ticks - 621355968000000000) / 10000000 / 86400;
var buildSetting = new DotNetCoreBuildSettings{
NoRestore = true,
Configuration = "Release",
ArgumentCustomization = args => {
return args.Append("/clp:ErrorsOnly")
.Append("-v quiet")
.Append($"-P:Version={versionPrefix}-{buildVersion}")
.Append("-P:Authors=AElf")
.Append("-o ./nuget")
;}
};
DotNetCoreBuild(solution, buildSetting);
});
Task("Test-with-Codecov")
.Description("operation test_with_codecov")
.IsDependentOn("Build")
.Does(() =>
{
var testSetting = new DotNetCoreTestSettings{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
ArgumentCustomization = args => {
return args
.Append("--logger trx")
.Append("--settings CodeCoverage.runsettings")
.Append("--collect:\"XPlat Code Coverage\"");
}
};
var codecovToken = "$CODECOV_TOKEN";
var actions = new List<Action>();
var testProjects = GetFiles("./test/*.Tests/*.csproj");
foreach(var testProject in testProjects)
{
var action=new Action(()=>{
DotNetCoreTest(testProject.FullPath, testSetting);
// if(codecovToken!=""){
// var dir=testProject.GetDirectory().FullPath;
// var reports = GetFiles(dir + "/TestResults/*/coverage.cobertura.xml");
// foreach(var report in reports)
// {
// Codecov(report.FullPath,"$CODECOV_TOKEN");
// }
// }
});
actions.Add(action);
}
var options = new ParallelOptions {
MaxDegreeOfParallelism = 1,
//CancellationToken = cancellationToken
};
Parallel.Invoke(options, actions.ToArray());
});
Task("Test-with-Codecov-N")
.Description("operation test_with_codecov")
.IsDependentOn("Build")
.Does(() =>
{
var testSetting = new DotNetCoreTestSettings{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
ArgumentCustomization = args => {
return args
.Append("--logger trx")
.Append("--settings CodeCoverage.runsettings")
.Append("--collect:\"XPlat Code Coverage\"");
}
};
var codecovToken = "$CODECOV_TOKEN";
var actions = new List<Action>();
var testProjects = GetFiles("./test/*.Tests/*.csproj");
var testProjectList = testProjects.OrderBy(p=>p.FullPath).ToList();
var n = Argument("number",1);
var parts = Argument("parts",1);
var codecoverage = Argument("codecoverage",true);
Information($"n:{n}, parts:{parts}");
int i=0;
foreach(var testProject in testProjectList)
{
if(i++ % parts == n - 1){
DotNetCoreTest(testProject.FullPath, testSetting);
if(!codecoverage) return;
}
}
});
Task("Run-Unit-Tests")
.Description("operation test")
.IsDependentOn("Build")
.Does(() =>
{
var testSetting = new DotNetCoreTestSettings{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
ArgumentCustomization = args => {
return args.Append("--logger trx");
}
};
var testProjects = GetFiles("./test/*.Tests/*.csproj");
foreach(var testProject in testProjects)
{
DotNetCoreTest(testProject.FullPath, testSetting);
}
});
Task("Upload-Coverage")
.Does(() =>
{
var reports = GetFiles("./test/*.Tests/TestResults/*/coverage.cobertura.xml");
foreach(var report in reports)
{
Codecov(report.FullPath,"$CODECOV_TOKEN");
}
});
Task("Upload-Coverage-Azure")
.Does(() =>
{
Codecov("./CodeCoverage/Cobertura.xml","$CODECOV_TOKEN");
});
Task("Publish-MyGet")
.IsDependentOn("Build-Release")
.Does(() => {
var apiKey = EnvironmentVariable("MYGET_API_KEY");
var pushSettings = new DotNetCoreNuGetPushSettings
{
Source = "https://www.myget.org/F/aelf-project-dev/api/v3/index.json",
ApiKey = apiKey
};
var pkgs = GetFiles("./nuget/*.nupkg");
foreach(var pkg in pkgs)
{
Information($"Publishing \"{pkg}\".");
DotNetCoreNuGetPush(pkg.FullPath, pushSettings);
}
});
Task("Default")
.IsDependentOn("Run-Unit-Tests");
RunTarget(target);