forked from exercism/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
104 lines (82 loc) · 3.16 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
using System.IO;
using System.Text.RegularExpressions;
var target = Argument("target", "Default");
var sourceDir = "./exercises";
var buildDir = "./build";
var defaultSln = buildDir + "/Exercises.Default.sln";
var allSln = buildDir + "/Exercises.All.sln";
var refactoringSln = buildDir + "/Exercises.Refactoring.sln";
var dotNetCoreBuildSettings = new DotNetCoreBuildSettings { NoIncremental = true };
Task("Clean")
.Does(() => {
CleanDirectory(buildDir);
});
// Copy everything to build so we make no changes in the actual files.
Task("CopyExercises")
.IsDependentOn("Clean")
.Does(() => {
CopyDirectory(sourceDir, buildDir);
});
Task("RestoreNugetPackages")
.IsDependentOn("CopyExercises")
.Does(() => {
DotNetCoreRestore(allSln);
});
Task("BuildStubImplementations")
.IsDependentOn("RestoreNugetPackages")
.Does(() => {
DotNetCoreBuild(defaultSln, dotNetCoreBuildSettings);
});
Task("EnableAllTests")
.IsDependentOn("BuildStubImplementations")
.Does(() => {
var skipRegex = new Regex(@"Skip\s*=\s*""Remove to run test""", RegexOptions.Compiled);
var testFiles = GetFiles(buildDir + "/*/*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(() => {
DotNetCoreBuild(refactoringSln, dotNetCoreBuildSettings);
// These projects have a working default implementation, and have
// all the tests enabled. These should pass without any changes.
var refactoringProjects =
GetFiles(buildDir + "/*/TreeBuilding.csproj")
+ GetFiles(buildDir + "/*/Ledger.csproj")
+ GetFiles(buildDir + "/*/Markdown.csproj");
foreach (var refactoringProject in refactoringProjects) {
DotNetCoreTest(refactoringProject.FullPath);
}
});
Task("ReplaceStubWithExample")
.IsDependentOn("TestRefactoringProjects")
.Does(() => {
var allProjects = GetFiles(buildDir + "/*/*.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(() => {
DotNetCoreBuild(allSln, dotNetCoreBuildSettings);
var allProjects = GetFiles(buildDir + "/*/*.csproj");
foreach (var project in allProjects) {
DotNetCoreTest(project.FullPath);
}
});
Task("Default")
.IsDependentOn("TestUsingExampleImplementation")
.Does(() => { });
RunTarget(target);