forked from chocolatey/ChocolateyGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe.cake
291 lines (248 loc) · 14.1 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
282
283
284
285
286
287
288
289
290
291
#load nuget:https://pkgs.dev.azure.com/cake-contrib/Home/_packaging/addins/nuget/v3/index.json?package=Cake.Recipe&version=2.0.0-alpha0276&prerelease
///////////////////////////////////////////////////////////////////////////////
// MODULES
///////////////////////////////////////////////////////////////////////////////
#module nuget:?package=Cake.Chocolatey.Module&version=0.3.0
#module nuget:?package=Cake.BuildSystems.Module&version=0.3.1
///////////////////////////////////////////////////////////////////////////////
// TOOLS
///////////////////////////////////////////////////////////////////////////////
#tool choco:?package=transifex-client&version=0.12.4
#tool nuget:?package=Brutal.Dev.StrongNameSigner&version=2.4.0
///////////////////////////////////////////////////////////////////////////////
// ADDINS
///////////////////////////////////////////////////////////////////////////////
#addin nuget:?package=Cake.StrongNameSigner&version=0.1.0
#addin nuget:?package=Cake.StrongNameTool&version=0.0.4
if(BuildSystem.IsLocalBuild)
{
Environment.SetVariableNames(
githubTokenVariable: "CHOCOLATEYGUI_GITHUB_TOKEN",
appVeyorApiTokenVariable: "CHOCOLATEYGUI_APPVEYOR_API_TOKEN",
wyamAccessTokenVariable: "CHOCOLATEYGUI_WYAM_ACCESS_TOKEN",
wyamDeployRemoteVariable: "CHOCOLATEYGUI_WYAM_DEPLOY_REMOTE",
wyamDeployBranchVariable: "CHOCOLATEYGUI_WYAM_DEPLOY_BRANCH",
transifexApiTokenVariable: "CHOCOLATEYGUI_TRANSIFEX_API_TOKEN"
);
}
else
{
Environment.SetVariableNames();
}
BuildParameters.SetParameters(context: Context,
buildSystem: BuildSystem,
sourceDirectoryPath: "./Source",
solutionFilePath: "./Source/ChocolateyGui.sln",
solutionDirectoryPath: "./Source/ChocolateyGui",
resharperSettingsFileName: "ChocolateyGui.sln.DotSettings",
title: "Chocolatey GUI",
repositoryOwner: "chocolatey",
repositoryName: "ChocolateyGUI",
appVeyorAccountName: "chocolatey",
appVeyorProjectSlug: "chocolateygui",
shouldDownloadFullReleaseNotes: true,
shouldDownloadMilestoneReleaseNotes: true,
shouldPublishChocolatey: false,
shouldPublishNuGet: false,
shouldPublishGitHub: false,
shouldRunGitVersion: true,
webLinkRoot: "ChocolateyGUI",
webBaseEditUrl: "https://github.com/chocolatey/ChocolateyGUI/tree/develop/docs/input/");
ToolSettings.SetToolSettings(context: Context,
dupFinderExcludePattern: new string[] {
BuildParameters.RootDirectoryPath + "/Source/ChocolateyGui.Common.Windows/Utilities/Converters/BooleanToVisibilityInverted.cs",
BuildParameters.RootDirectoryPath + "/Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiModule.cs",
BuildParameters.RootDirectoryPath + "/Source/ChocoalteyGuiCli/Startup/ChocolateyGuiCliModule.cs"
},
buildMSBuildToolVersion: MSBuildToolVersion.VS2019
);
BuildParameters.PrintParameters(Context);
//var SIGN_TOOL = EnvironmentVariable("SIGN_TOOL") ?? @"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe";
var CERT_PATH = EnvironmentVariable("CHOCOLATEY_OFFICIAL_CERT") ?? "";
var CERT_PASSWORD = EnvironmentVariable("CHOCOLATEY_OFFICIAL_CERT_PASSWORD") ?? "";
var CERT_TIMESTAMP_URL = EnvironmentVariable("CERT_TIMESTAMP_URL") ?? "http://timestamp.digicert.com";
var CERT_ALGORITHM = EnvironmentVariable("CERT_ALGORITHM") ?? "Sha256";
var STRONG_KEY_PATH = "";
// todo: we need a hook in AFTER compiling before the copy, but it currently
// involves a lot of work to reimplement the Build task to split CopyOutputFiles
// away as a separate task
// So for now, we will just look to sign the executables prior to building MSI
Task("SignExecutable")
.WithCriteria(() => {
return !string.IsNullOrWhiteSpace(CERT_PATH) && FileExists(CERT_PATH);
})
.Does(() =>
{
// needs to bake into VS or separate out to two build steps (two solutions)
// compilation as a Cake step
// from maintenance it is better to separate out to two solution files
//C:\codelocal\chocolateygui\BuildArtifacts\temp\_PublishedApplications\ChocolateyGui\ChocolateyGui.exe
var filesToSign = new List<string>() {
BuildParameters.Paths.Directories.PublishedApplications + "/ChocolateyGui/ChocolateyGui.exe",
BuildParameters.Paths.Directories.PublishedApplications + "/ChocolateyGui/ChocolateyGui.Common.dll",
BuildParameters.Paths.Directories.PublishedApplications + "/ChocolateyGui/ChocolateyGui.Common.Windows.dll",
BuildParameters.Paths.Directories.PublishedApplications + "/ChocolateyGuiCli/ChocolateyGuiCli.exe",
BuildParameters.Paths.Directories.PublishedApplications + "/ChocolateyGuiCli/ChocolateyGui.Common.dll",
BuildParameters.Paths.Directories.PublishedLibraries + "/ChocolateyGui.Common/ChocolateyGui.Common.dll",
BuildParameters.Paths.Directories.PublishedLibraries + "/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.dll"
};
var platformTarget = ToolSettings.BuildPlatformTarget == PlatformTarget.MSIL ? "AnyCPU" : ToolSettings.BuildPlatformTarget.ToString();
foreach(var project in ParseSolution(BuildParameters.SolutionFilePath).GetProjects())
{
var parsedProject = ParseProject(project.Path, BuildParameters.Configuration, platformTarget);
if (parsedProject.RootNameSpace == "ChocolateyGui")
{
filesToSign.Add(parsedProject.OutputPaths.First().FullPath + "/ChocolateyGui.exe");
continue;
}
if (parsedProject.RootNameSpace == "ChocolateyGuiCli")
{
filesToSign.Add(parsedProject.OutputPaths.First().FullPath + "/ChocolateyGuiCli.exe");
continue;
}
if (parsedProject.RootNameSpace == "ChocolateyGui.Common")
{
filesToSign.Add(parsedProject.OutputPaths.First().FullPath + "/ChocolateyGui.Common.dll");
continue;
}
if (parsedProject.RootNameSpace == "ChocolateyGui.Common.Windows")
{
filesToSign.Add(parsedProject.OutputPaths.First().FullPath + "/ChocolateyGui.Common.Windows.dll");
continue;
}
}
var password = System.IO.File.ReadAllText(CERT_PASSWORD);
foreach(var fileToSign in filesToSign)
{
Information("Signing '{0}' with {1}", fileToSign, CERT_PATH);
// Sign(fileToSign, new SignToolSignSettings {
// TimeStampUri = new Uri(CERT_TIMESTAMP_URL),
// CertPath = CERT_PATH,
// Password = password,
// DigestAlgorithm = SignToolDigestAlgorithm.Sha1,
// TimeStampDigestAlgorithm = SignToolDigestAlgorithm.Sha1
// });
// takes the last signed settings
Sign(fileToSign, new SignToolSignSettings {
TimeStampUri = new Uri(CERT_TIMESTAMP_URL),
CertPath = CERT_PATH,
Password = password,
DigestAlgorithm = (SignToolDigestAlgorithm)Enum.Parse(typeof(SignToolDigestAlgorithm), CERT_ALGORITHM, true),
TimeStampDigestAlgorithm = (SignToolDigestAlgorithm)Enum.Parse(typeof(SignToolDigestAlgorithm), CERT_ALGORITHM, true)
});
}
});
Task("BuildMSI")
.IsDependentOn("SignExecutable")
.Does(() => RequireTool(ToolSettings.MSBuildExtensionPackTool, () => {
Information("Building MSI", BuildParameters.SolutionFilePath);
var msbuildSettings = new MSBuildSettings()
.SetPlatformTarget(PlatformTarget.x86)
.UseToolVersion(ToolSettings.BuildMSBuildToolVersion)
.WithProperty("TreatWarningsAsErrors","true")
.WithProperty("MSBuildExtensionsPath32", "C:/Program Files (x86)/MSBuild")
.WithTarget("Build")
.SetMaxCpuCount(ToolSettings.MaxCpuCount)
.SetConfiguration("WIX")
.WithLogger(
Context.Tools.Resolve("MSBuild.ExtensionPack.Loggers.dll").FullPath,
"XmlFileLogger",
string.Format(
"logfile=\"{0}\";invalidCharReplacement=_;verbosity=Detailed;encoding=UTF-8",
BuildParameters.Paths.Directories.Build + "/MSBuild.msi.log")
);
MSBuild(BuildParameters.SolutionFilePath, msbuildSettings);;
}));
Task("SignMSI")
.IsDependentOn("BuildMSI")
.WithCriteria(() => {
return !string.IsNullOrWhiteSpace(CERT_PATH) && FileExists(CERT_PATH);
})
.Does(() =>
{
var msiPath = BuildParameters.Paths.Directories.Build + "/ChocolateyGUI.msi";
var password = System.IO.File.ReadAllText(CERT_PASSWORD);
Information("Signing '{0}' with {1}", msiPath, CERT_PATH);
Sign(msiPath, new SignToolSignSettings {
TimeStampUri = new Uri(CERT_TIMESTAMP_URL),
CertPath = CERT_PATH,
Password = password,
DigestAlgorithm = (SignToolDigestAlgorithm)Enum.Parse(typeof(SignToolDigestAlgorithm), CERT_ALGORITHM, true),
TimeStampDigestAlgorithm = (SignToolDigestAlgorithm)Enum.Parse(typeof(SignToolDigestAlgorithm), CERT_ALGORITHM, true)
});
// dual signing Sha1 and Sha256 for an MSI would require https://github.com/puppetlabs/packaging/blob/8f5c5ff19fa1c495cc82b608464b3bd7e23a2e27/lib/packaging/msi.rb#L14-L63
// Sign(msiPath, new SignToolSignSettings {
// TimeStampUri = new Uri(CERT_TIMESTAMP_URL),
// CertPath = CERT_PATH,
// Password = password,
// TimeStampDigestAlgorithm = SignToolDigestAlgorithm.Sha1
// });
});
Task("Create-Solution-Info-File")
.IsDependeeOf("Clean")
.Does<BuildVersion>((context, buildVersion) =>
{
var officialStrongNameKey = EnvironmentVariable("CHOCOLATEYGUI_OFFICIAL_KEY");
var localUnofficialStrongNameKey = BuildParameters.RootDirectoryPath.CombineWithFilePath("chocolateygui.snk").FullPath;
if (BuildParameters.Configuration == "ReleaseOfficial" && !string.IsNullOrWhiteSpace(officialStrongNameKey) && FileExists(officialStrongNameKey))
{
Information("Using Official Strong Name Key...");
STRONG_KEY_PATH = officialStrongNameKey;
}
else if (FileExists(localUnofficialStrongNameKey))
{
Information("Using local Unofficial Strong Name Key...");
STRONG_KEY_PATH = localUnofficialStrongNameKey;
}
else
{
Information("Creating new unofficial Strong Name Key...");
var newChocolateyUnofficialKey = MakeAbsolute(new FilePath(string.Format("{0}.snk", BuildParameters.Title)));
// If the file already exists, don't re-create it
if (!FileExists(newChocolateyUnofficialKey))
{
// The Cake.StrongNameTool Addin doesn't have an alias for creating a new key, so here I am really
// abusing an existing alias, and making it run the -k argument. I plan of raising a PR to the addin
// to add an actual alias for doing this, for now this, this works, just not pretty.
var settings = new StrongNameToolSettings();
settings.ArgumentCustomization = arts => new ProcessArgumentBuilder().Append(string.Format("-k {0}", newChocolateyUnofficialKey.FullPath));
StrongNameVerify(BuildParameters.SolutionFilePath, settings);
}
STRONG_KEY_PATH = newChocolateyUnofficialKey.FullPath;
}
// create SolutionVersion.cs file...
var assemblyInfoSettings = new AssemblyInfoSettings {
Company = "Chocolatey",
Version = buildVersion.AssemblySemVer,
FileVersion = string.Format("{0}.0", buildVersion.Version),
InformationalVersion = buildVersion.InformationalVersion,
Product = "Chocolatey GUI",
Copyright = "Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC"
};
var assemblyKeyFileAttribute = new AssemblyInfoCustomAttribute
{
Name = "AssemblyKeyFile",
Value = STRONG_KEY_PATH.Replace("\\", "\\\\").Replace("/", "\\\\"),
NameSpace = "System.Reflection"
};
assemblyInfoSettings.CustomAttributes = new List<AssemblyInfoCustomAttribute>();
assemblyInfoSettings.CustomAttributes.Add(assemblyKeyFileAttribute);
CreateAssemblyInfo(BuildParameters.Paths.Files.SolutionInfoFilePath, assemblyInfoSettings);
});
Task("Strong-Name-Signer")
.IsDependentOn("Create-Solution-Info-File")
.IsDependeeOf("Build")
.Does(() => {
var settings = new StrongNameSignerSettings();
settings.KeyFile = STRONG_KEY_PATH;
var inputDirectoryString = string.Format("{0}{1}", BuildParameters.SourceDirectoryPath.FullPath, "\\packages\\Splat*");
Information("InputDirectoryString: {0}", inputDirectoryString);
settings.InputDirectory = inputDirectoryString;
settings.LogLevel = StrongNameSignerVerbosity.Summary;
StrongNameSigner(settings);
});
BuildParameters.Tasks.CreateChocolateyPackagesTask
.IsDependentOn("SignMSI");
BuildParameters.Tasks.CreateNuGetPackagesTask
.IsDependentOn("SignExecutable");
Build.Run();