forked from cake-build/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.cake
197 lines (171 loc) · 6.74 KB
/
deploy.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
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
194
195
196
197
#tool "nuget:https://www.nuget.org/api/v2/?package=KuduSync.NET"
#addin "nuget:https://www.nuget.org/api/v2/?package=Cake.Kudu"
#addin "nuget:https://www.nuget.org/api/v2/?package=Cake.Git"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
DirectoryPath outputPath = MakeAbsolute(Directory("./output"));
DirectoryPath websitePublishPath = outputPath.Combine("_PublishedWebsites/Cake.Web");
DirectoryPath addinPath = websitePublishPath.Combine("App_Data/libs");
DirectoryPath deploymentPath;
FilePath solutionPath = MakeAbsolute(File("./src/Cake.Web.sln"));
FilePath projectPath = MakeAbsolute(File("./src/Cake.Web/Cake.Web.csproj"));
FilePath addinsXmlPath = addinPath.CombineWithFilePath("../addins.xml").Collapse();
FilePath solutionInfoPath = MakeAbsolute(File("./src/SolutionInfo.cs"));
FilePath webConfigPath = websitePublishPath.CombineWithFilePath("web.config");
DateTime utcNow = DateTime.UtcNow;
string version = string.Format(
"{0}.{1}.{2}.{3}{4:00}",
utcNow.Year,
utcNow.Month,
utcNow.Day,
utcNow.Hour,
utcNow.Minute
);
string semVersion = string.Format(
"{0}+{1}.{2}.{3}",
version,
GitBranchCurrent("./").FriendlyName,
GitLogTip("./").Sha,
System.Environment.MachineName
);
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
if (!Kudu.IsRunningOnKudu)
{
throw new Exception("Not running on Kudu");
}
deploymentPath = Kudu.Deployment.Target;
if (!DirectoryExists(deploymentPath))
{
throw new DirectoryNotFoundException(
string.Format(
"Deployment target directory not found {0}.",
deploymentPath
)
);
}
// Executed BEFORE the first task.
Information("Building version {0}...", semVersion);
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Done building version {0}.", semVersion);
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
//Clean up any artifacts from previous builds
CleanDirectories("./src/**/" + configuration + "/bin");
CleanDirectories("./src/**/" + configuration + "/obj");
CleanDirectories(new [] {
outputPath,
websitePublishPath,
addinPath,
"./src/Cake.Web/bin",
"./src/Cake.Web/obj"
});
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
Information("Restoring {0}...", solutionPath);
NuGetRestore(solutionPath);
});
Task("Create-Solution-Info")
.Does(() =>
{
var assemblyInfoSettings = new AssemblyInfoSettings {
Version = version,
FileVersion = version,
InformationalVersion = semVersion,
Copyright = "Copyright (c) .NET Foundation and Contributors"
};
CreateAssemblyInfo(solutionInfoPath, assemblyInfoSettings);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Create-Solution-Info")
.Does(() =>
{
// Build target web & tests.
Information("Building web {0}...", projectPath);
MSBuild(projectPath, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("TreatWarningsAsErrors","true")
.WithProperty("OutDir", outputPath.FullPath + "/")
.WithTarget("Build")
.WithTarget("ResolveReferences")
.WithTarget("_CopyWebApplication")
.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal));
});
Task("Transform-Warmup")
.IsDependentOn("Build")
.Does(() =>
{
XmlPoke(webConfigPath, "/configuration/system.webServer/applicationInitialization/add[@initializationPage = '/']/@hostName", Kudu.WebSite.HostName);
});
Task("Prefetch-Addins")
.IsDependentOn("Transform-Warmup")
.Does(() =>
{
Information("Parsing {0}...", addinsXmlPath);
var addinIds = new []{
"Cake",
"Cake.Common",
"Cake.Core",
"Cake.Testing"
}.Concat(
from addins in System.Xml.Linq.XDocument.Load(addinsXmlPath.FullPath).Elements("Addins")
from addin in addins.Elements("Addin")
from nuget in addin.Elements("NuGet")
from id in nuget.Attributes("Id")
select id.Value
).ToArray();
Information("Found {0} addins.", addinIds.Length);
foreach(var addinId in addinIds)
{
try
{
Information("Installing addin {0}...", addinId);
NuGetInstall(addinId, new NuGetInstallSettings {
ExcludeVersion = true,
OutputDirectory = addinPath,
Source = new [] { "https://api.nuget.org/v3/index.json" },
Verbosity = NuGetVerbosity.Quiet,
Prerelease = true });
}
catch
{
Information("Failed to install addin {0}.", addinId);
}
}
});
Task("Publish")
.IsDependentOn("Prefetch-Addins")
.Does(() =>
{
Information("Deploying web from {0} to {1}...", websitePublishPath, deploymentPath);
Kudu.Sync(websitePublishPath);
});
Task("Default")
.IsDependentOn("Publish");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);