-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.cake
152 lines (128 loc) · 3.91 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
#addin "nuget:?package=Cake.StyleCop&version=1.1.0"
#addin "Cake.XdtTransform"
#addin "Cake.SemVer"
#tool "xunit.runner.console"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solutionFile = GetFiles("./*.sln").First();
var solution = new Lazy<SolutionParserResult>(() => ParseSolution(solutionFile));
var distDir = Directory("./dist");
var buildDir = Directory("./build");
Task("Clean")
.IsDependentOn("Clean-Outputs")
.Does(() =>
{
DotNetBuild(solutionFile, settings => settings
.SetConfiguration(configuration)
.WithTarget("Clean")
.SetVerbosity(Verbosity.Minimal));
});
Task("Clean-Outputs")
.Does(() =>
{
CleanDirectory(buildDir);
CleanDirectory(distDir);
});
Task("StyleCop")
.Does(() =>
{
StyleCopAnalyse(settings => settings
.WithSolution(solutionFile)
.WithSettings(File("./Settings.StyleCop"))
.ToResultFile(buildDir + File("StyleCopViolations.xml")));
});
Task("Build")
.IsDependentOn("Clean-Outputs")
.IsDependentOn("StyleCop")
.Does(() =>
{
NuGetRestore(solutionFile);
DotNetBuild(solutionFile, settings => settings
.SetConfiguration(configuration)
.WithTarget("Rebuild")
.SetVerbosity(Verbosity.Minimal));
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
XUnit2(string.Format("./test/**/bin/{0}/*.Tests.dll", configuration), new XUnit2Settings {
XmlReport = true,
OutputDirectory = buildDir
});
});
Task("Packages")
.IsDependentOn("Test")
.WithCriteria(() => Jenkins.IsRunningOnJenkins)
.Does(() =>
{
var projectFilesToPack = solution.Value
.Projects
.Where(p => FileExists(p.Path.ChangeExtension(".nuspec")))
.Select(p => p.Path);
foreach(var project in projectFilesToPack)
{
var assemblyInfo = ParseAssemblyInfo(project.GetDirectory().CombineWithFilePath("./Properties/AssemblyInfo.cs"));
var assemblyVersion = ParseSemVer(assemblyInfo.AssemblyVersion);
var packageVersion = assemblyVersion.Change(prerelease: "pre" + Jenkins.Environment.Build.BuildNumber);
NuGetPack(project, new NuGetPackSettings
{
OutputDirectory = distDir,
Properties = new Dictionary<string, string>
{
{ "Configuration", configuration }
},
Authors = new []{ "John Doe" },
Version = packageVersion.ToString(),
});
}
});
Task("Websites")
.IsDependentOn("Test")
.Does(() =>
{
var webProjects = solution.Value
.Projects
.Where(p => p.Name.EndsWith(".Web"));
foreach(var project in webProjects)
{
Information("Publishing {0}", project.Name);
var publishDir = distDir + Directory(project.Name);
DotNetBuild(project.Path, settings => settings
.SetConfiguration(configuration)
.WithProperty("DeployOnBuild", "true")
.WithProperty("WebPublishMethod", "FileSystem")
.WithProperty("DeployTarget", "WebPublish")
.WithProperty("publishUrl", MakeAbsolute(publishDir).FullPath)
.SetVerbosity(Verbosity.Minimal));
Zip(publishDir, distDir + File(project.Name + ".zip"));
}
});
Task("Consoles")
.IsDependentOn("Test")
.Does(() =>
{
var consoleProjects = solution.Value
.Projects
.Where(p => p.Name.EndsWith(".Console"));
foreach(var project in consoleProjects)
{
Information("Publishing {0}", project.Name);
var projectDir = project.Path.GetDirectory();
var publishDir = distDir + Directory(project.Name);
Information("Copying to output directory");
CopyDirectory(
projectDir.Combine("bin").Combine(configuration),
publishDir);
var configFile = publishDir + File(project.Name + ".exe.config");
var transformFile = projectDir.CombineWithFilePath("App." + configuration + ".config");
Information("Transforming configuration file");
XdtTransformConfig(configFile, transformFile, configFile);
Zip(publishDir, distDir + File(project.Name + ".zip"));
}
});
Task("Default")
.IsDependentOn("Packages")
.IsDependentOn("Websites")
.IsDependentOn("Consoles");
RunTarget(target);