-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cake
145 lines (120 loc) · 4.13 KB
/
Main.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
#load "DotNet.cake"
#load "Git.cake"
#load "Npm.cake"
#load "NuGet.cake"
public static class Build
{
public static class Folders
{
public const string Source = "src";
public const string Test = "test";
public const string Publish = "publish";
}
public static readonly string Version = $"{Environment.GetEnvironmentVariable("BUILD_NUMBER") ?? "1.0.0"}{GetBranchName()}";
public static string Configuration { get; private set; } = "Debug";
public static List<Project> UnitTests { get; set; } = new List<Project>();
public static List<Project> IntegrationTests { get; set; } = new List<Project>();
public static List<Project> Spas { get; set; } = new List<Project>();
public static List<Project> ToBePublished { get; set; } = new List<Project>();
public static List<Project> ToBePackedByNuGet { get; set; } = new List<Project>();
public static List<Project> NuGetPackages { get; set; } = new List<Project>();
public static void SetReleaseConfiguration() => Configuration = "Release";
private static string GetBranchName()
{
var branch = Git.CurrentBranch();
return branch.IsMaster()
? string.Empty
: $"-{branch}";
}
}
public class Project
{
public Project(string name, string path)
{
Name = name;
Path = path;
}
public string Name { get; }
public string Path { get; }
}
public static Project FromFolder(this string name, string folder) => new Project(name, System.IO.Path.Combine(folder, name));
public static Project FromSourceFolder(this string name) => name.FromFolder(Build.Folders.Source);
public static Project FromTestFolder(this string name) => name.FromFolder(Build.Folders.Test);
public static Project FromPublishFolder(this string name) => name.FromFolder(Build.Folders.Publish);
public static Project AddUnitTests(this Project project)
{
Build.UnitTests.Add(project);
return project;
}
public static Project AddIntegrationTests(this Project project)
{
Build.IntegrationTests.Add(project);
return project;
}
public static Project AddSpa(this Project project, string spaDirectory)
{
Build.Spas.Add(new Project(project.Name, System.IO.Path.Combine(project.Path, spaDirectory)));
return project;
}
public static Project Publish(this Project project)
{
Build.ToBePublished.Add(project);
return FromPublishFolder(project.Name);
}
public static Project DeployNuGetPackage(this Project project)
{
Build.ToBePackedByNuGet.Add(project);
var result = new Project(project.Name, NuGet.GetPackagePath(project.Name));
Build.NuGetPackages.Add(result);
return result;
}
Task("config")
.Does(() =>
{
Information("\r\nUnit tests:");
foreach (var project in Build.UnitTests)
Information($" - Name={project.Name}; Path={project.Path}");
Information("\r\nIntegration tests:");
foreach (var project in Build.IntegrationTests)
Information($" - Name={project.Name}; Path={project.Path}");
Information("\r\nSPAs:");
foreach (var project in Build.Spas)
Information($" - Name={project.Name}; Path={project.Path}");
Information("\r\nTo be published:");
foreach (var project in Build.ToBePublished)
Information($" - Name={project.Name}; Path={project.Path}");
Information("\r\nTo be packed by NuGet:");
foreach (var project in Build.ToBePackedByNuGet)
Information($" - Name={project.Name}; Path={project.Path}");
Information("\r\nNuGet packages:");
foreach (var project in Build.NuGetPackages)
Information($" - Name={project.Name}; Path={project.Path}");
});
Task("set-release-config")
.Does(() =>
{
Build.SetReleaseConfiguration();
Information($"Configuration set to '{Build.Configuration}'");
});
Task("build")
.IsDependentOn("dotnet-version")
.IsDependentOn("dotnet-clean")
.IsDependentOn("dotnet-restore")
.IsDependentOn("npm-install")
.IsDependentOn("dotnet-build");
Task("test")
.IsDependentOn("dotnet-unit-tests")
.IsDependentOn("npm-test");
Task("ci")
.IsDependentOn("build")
.IsDependentOn("test")
.IsDependentOn("dotnet-integration-tests");
Task("cd")
.IsDependentOn("dotnet-publish")
.IsDependentOn("git-tag-build")
.IsDependentOn("nuget-pack")
.IsDependentOn("nuget-push");
Task("release")
.IsDependentOn("set-release-config")
.IsDependentOn("ci")
.IsDependentOn("cd");