-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.cake
139 lines (113 loc) · 3.83 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
#tool "dotnet:?package=GitVersion.Tool&version=5.10.3"
#addin nuget:?package=Cake.Docker&version=1.1.2
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
string version = String.Empty;
string projectTag = "Diogel";
string rootNamespace = "Root";
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() => {
DotNetClean("./Diogel.sln");
});
Task("Restore")
.IsDependentOn("Clean")
.Description("Restoring the solution dependencies")
.Does(() => {
var projects = GetFiles("./**/**/*.csproj");
var settings = new DotNetRestoreSettings
{
Verbosity = DotNetVerbosity.Minimal,
Sources = new [] { "https://api.nuget.org/v3/index.json" }
};
foreach(var project in projects )
{
Information($"Restoring { project.ToString()}");
DotNetRestore(project.ToString(), settings);
}
});
Task("Version")
.IsDependentOn("Restore")
.Does(() =>
{
var result = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true
});
version = result.FullSemVer.ToString();
Information($"Nuget Version: { version.ToString() }");
Information($"Semantic Version: { result.FullSemVer.ToString() }");
});
Task("Build")
.IsDependentOn("Version")
.Does(() => {
var buildSettings = new DotNetCoreBuildSettings {
Configuration = configuration,
};
var projects = GetFiles("./**/**/*.csproj");
foreach(var project in projects )
{
Information($"Building {project.ToString()}");
DotNetBuild(project.ToString(),buildSettings);
}
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
var testSettings = new DotNetCoreTestSettings {
Configuration = configuration,
NoBuild = true,
};
var projects = GetFiles("./tests/Unit/*.csproj");
foreach(var project in projects )
{
Information($"Running Tests : { project.ToString()}");
DotNetTest(project.ToString(), testSettings );
}
});
Task("Publish")
.IsDependentOn("Test")
.Does(() => {
var projects = GetFiles("./src/Api/Api.csproj");
foreach(var project in projects )
{
var publishSettings = new DotNetPublishSettings {
Configuration = configuration,
NoBuild = true,
OutputDirectory = ".publish",
};
Information($"Publishing API : { project.ToString()}");
DotNetPublish(project.ToString(), publishSettings );
}
});
Task("Docker-Build")
.IsDependentOn("Publish")
.Does(() => {
string [] tags = new string[] { $"{ rootNamespace.ToLower() }/{ projectTag.ToLower() }:{version}"};
Information("Building : Docker Image");
var settings = new DockerImageBuildSettings { Tag=tags};
DockerBuild(settings, "./");
});
Task("Docker-Push")
.IsDependentOn("Docker-Build")
.Does(() => {
if (BuildSystem.GitHubActions.IsRunningOnGitHubActions)
{
Information("Pushing : Docker Image");
DockerPush( $"{ rootNamespace.ToLower() }/{ projectTag.ToLower() }:{version}");
}
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Version")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Publish")
.IsDependentOn("Docker-Build")
.IsDependentOn("Docker-Push");
RunTarget(target);