-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
133 lines (99 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
#addin nuget:https://www.nuget.org/api/v2/?package=Cake.Docker
#addin nuget:https://www.nuget.org/api/v2/?package=Cake.FileHelpers
#addin nuget:https://www.nuget.org/api/v2/?package=Cake.Docker
#addin nuget:https://www.nuget.org/api/v2/?package=Cake.AssemblyInfoReflector
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Full-Build");
var configuration = Argument("configuration", "Release");
var dockerPushCurrentVersion = HasArgument("dockerPushCurrentVersion");
var dockerPushAdditionalTag = Argument<string>("dockerPushAdditionalTag", null);
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var outputDir = Directory("Output/");
var artifactsDir = outputDir + Directory("Artifacts/");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDir);
});
Task("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreRestore("NAME.Registry.API.sln");
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var dotNetBuildConfig = new DotNetCoreBuildSettings() {
Configuration = configuration
};
DotNetCoreBuild("NAME.Registry.API.sln", dotNetBuildConfig);
});
Task("Run-Unit-Tests")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var files = GetFiles("./unit-tests/**/*.csproj");
foreach (var file in files) {
DotNetCoreTool(file, "xunit", "-trait \"TestCategory=\"Unit\"\"");
}
});
Task("Publish-Website")
.IsDependentOn("Clean")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var registryApiLocation = artifactsDir + Directory("NAME.Registry.API/");
var settings = new DotNetCorePublishSettings {
Configuration = configuration,
OutputDirectory = registryApiLocation
};
DotNetCorePublish("./src/NAME.Registry.API", settings);
Zip("./Output/Artifacts", "./Output/Artifacts/NAME.Registry.API.zip", "./Output/Artifacts/**/*");
});
Task("Docker-Build-AND-Push")
.Does(() =>
{
var registryApiLocation = artifactsDir + Directory("NAME.Registry.API/");
var reflectedAssemblyInfo = ReflectAssemblyInfo(registryApiLocation + File("NAME.Registry.API.dll"));
var currentVersion = reflectedAssemblyInfo.AssemblyFileVersion;
var dockerImage = "nosinovacao/name-registry-api";
var tags = new List<string>();
if (dockerPushCurrentVersion)
tags.Add(dockerImage + ":" + currentVersion);
if (!string.IsNullOrWhiteSpace(dockerPushAdditionalTag))
tags.Add(dockerImage + ":" + dockerPushAdditionalTag);
var buildSettings = new DockerBuildSettings() {
Tag = tags.ToArray()
};
DockerBuild(buildSettings, registryApiLocation);
foreach(var tag in tags) {
DockerPush(tag);
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Build-AND-Test")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests");
Task("AppVeyor")
.IsDependentOn("Run-Unit-Tests");
Task("TravisCI")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Publish-Website");
Task("Default")
.IsDependentOn("Build-AND-Test");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);