forked from PragmaticFlow/NBomber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
208 lines (175 loc) · 6.65 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
#addin nuget:?package=Cake.Git&version=0.21.0
using LibGit2Sharp;
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var committerName = Argument("username", "cake build script");
var committerEmail = Argument("email", "pragmaticflow.org@gmail.com");
var committerPassword = Argument("password", "");
var solution = File("./NBomber.sln");
var nbomberProject = File("./src/NBomber/NBomber.fsproj");
var nbomberVersion = XmlPeek(nbomberProject, "//Version");
var pluginsDir = Directory($"./.nbomber-plugins/{nbomberVersion}");
var plugins = new[]
{
new PluginInfo
{
GitUrl = "https://github.com/PragmaticFlow/NBomber.Http.git",
DirPath = pluginsDir + Directory("NBomber.Http"),
ProjPath = File("./src/NBomber.Http/NBomber.Http.fsproj"),
SolutionPath = File("./NBomber.Http.sln")
},
new PluginInfo
{
GitUrl = "https://github.com/PragmaticFlow/NBomber.Sinks.InfluxDB.git",
DirPath = pluginsDir + Directory("NBomber.Sinks.InfluxDB"),
ProjPath = File("./src/NBomber.Sinks.InfluxDB/NBomber.Sinks.InfluxDB.fsproj"),
SolutionPath = File("./NBomber.Sinks.InfluxDB.sln")
}
};
Task("Clean")
.Does(() =>
{
CleanDirectories("./src/**/obj");
CleanDirectories("./src/**/bin");
CleanDirectories("./src/examples/**/obj");
CleanDirectories("./src/examples/**/bin");
CleanDirectories("./tests/**/obj");
CleanDirectories("./tests/**/bin");
CleanDirectories("./examples/**/obj");
CleanDirectories("./examples/**/bin");
CleanDirectories("./artifacts/");
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(solution);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
Information("NBomber Version: {0}", nbomberVersion);
DotNetCoreBuild(solution, new DotNetCoreBuildSettings()
{
Configuration = configuration,
ArgumentCustomization = args => args.Append("--no-restore"),
});
});
Task("Test")
.Does(() =>
{
var projects = GetFiles("./tests/**/*.fsproj");
foreach(var project in projects)
{
Information("Testing project " + project);
DotNetCoreTest(project.ToString(),
new DotNetCoreTestSettings()
{
Configuration = configuration,
NoBuild = true,
ArgumentCustomization = args => args.Append("--no-restore"),
});
}
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
OutputDirectory = "./artifacts/",
NoBuild = true,
IncludeSource = true,
IncludeSymbols = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-p:SymbolPackageFormat=snupkg")
};
DotNetCorePack(nbomberProject, settings);
});
Task("BuildPlugins")
.Does(() =>
{
if (DirectoryExists(pluginsDir))
DeleteDirectory(pluginsDir, new DeleteDirectorySettings { Recursive = true, Force = true });
EnsureDirectoryExists(pluginsDir);
foreach (var plugin in plugins)
{
var branchName = "dev";
var projPath = plugin.GetAbsoluteProjPath();
var slnPath = plugin.GetAbsoluteSolutionPath();
Information("Cloning {0} branch for repository {1} to directory {2}",
branchName, plugin.GitUrl, pluginsDir);
GitClone(plugin.GitUrl, plugin.DirPath, new GitCloneSettings { BranchName = branchName });
// update plugin project version
Information("Updating plugin project version on '{0}'", nbomberVersion);
var pluginVersionXPath = "/Project/PropertyGroup/Version";
XmlPoke(projPath, pluginVersionXPath, nbomberVersion);
// update NBomber reference version
Information("Updating NBomber reference package on '{0}'", nbomberVersion);
var nbomberReferenceVersionXPath = "/Project/ItemGroup/PackageReference[@Include = 'NBomber']/@Version";
XmlPoke(projPath, nbomberReferenceVersionXPath, nbomberVersion);
// update appveyor.yml
Information("Updating appveyor.yml");
var appveyorPath = System.IO.Path.Combine(plugin.DirPath, "appveyor.yml");
var appveyorContent = System.IO.File.ReadAllLines(appveyorPath);
appveyorContent[0] = String.Format("version: {0}-{{build}}", nbomberVersion);
System.IO.File.WriteAllLines(appveyorPath, appveyorContent);
// build and test plugin
Information("Build plugin solution");
DotNetCoreBuild(slnPath, new DotNetCoreBuildSettings { Configuration = configuration });
// commit all changes
Information("Commiting all changes");
GitAddAll(plugin.DirPath);
try
{
// commit can fail in case of 0 changes
GitCommit(plugin.DirPath, committerName, committerEmail, String.Format("version: {0}", nbomberVersion));
}
catch (Exception ex)
{
Warning(ex.ToString());
}
}
});
Task("PublishPlugins")
.Does(() =>
{
foreach (var plugin in plugins)
{
Information("Publish plugin: '{0}'", plugin.DirPath);
GitPush(plugin.DirPath, committerName, committerPassword);
}
});
Task("MergePluginsToMaster")
.Does(() =>
{
if (DirectoryExists(pluginsDir))
DeleteDirectory(pluginsDir, new DeleteDirectorySettings { Recursive = true, Force = true });
EnsureDirectoryExists(pluginsDir);
foreach (var plugin in plugins)
{
Information("clone master branch for plugin: '{0}'", plugin.GitUrl);
GitClone(plugin.GitUrl, plugin.DirPath, new GitCloneSettings { BranchName = "master" });
Information("merge dev into master");
using (var repo = new Repository(plugin.DirPath))
{
var comitterInfo = new Signature(committerName, committerEmail, System.DateTime.UtcNow);
var mergeResult = repo.Merge(repo.Branches["remotes/origin/dev"], comitterInfo);
}
Information("add tag");
GitTag(plugin.DirPath, $"version-{nbomberVersion}");
}
});
Task("Default")
.IsDependentOn("Build");
RunTarget(target);
public class PluginInfo
{
public string GitUrl { get; set; }
public ConvertableDirectoryPath DirPath { get; set; }
public ConvertableFilePath ProjPath { get; set; }
public ConvertableFilePath SolutionPath { get; set; }
public ConvertableFilePath GetAbsoluteProjPath () => DirPath + ProjPath;
public ConvertableFilePath GetAbsoluteSolutionPath () => DirPath + SolutionPath;
}