-
Notifications
You must be signed in to change notification settings - Fork 908
/
Copy pathrecipe.cake
281 lines (235 loc) · 14.5 KB
/
recipe.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.28.4
#tool nuget:?package=WiX&version=3.11.2
///////////////////////////////////////////////////////////////////////////////
// TOOLS
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// SCRIPT
///////////////////////////////////////////////////////////////////////////////
Func<List<ILMergeConfig>> getILMergeConfigs = () =>
{
var mergeConfigs = new List<ILMergeConfig>();
var targetPlatform = "v4,C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.8";
var assembliesToILMerge = GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/*.{exe|dll}")
- GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/choco.exe")
- GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/System.Management.Automation.dll")
- GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/Chocolatey.PowerShell.dll");
Information("The following assemblies have been selected to be ILMerged for choco.exe...");
foreach (var assemblyToILMerge in assembliesToILMerge)
{
Information(assemblyToILMerge.FullPath);
}
mergeConfigs.Add(new ILMergeConfig() {
KeyFile = BuildParameters.StrongNameKeyPath,
LogFile = BuildParameters.Paths.Directories.Build + "/ilmerge-chocoexe.log",
TargetPlatform = targetPlatform,
Target = "exe",
Internalize = BuildParameters.RootDirectoryPath + "/src/chocolatey.console/ilmerge.internalize.ignore.txt",
Output = BuildParameters.Paths.Directories.PublishedApplications + "/choco_merged/choco.exe",
PrimaryAssemblyName = BuildParameters.Paths.Directories.PublishedApplications + "/choco/choco.exe",
AssemblyPaths = assembliesToILMerge });
assembliesToILMerge = GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/*.{exe|dll}")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/choco.exe")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.dll")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/log4net.dll")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/System.Management.Automation.dll")
- GetFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/Chocolatey.PowerShell.dll");
Information("The following assemblies have been selected to be ILMerged for chocolatey.dll...");
foreach (var assemblyToILMerge in assembliesToILMerge)
{
Information(assemblyToILMerge.FullPath);
}
mergeConfigs.Add(new ILMergeConfig() {
KeyFile = BuildParameters.StrongNameKeyPath,
LogFile = BuildParameters.Paths.Directories.Build + "/ilmerge-chocolateydll.log",
TargetPlatform = targetPlatform,
Target = "dll",
Internalize = BuildParameters.RootDirectoryPath + "/src/chocolatey/ilmerge.internalize.ignore.dll.txt",
Output = BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey_merged/chocolatey.dll",
PrimaryAssemblyName = BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.dll",
AssemblyPaths = assembliesToILMerge });
return mergeConfigs;
};
Func<FilePathCollection> getScriptsToVerify = () =>
{
var scriptsToVerify = GetFiles("./src/chocolatey.resources/**/*.{ps1|psm1|psd1}") +
GetFiles(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/**/*.{ps1|psm1|psd1}") +
GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/**/*.{ps1|psm1|psd1}");
Information("The following PowerShell scripts have been selected to be verified...");
foreach (var scriptToVerify in scriptsToVerify)
{
Information(scriptToVerify.FullPath);
}
return scriptsToVerify;
};
Func<FilePathCollection> getScriptsToSign = () =>
{
var scriptsToSign = GetFiles("./nuspec/**/*.{ps1|psm1|psd1}") +
GetFiles("./src/chocolatey.resources/**/*.{ps1|psm1|psd1}");
Information("The following PowerShell scripts have been selected to be signed...");
foreach (var scriptToSign in scriptsToSign)
{
Information(scriptToSign.FullPath);
}
return scriptsToSign;
};
Func<FilePathCollection> getFilesToSign = () =>
{
var filesToSign = GetFiles(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/lib/chocolatey.dll")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/choco.exe")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/tools/{checksum|shimgen}.exe")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/redirects/*.exe")
+ GetFiles(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/helpers/Chocolatey.PowerShell.dll");
Information("The following assemblies have been selected to be signed...");
foreach (var fileToSign in filesToSign)
{
Information(fileToSign.FullPath);
}
return filesToSign;
};
Func<FilePathCollection> getMsisToSign = () =>
{
var msisToSign = GetFiles(BuildParameters.Paths.Directories.Build + "/MSIs/**/*.msi");
Information("The following msi's have been selected to be signed...");
foreach (var msiToSign in msisToSign)
{
Information(msiToSign.FullPath);
}
return msisToSign;
};
///////////////////////////////////////////////////////////////////////////////
// CUSTOM TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Prepare-Chocolatey-Packages")
.IsDependeeOf("Create-Chocolatey-Packages")
.IsDependeeOf("Verify-PowerShellScripts")
.IsDependeeOf("Sign-Assemblies")
.IsDependentOn("Copy-Nuspec-Folders")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping because not running on Windows")
.WithCriteria(() => BuildParameters.ShouldRunChocolatey, "Skipping because execution of Chocolatey has been disabled")
.Does(() =>
{
// Copy legal documents
CopyFile(BuildParameters.RootDirectoryPath + "/docs/legal/CREDITS.md", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/CREDITS.txt");
CopyFile(BuildParameters.Paths.Directories.PublishedApplications + "/choco/LICENSE.txt", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/LICENSE.txt");
// Copy choco.exe.manifest
CopyFile(BuildParameters.Paths.Directories.PublishedApplications + "/choco/choco.exe.manifest", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/choco.exe.manifest");
// Copy external file resources
EnsureDirectoryExists(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/helpers");
CopyFiles(GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/helpers/**/*"), BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/helpers", true);
EnsureDirectoryExists(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/redirects");
CopyFiles(GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/redirects/**/*"), BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/redirects", true);
EnsureDirectoryExists(BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/tools");
CopyFiles(GetFiles(BuildParameters.Paths.Directories.PublishedApplications + "/choco/tools/**/*"), BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/tools", true);
// Copy merged choco.exe
CopyFile(BuildParameters.Paths.Directories.PublishedApplications + "/choco_merged/choco.exe", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/choco.exe");
// Copy Chocolatey.PowerShell.dll and its help.xml file
CopyFile(BuildParameters.Paths.Directories.PublishedLibraries + "/Chocolatey.PowerShell/Chocolatey.PowerShell.dll", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/helpers/Chocolatey.PowerShell.dll");
CopyFile(BuildParameters.Paths.Directories.PublishedLibraries + "/Chocolatey.PowerShell/Chocolatey.PowerShell.dll-help.xml", BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/helpers/Chocolatey.PowerShell.dll-help.xml");
// Tidy up logs and config folder which are not required
var logsDirectory = BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/logs";
var configDirectory = BuildParameters.Paths.Directories.ChocolateyNuspecDirectory + "/tools/chocolateyInstall/config";
if (DirectoryExists(logsDirectory))
{
DeleteDirectory(logsDirectory, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
}
if (DirectoryExists(configDirectory))
{
DeleteDirectory(configDirectory, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
}
});
Task("Prepare-NuGet-Packages")
.WithCriteria(() => BuildParameters.ShouldRunNuGet, "Skipping because execution of NuGet has been disabled")
.IsDependeeOf("Create-NuGet-Packages")
.IsDependeeOf("Verify-PowerShellScripts")
.IsDependeeOf("Sign-Assemblies")
.Does(() =>
{
CleanDirectory(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib");
EnsureDirectoryExists(BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/net48");
// Copy legal documents
CopyFile(BuildParameters.RootDirectoryPath + "/docs/legal/CREDITS.md", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/CREDITS.txt");
CopyFiles(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey_merged/*", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/net48");
CopyFile(BuildParameters.Paths.Directories.PublishedLibraries + "/chocolatey/chocolatey.xml", BuildParameters.Paths.Directories.NuGetNuspecDirectory + "/chocolatey.lib/lib/net48/chocolatey.xml");
});
Task("Prepare-MSI")
.WithCriteria(() => BuildParameters.ShouldBuildMsi, "Skipping because creation of MSI has been disabled")
.IsDependeeOf("Build-MSI")
.Does(() =>
{
var installScriptPath = BuildParameters.RootDirectoryPath + "/src/chocolatey.install/assets/Install.ps1";
if (!FileExists(installScriptPath))
{
DownloadFile(
"https://community.chocolatey.org/install.ps1",
installScriptPath
);
}
});
Task("Create-TarGz-Packages")
.IsDependentOn("Build")
.IsDependeeOf("Package")
.WithCriteria(!IsRunningOnWindows(), "Skipping because this is a Windows build")
.Does(() =>
{
EnsureDirectoryExists(BuildParameters.Paths.Directories.ChocolateyPackages);
var outputFile = string.Format(
"{0}/chocolatey.v{1}.tar.gz",
MakeAbsolute(new DirectoryPath(BuildParameters.Paths.Directories.ChocolateyPackages.FullPath)),
BuildParameters.Version.SemVersion
);
StartProcess(
"tar",
new ProcessSettings {
Arguments = string.Format(
"-czvf {0} .",
outputFile
),
WorkingDirectory = BuildParameters.Paths.Directories.PublishedApplications.FullPath + "/choco/"
}
);
if (FileExists(outputFile))
{
BuildParameters.BuildProvider.UploadArtifact(outputFile);
}
});
///////////////////////////////////////////////////////////////////////////////
// RECIPE SCRIPT
///////////////////////////////////////////////////////////////////////////////
Environment.SetVariableNames();
BuildParameters.SetParameters(context: Context,
buildSystem: BuildSystem,
sourceDirectoryPath: "./src",
solutionFilePath: "./src/chocolatey.sln",
solutionDirectoryPath: "./src/chocolatey",
resharperSettingsFileName: "chocolatey.sln.DotSettings",
title: "Chocolatey",
repositoryOwner: "chocolatey",
repositoryName: "choco",
productName: "Chocolatey",
productDescription: "chocolatey is a product of Chocolatey Software, Inc. - All Rights Reserved.",
productCopyright: string.Format("Copyright © 2017 - {0} Chocolatey Software, Inc. Copyright © 2011 - 2017, RealDimensions Software, LLC - All Rights Reserved.", DateTime.Now.Year),
shouldStrongNameSignDependentAssemblies: false,
treatWarningsAsErrors: false,
getScriptsToVerify: getScriptsToVerify,
getScriptsToSign: getScriptsToSign,
getFilesToSign: getFilesToSign,
getMsisToSign: getMsisToSign,
getILMergeConfigs: getILMergeConfigs,
preferDotNetGlobalToolUsage: !IsRunningOnWindows(),
shouldBuildMsi: false,
msiUsedWithinNupkg: false,
shouldAuthenticodeSignMsis: true,
shouldRunNuGet: IsRunningOnWindows(),
shouldAuthenticodeSignPowerShellScripts: IsRunningOnWindows(),
shouldPublishAwsLambdas: false,
chocolateyNupkgGlobbingPattern: "/**/chocolatey*.nupkg");
ToolSettings.SetToolSettings(context: Context);
BuildParameters.PrintParameters(Context);
Build.Run();