forked from cake-contrib/Cake.Recipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cake
163 lines (141 loc) · 5.41 KB
/
test.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
#addin nuget:?package=Cake.FileHelpers&version=3.2.0
#addin nuget:?package=Cake.Git&version=0.19.0
////////////////////////////////////////////////////////
/// Global variables
////////////////////////////////////////////////////////
var recipePath = MakeAbsolute(Directory("./BuildArtifacts/Packages/NuGet"));
var recipeVersion = Argument("recipe-version", "*");
var shouldCreateGlobalReposFolder = Argument("shouldCreateGlobalReposFolder", true);
var testReposRootPath = MakeAbsolute(Directory(shouldCreateGlobalReposFolder ? "c:/CakeRecipeTests/repos" : "./tests/repos"));
var exceptions = new List<Exception>();
var testRepos = new [] {
new {
Path = testReposRootPath.Combine("Cake.Gulp"),
Url = "https://github.com/cake-contrib/Cake.Gulp.git",
BuildScriptName = "recipe.cake"
},
new {
Path = testReposRootPath.Combine("Cake.Http"),
Url = "https://github.com/cake-contrib/Cake.Http.git",
BuildScriptName = "recipe.cake"
},
new {
Path = testReposRootPath.Combine("Cake.Twitter"),
Url = "https://github.com/cake-contrib/Cake.Twitter.git",
BuildScriptName = "recipe.cake"
}
};
var package = GetFiles(
string.Concat(
recipePath,
"/Cake.Recipe." + recipeVersion + ".nupkg"
)
).FirstOrDefault();
if (package == null)
{
throw new Exception("Failed to find Cake Recipe NuGet Package");
}
////////////////////////////////////////////////////////
/// Main tasks
////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
if (DirectoryExists(testReposRootPath))
{
ForceDeleteDirectory(testReposRootPath.FullPath);
}
EnsureDirectoryExists(testReposRootPath);
});
var cloneTask = Task("Clone-Repositories")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Clone complete.");
});
var updateFileTask = Task("Update-Repo-Cake-Recipe-File")
.IsDependentOn("Clone-Repositories")
.Does(() =>
{
Information("Update Repo Cake.Recipe File done.");
});
var testsTask = Task("Tests")
.IsDependentOn("Update-Repo-Cake-Recipe-File")
.Does(() =>
{
if (exceptions.Any())
{
throw new AggregateException("Integration tests failed", exceptions);
}
Information("Tests complete.");
});
////////////////////////////////////////////////////////
/// Dynamic tasks
////////////////////////////////////////////////////////
Information("Setting up integration tests...");
foreach (var testRepo in testRepos)
{
var url = testRepo.Url;
var path = testRepo.Path;
var name = path.GetDirectoryName();
var exs = exceptions;
cloneTask.IsDependentOn(
Task("Clone: " + name)
.Does(context =>
{
context.Information("Cloning {0}...", url);
context.GitClone(url, path);
}));
updateFileTask.IsDependentOn(
Task("Update file for: " + name)
.Does(context =>
{
// Here we want to search the entry cake file for the load preprocessor directive that is loading Cake.Recipe
// i.e. change this #load nuget:?package=Cake.Recipe&prerelease
// #load nuget:file://<path_to_where_newly_generated_nupkg_lives>?package=Cake.Recipe&prerelease
ReplaceRegexInFiles(
path.CombineWithFilePath(testRepo.BuildScriptName).FullPath,
@"\s*#l(oad)?.*Cake\.Recipe.*",
string.Format("#load nuget:file://{0}?package=Cake.Recipe&prerelease", recipePath));
}));
testsTask.IsDependentOn(
Task("Tests: " + name)
.Does(context =>
{
try
{
var setupCakePath = path.CombineWithFilePath(testRepo.BuildScriptName);
context.Information("Testing {0}...", setupCakePath);
context.CakeExecuteScript(setupCakePath,
new CakeSettings {
Arguments = new Dictionary<string, string>{
{ "verbosity", context.Log.Verbosity.ToString("F") }
}});
}
catch(Exception ex)
{
Error("{0}: {1}", name, ex);
exs.Add(new Exception(
testRepo.Url,
ex
));
}
}));
}
Setup(context =>
{
Information("Starting integration tests...");
});
Teardown(context =>
{
});
RunTarget("Tests");
public static void ForceDeleteDirectory(string path)
{
var directory = new System.IO.DirectoryInfo(path) { Attributes = FileAttributes.Normal };
foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories))
{
info.Attributes = FileAttributes.Normal;
}
directory.Delete(true);
}