-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
140 lines (115 loc) · 3.49 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
#addin nuget:?package=Cake.Terraform&version=0.11.0
var target = Argument("target", "Default");
var migration = Argument("migration", "");
var configuration = Argument("configuration", "Release");
const string solution = "BituBooking";
var startupMigrationProj = "-s src/BituBooking.Api/BituBooking.Api.csproj ";
var migrationProj = "-p src/BituBooking.Infra.Storage.Postgres/BituBooking.Infra.Storage.Postgres.csproj ";
var projectsVariables = startupMigrationProj + migrationProj;
//////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////
var taskClean = Task("Clean")
.WithCriteria(c => HasArgument("rebuild"))
.Does(() =>
{
CleanDirectory($"./src/**/bin");
});
var taskBuild = Task("build")
.IsDependentOn("clean")
.Does(() =>
{
DotNetBuild($"./{solution}.sln", new DotNetCoreBuildSettings
{
Configuration = configuration,
});
});
Task("database-clean")
.Does(() =>
{
var command = "ef database update 0 ";
command += projectsVariables;
command += "-v";
DotNetTool(command);
});
var taskDatabaseUpdate = Task("database-update")
.Does(() =>
{
var command = "ef database update ";
command += projectsVariables;
command += "-v";
DotNetTool(command);
});
Task("migration-remove")
.Does(() =>
{
var command = "ef migrations remove ";
command += projectsVariables;
DotNetTool(command);
});
Task("migration-add")
.IsDependentOn(taskBuild)
.Does(() =>
{
if(string.IsNullOrWhiteSpace(migration))
{
throw new ArgumentException("Migration is mandatory", nameof(migration));
}
var command = "ef migrations add ";
command += "--no-build ";
command += migration + " ";
command += projectsVariables;
DotNetTool(command);
});
var taskTerraformInit = Task("terraform-init")
.Does(() =>
{
// var configs = new Cake.Terraform.Init.TerraformInitSettings
// {
// BackendConfigOverrides = new Dictionary<string, string>
// {
// {"chdir", "./deployments/terraform"}
// },
// ForceCopy = true
// };
// TerraformInit(configs);
StartProcess("terraform", "-chdir=./deployments/terraform init");
});
var taskTerraformApply = Task("terraform-apply")
.IsDependentOn(taskTerraformInit)
.Does(() =>
{
// var settings = new Cake.Terraform.Apply.TerraformApplySettings
// {
// InputVariables = new Dictionary<string, string>
// {
// {"chdir", "./deployments/terraform"}
// }
// };
// TerraformApply(settings);
StartProcess("terraform", "-chdir=./deployments/terraform apply -auto-approve");
});
var taskIntegrationTest = Task("dotnet-test")
.IsDependentOn(taskBuild)
.IsDependentOn(taskDatabaseUpdate)
.IsDependentOn(taskTerraformApply)
.Does(() =>
{
DotNetTest("./tests/BituBooking.Integration/BituBooking.Integration.csproj");
});
var taskPublish = Task("dotnet-deploy")
.Does(() =>
{
DotNetPublish("./src/BituBooking.Api",new DotNetPublishSettings
{
Configuration = "Release",
OutputDirectory = "./artifacts/"
});
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);