-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.cake
146 lines (128 loc) · 3.81 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
#addin "nuget:?package=Cake.Docker&version=0.9.4"
#addin "nuget:?package=Cake.MiniCover&version=0.29.0-next20180721071547&prerelease"
const string SOLUTION = "./Harbor.Tagd.sln";
SetMiniCoverToolsProject("./minicover/minicover.csproj");
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var tag = Argument("tag", "latest");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean::Test")
.Does(() =>
{
if(DirectoryExists("./_tests"))
{
DeleteDirectory("./_tests", new DeleteDirectorySettings {
Recursive = true
});
}
});
Task("Clean::Dist")
.Does(() =>
{
if(DirectoryExists("./dist"))
{
DeleteDirectory("./dist", new DeleteDirectorySettings {
Recursive = true
});
}
});
Task("Clean")
.IsDependentOn("Clean::Test")
.IsDependentOn("Clean::Dist")
.Does(() =>
{
DotNetCoreClean(SOLUTION);
});
Task("Restore")
.Does(() =>
{
DotNetCoreRestore();
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild(SOLUTION, new DotNetCoreBuildSettings
{
Configuration = configuration,
ArgumentCustomization = args => args.Append("--no-restore")
});
});
Task("Test")
.IsDependentOn("Build")
.WithCriteria(!Argument("SkipTests", false))
.Does(() =>
{
MiniCover(tool =>
{
foreach(var proj in GetFiles("./test/**/*.csproj"))
{
Information("Testing Project: " + proj);
DotNetCoreTest(proj.FullPath, new DotNetCoreTestSettings
{
NoBuild = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("--no-restore")
});
}
},
new MiniCoverSettings()
.WithAssembliesMatching("./test/**/*.dll")
.WithSourcesMatching("./src/**/*.cs")
.WithNonFatalThreshold()
.GenerateReport(ReportType.CONSOLE)
);
});
Task("Coveralls")
.WithCriteria(TravisCI.IsRunningOnTravisCI)
.Does(() =>
{
MiniCoverReport(new MiniCoverSettings()
.WithCoverallsSettings(c => c.UseTravisDefaults())
.GenerateReport(ReportType.COVERALLS)
);
});
Task("Dist")
.IsDependentOn("Clean::Dist")
.IsDependentOn("Test")
.Does(() =>
{
DotNetCorePublish("./src/Harbor.Tagd/Harbor.Tagd.csproj", new DotNetCorePublishSettings {
OutputDirectory = "./dist",
Configuration = configuration,
ArgumentCustomization = args => args.Append("--no-restore")
});
});
Task("Docker::Build")
.IsDependentOn("Dist")
.Does(() =>
{
DockerBuild(new DockerImageBuildSettings {
Tag = new[]{ $"hylandsoftware/tagd:{tag}" }
}, ".");
});
Task("Docker::Push")
.IsDependentOn("Docker::Build")
.WithCriteria(TravisCI.IsRunningOnTravisCI)
.Does(() =>
{
DockerPush($"hylandsoftware/tagd:{tag}");
if (tag != "latest") {
DockerTag($"hylandsoftware/tagd:{tag}", "hylandsoftware/tagd:latest");
DockerPush($"hylandsoftware/tagd:latest");
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Test");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);