-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile.shade
193 lines (146 loc) · 6.72 KB
/
makefile.shade
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use namespace="System"
use namespace="System.IO"
use import="Console"
use import="Help"
use import="MsBuild"
use import="BuildTime"
functions
@{
static string PROJECT_NAME = "ContosoUniversity2016";
static bool INSTALL_DNX = true; // allow check to be turned off on build server
static string DNX_VERSION = "1.0.0-rc1-update1";
static string DNX_RUNTIME = "clr"; // clr, coreclr, mono
static string DNX_ARCH = "x86"; // x86, x64, arm
static string DNX_OS = "win"; // "win", "osx", "darwin", "linux"
static string DNX_BASE_DIR_ENV_VAR = "DNX.InstallationDirectory";
static string DNX_BASE_DIR = Environment.GetEnvironmentVariable(DNX_BASE_DIR_ENV_VAR) ??
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
static string BASE_DIR = Directory.GetCurrentDirectory();
static string SOURCE_DIR = Path.Combine(BASE_DIR, "src");
static string TOOLS_DIR = Path.Combine(BASE_DIR, "tools");
static string TEST_PROJECT_NAME = "ContosoUniversity.Tests";
static string TEST_PROJECT_DIR = Path.Combine(SOURCE_DIR, TEST_PROJECT_NAME);
static string CONFIGURATION = "Release";
static string PROJECT_FILE = Path.Combine(SOURCE_DIR, PROJECT_NAME + ".sln");
static string DEV_CONNECTION_STRING_ENV_VAR = string.Join(".", PROJECT_NAME, "ConnectionString");
static string TEST_CONNECTION_STRING_ENV_VAR = string.Join(".", PROJECT_NAME + ".Tests", "ConnectionString");
static string DEV_CONNECTION_STRING = Environment.GetEnvironmentVariable(DEV_CONNECTION_STRING_ENV_VAR) ??
"Server=localhost;Database=ContosoUniversity2016;Trusted_Connection=True;MultipleActiveResultSets=true";
static string TEST_CONNECTION_STRING = Environment.GetEnvironmentVariable(TEST_CONNECTION_STRING_ENV_VAR) ??
"Server=localhost;Database=ContosoUniversity2016.Tests;Trusted_Connection=True;MultipleActiveResultSets=true";
}
#default .restore .rdb .rat description="Comprehensive Building|Ensures the environment is initialized: installs dnx if needed and rebuilds the databases."
@{
ReportTime();
WriteLine();
Write("*** ", ConsoleColor.Yellow);
Write("Execute ", ConsoleColor.Cyan);
Write("run.cmd", ConsoleColor.Yellow);
Write(" to start the Kestrel server and browse to the site.", ConsoleColor.Cyan);
WriteLine(" ***", ConsoleColor.Yellow);
WriteLine();
}
#full .clean .restore .build .rdb .rat description="Comprehensive Building|Intended for first build or when you want a fresh, clean local copy"
@{
ReportTime();
}
#dev .clean .restore .build .udb .rat description="Comprehensive Building|Optimized for local dev; Most noteably UPDATES databases instead of REBUILDING"
@{
ReportTime();
}
#clean description="Building|Remove artifacts of a previous build"
@{
StartTarget("Clean");
// clear the artifacts folder from prior builds or this one may fail when doing a 'dnu restore'
var artifactsDir = Path.Combine(SOURCE_DIR, "artifacts");
if (Directory.Exists(artifactsDir))
{
Directory.Delete(artifactsDir, true);
}
var extra = "/t:clean /v:q";
ExecuteMsBuild(PROJECT_FILE, CONFIGURATION, extra);
FinishTarget("Clean");
}
#dnx description="Building|Check for and install DNX."
@{
if (!INSTALL_DNX)
{
WriteLine("Build is configured to skip DNX installation.", ConsoleColor.DarkCyan);
return;
}
StartTarget("DNX");
// assume if dnx.exe exists that dnx has been installed
// dnx runtime directory path will be: DNX_BASE_DIR\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta8\bin\dnx.exe
var dnxDir = string.Format("dnx-{0}-{1}-{2}.{3}", DNX_RUNTIME, DNX_OS, DNX_ARCH, DNX_VERSION);
var dnxPath = Path.Combine(DNX_BASE_DIR, ".dnx", "runtimes", dnxDir, "bin", "dnx.exe");
if (File.Exists(dnxPath))
{
WriteLine("DNX is already installed.", ConsoleColor.DarkCyan);
}
else
{
// todo: investigate use of -Ngen switch
var commandline = string.Format("/C dnvm.cmd install {0} -r {1} -a {2} -OS {3} -p -alias default", DNX_VERSION, DNX_RUNTIME, DNX_ARCH, DNX_OS);
Exec("cmd", commandline);
}
FinishTarget("DNX");
}
#restore .dnx description="Building|Restore packages for the project"
@{
StartTarget("Restore");
// when dnx is installed, the -p flag is included, which updates the user path
// however these changes are not visible in this session. to do: try to refresh
// the path variable in this session, then we won't have to rely on this path
var dnxDir = string.Format("dnx-{0}-{1}-{2}.{3}", DNX_RUNTIME, DNX_OS, DNX_ARCH, DNX_VERSION);
var dnuPath = Path.Combine(DNX_BASE_DIR, ".dnx", "runtimes", dnxDir, "bin", "dnu.cmd");
//Exec("cmd", "/C dnu restore");
Exec("cmd", "/C \"" + dnuPath + "\" restore");
FinishTarget("Restore");
}
#build .dnx .clean .restore description="Building|Build the project"
@{
StartTarget("Build");
var extra = "/t:build /v:q";
ExecuteMsBuild(PROJECT_FILE, CONFIGURATION, extra);
FinishTarget("Build");
}
#udb description="Database Maintenance|Update the Database to the latest version (leave db up to date with migration scripts)"
@{
StartTarget("Update Databases");
Roundhouse(DEV_CONNECTION_STRING, "DEV", "--transaction");
Roundhouse(TEST_CONNECTION_STRING, "TEST", "--transaction");
FinishTarget("Update Databases");
}
#rdb description="Database Maintenance|Rebuild database to the latest version from scratch (useful while working on the schema)"
@{
StartTarget("Rebuild Databases");
Roundhouse(DEV_CONNECTION_STRING, "DEV", "--drop");
Roundhouse(DEV_CONNECTION_STRING, "DEV", "--transaction");
Roundhouse(TEST_CONNECTION_STRING, "TEST", "--drop");
Roundhouse(TEST_CONNECTION_STRING, "TEST", "--transaction");
FinishTarget("Rebuild Databases");
}
#rat description="Running Tests|Run all tests"
@{
StartTarget("Run All Tests");
// when dnx is installed, the -p flag is included, which updates the user path
// however these changes are not visible in this session. to do: try to refresh
// the path variable in this session, then we won't have to rely on this path
var dnxDir = string.Format("dnx-{0}-{1}-{2}.{3}", DNX_RUNTIME, DNX_OS, DNX_ARCH, DNX_VERSION);
var dnxPath = Path.Combine(DNX_BASE_DIR, ".dnx", "runtimes", dnxDir, "bin", "dnx.exe");
//var commandline = string.Format("/C dnx -p {0} test", TEST_PROJECT_DIR);
var commandline = string.Format("/C \"" + dnxPath + "\" -p {0} test", TEST_PROJECT_DIR);
Exec("cmd", commandline);
FinishTarget("Run All Tests");
}
#help description="Help|Displays a list of build commands"
@{
WriteHelp();
}
macro name='Roundhouse' connectionString='string' environment='string' options='string'
roundhouse
@{
// global actions here - will always be performed before first task
// unfortunately, we can't get the arguments that were used in the call
// to check and fail gracefully if the target does not exist
}