forked from exercism/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
94 lines (77 loc) · 2.96 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
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
var target = Argument("target", "Default");
var exercise = Argument<string>("exercise", null);
var exercisesSourceDir = "./exercises";
var exercisesBuildDir = "./build";
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = System.Environment.ProcessorCount
};
Task("BuildGenerators")
.Does(() => {
DotNetCoreBuild("./generators/Generators.csproj");
});
Task("Clean")
.Does(() => {
CleanDirectory(exercisesBuildDir);
});
// Copy everything to build so we make no changes in the actual files.
Task("CopyExercises")
.IsDependentOn("Clean")
.Does(() => {
CopyDirectory($"{exercisesSourceDir}/{exercise}", $"{exercisesBuildDir}/{exercise}");
});
Task("EnableAllTests")
.IsDependentOn("CopyExercises")
.Does(() => {
var skipRegex = new Regex(@"Skip\s*=\s*""Remove to run test""", RegexOptions.Compiled);
var testFiles = GetFiles(exercisesBuildDir + "/*/*Test.cs");
foreach (var testFile in testFiles) {
var contents = System.IO.File.ReadAllText(testFile.FullPath);
if (skipRegex.IsMatch(contents)) {
var updatedContents = skipRegex.Replace(contents, "");
System.IO.File.WriteAllText(testFile.FullPath, updatedContents);
}
}
});
Task("TestRefactoringProjects")
.IsDependentOn("EnableAllTests")
.Does(() => {
// These projects have a working default implementation, and have
// all the tests enabled. These should pass without any changes.
var refactoringProjects =
GetFiles(exercisesBuildDir + "/*/TreeBuilding.csproj")
+ GetFiles(exercisesBuildDir + "/*/Ledger.csproj")
+ GetFiles(exercisesBuildDir + "/*/Markdown.csproj");
Parallel.ForEach(refactoringProjects, parallelOptions, (project) => DotNetCoreTest(project.FullPath));
});
Task("ReplaceStubWithExample")
.IsDependentOn("TestRefactoringProjects")
.Does(() => {
var allProjects = GetFiles(exercisesBuildDir + "/*/*.csproj");
foreach (var project in allProjects) {
var projectDir = project.GetDirectory();
var projectName = project.GetFilenameWithoutExtension();
var stub = projectDir.GetFilePath(projectName).AppendExtension("cs");
var example = projectDir.GetFilePath("Example.cs");
DeleteFile(stub);
MoveFile(example, stub);
}
});
Task("TestUsingExampleImplementation")
.IsDependentOn("ReplaceStubWithExample")
.Does(() => {
if (string.IsNullOrEmpty(exercise)) {
DotNetCoreTest($"{exercisesBuildDir}/Exercises.sln");
}
else {
DotNetCoreTest($"{exercisesBuildDir}/{exercise}");
}
});
Task("Default")
.IsDependentOn("BuildGenerators")
.IsDependentOn("TestUsingExampleImplementation")
.Does(() => { });
RunTarget(target);