forked from cake-contrib/Cake.Recipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cake
157 lines (133 loc) · 5.34 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
#addin "nuget:https://api.nuget.org/v3/index.json?package=Cake.Git&Version=0.16.1"
////////////////////////////////////////////////////////
/// Global variables
////////////////////////////////////////////////////////
var recipePath = MakeAbsolute(Directory("./BuildArtifacts/Packages/NuGet"));
var testReposRootPath = MakeAbsolute(Directory("./tests/integration/repos"));
var recipeVersion = Argument("recipe-version", "*");
var exceptions = new List<Exception>();
var testRepos = new [] {
new {
Path = testReposRootPath.Combine("Cake.Gulp"),
Url = "https://github.com/cake-contrib/Cake.Gulp.git"
},
new {
Path = testReposRootPath.Combine("Cake.Http"),
Url = "https://github.com/cake-contrib/Cake.Http.git"
},
new {
Path = testReposRootPath.Combine("Cake.Unity"),
Url = "https://github.com/cake-contrib/Cake.Unity.git"
}
};
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 unzipTask = Task("Unzip-Cake-Recipe")
.IsDependentOn("Clone-Repositories")
.Does(() => {
Information("Unzip Cake recipe done.");
});
var testsTask = Task("Tests")
.IsDependentOn("Unzip-Cake-Recipe")
.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 pkg = package;
var pkgName = pkg.GetFilename();
var name = path.GetDirectoryName();
var exs = exceptions;
cloneTask.IsDependentOn(
Task("Clone: " + name)
.Does(context => {
context.Information("Cloning {0}...", url);
context.GitClone(url, path);
}));
unzipTask.IsDependentOn(
Task("Unzip: " + name)
.Does(context => {
var testReposRecipePath = path.Combine("tools").Combine("Cake.Recipe");
context.Information("Unzipping nuget {0} to {1}...", pkgName, testReposRecipePath);
context.EnsureDirectoryExists(testReposRecipePath);
context.Unzip(pkg, testReposRecipePath);
}));
testsTask.IsDependentOn(
Task("Tests: " + name)
.Does(context => {
try
{
var setupCakePath = path.CombineWithFilePath("setup.cake");
context.Information("Testing {0}...", setupCakePath);
var arguments = new Dictionary<string, string>();
if(BuildParameters.CakeConfiguration.GetValue("NuGet_UseInProcessClient") != null) {
arguments.Add("nuget_useinprocessclient", BuildParameters.CakeConfiguration.GetValue("NuGet_UseInProcessClient"));
}
if(BuildParameters.CakeConfiguration.GetValue("Settings_SkipVerification") != null) {
arguments.Add("settings_skipverification", BuildParameters.CakeConfiguration.GetValue("Settings_SkipVerification"));
}
arguments.Add("verbosity", context.Log.Verbosity.ToString("F"));
context.CakeExecuteScript(setupCakePath,
new CakeSettings {
Arguments = arguments
});
}
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);
}