-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.cake
187 lines (145 loc) · 6.47 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
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
#addin nuget:?package=Cake.XdtTransform&version=0.16.0
#addin nuget:?package=Cake.Powershell&version=0.4.7
#addin nuget:?package=Cake.Http&version=0.5.0
#addin nuget:?package=Cake.Json&version=3.0.1
#addin nuget:?package=Newtonsoft.Json&version=12.0.1
#addin nuget:?package=Cake.Incubator&version=4.0.1
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0
#load local:?path=CakeScripts/helper-methods.cake
var target = Argument<string>("Target", "Default");
var configuration = new Configuration();
var cakeConsole = new CakeConsole();
var configJsonFile = "cake-config.json";
var unicornSyncScript = $"./scripts/Unicorn/Sync.ps1";
/*===============================================
================ MAIN TASKS =====================
===============================================*/
Setup(context =>
{
cakeConsole.ForegroundColor = ConsoleColor.Yellow;
PrintHeader(ConsoleColor.DarkGreen);
var configFile = new FilePath(configJsonFile);
configuration = DeserializeJsonFromFile<Configuration>(configFile);
});
Task("Build-All-Projects")
.IsDependentOn("Build-Solution");
Task("Default")
.WithCriteria(configuration != null)
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Modify-PublishSettings")
.IsDependentOn("Publish-All-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Post-Deploy");
Task("Post-Deploy")
.IsDependentOn("Sync-Unicorn");
Task("Quick-Deploy")
.WithCriteria(configuration != null)
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Modify-PublishSettings")
.IsDependentOn("Publish-All-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder");
/*===============================================
================= SUB TASKS =====================
===============================================*/
Task("Copy-Sitecore-Lib")
.WithCriteria(()=>(configuration.BuildConfiguration == "Local"))
.Does(()=> {
var files = GetFiles(
$"{configuration.WebsiteRoot}/bin/Sitecore*.dll");
var destination = "./sc.lib";
EnsureDirectoryExists(destination);
CopyFiles(files, destination);
});
Task("Publish-All-Projects")
.IsDependentOn("Build-Solution")
.IsDependentOn("Publish-Projects")
.IsDependentOn("Publish-XConnect");
Task("Build-Solution").Does(() => {
MSBuild(configuration.SolutionFile, cfg => InitializeMSBuildSettings(cfg));
});
Task("Publish-Projects").Does(() => {
PublishProjects($"{configuration.ProjectFolder}\\src\\Foundation\\Umbrella.Pantau\\website", configuration.WebsiteRoot);
});
Task("Publish-XConnect").Does(()=>{
DeployFiles(
$"{configuration.ProjectSrcFolder}\\*.dll",
$"{configuration.XConnectRoot}\\bin");
});
Task("Modify-Unicorn-Source-Folder").Does(() => {
var zzzDevSettingsFile = File($"{configuration.WebsiteRoot}/App_config/Include/Sitecore.HabitatHome.Fitness/z.Sitecore.HabitatHome.Fitness.DevSettings.config");
var rootXPath = "configuration/sitecore/sc.variable[@name='{0}']/@value";
var sourceFolderXPath = string.Format(rootXPath, "fitnessSourceFolder");
var directoryPath = MakeAbsolute(new DirectoryPath(configuration.SourceFolder)).FullPath;
var xmlSetting = new XmlPokeSettings {
Namespaces = new Dictionary<string, string> {
{"patch", @"http://www.sitecore.net/xmlconfig/"}
}
};
XmlPoke(zzzDevSettingsFile, sourceFolderXPath, directoryPath, xmlSetting);
});
Task("Modify-PublishSettings").Does(() => {
var publishSettingsOriginal = File($"{configuration.ProjectFolder}/publishsettings.targets");
var destination = $"{configuration.ProjectFolder}/publishsettings.targets.user";
CopyFile(publishSettingsOriginal,destination);
return;
var importXPath = "/ns:Project/ns:Import";
var publishUrlPath = "/ns:Project/ns:PropertyGroup/ns:publishUrl";
var xmlSetting = new XmlPokeSettings {
Namespaces = new Dictionary<string, string> {
{"ns", @"http://schemas.microsoft.com/developer/msbuild/2003"}
}
};
XmlPoke(destination,importXPath,null,xmlSetting);
XmlPoke(destination,publishUrlPath,$"{configuration.InstanceUrl}",xmlSetting);
});
Task("Sync-Unicorn").Does(() => {
var unicornUrl = configuration.InstanceUrl + "unicorn.aspx";
Information("Sync Unicorn items from url: " + unicornUrl);
var authenticationFile = new FilePath($"{configuration.WebsiteRoot}/App_config/Include/Unicorn/Unicorn.SharedSecret.config");
var xPath = "/configuration/sitecore/unicorn/authenticationProvider/SharedSecret";
string sharedSecret = XmlPeek(authenticationFile, xPath);
StartPowershellFile(unicornSyncScript, new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args => {
args.Append("secret", sharedSecret)
.Append("url", unicornUrl);
}));
});
Task("Apply-Xml-Transform").Does(() => {
// target website transforms
Transform($"{configuration.ProjectSrcFolder}\\Fitness.AppItems", configuration.WebsiteRoot);
// xconnect transforms
Transform($"{configuration.ProjectSrcFolder}\\Fitness.Automation\\App_Data\\Config\\sitecore\\MarketingAutomation", $"{configuration.XConnectAutomationServiceRoot}\\App_Data\\Config\\sitecore\\MarketingAutomation");
});
Task("Build-NuGet-Packages")
//.IsDependentOn("Restore-NuGet-Packages")
//.IsDependentOn("Build")
.Does(() =>
{
var nuGetPackSettings = new NuGetPackSettings
{
OutputDirectory = $"{configuration.ProjectSrcFolder}\\NuGetPackages",
IncludeReferencedProjects = true,
Properties = new Dictionary<string, string>
{
{ "Configuration", "Release" },
{ "version", configuration.NuGetVersion },
},
Files = new [] {
new NuSpecContent {Source = "bin/Umbrella.PanTau.dll", Target = "lib/net472/"},
new NuSpecContent {Source = "App_Config/**/*", Target = "."},
}
};
NuGetPack($"{configuration.ProjectFolder}\\src\\Foundation\\Umbrella.Pantau\\website\\Umbrella.Pantau.nuspec", nuGetPackSettings);
// Get the path to the package.
//var package = "";
// Push the package.
//NuGetPush(package, new NuGetPushSettings {
// Source = "",
// ApiKey = "AzureDevOps"
//});
});
RunTarget(target);