Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logging to Releasify #1432

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
73 changes: 63 additions & 10 deletions src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,27 @@ public async Task Uninstall(string appName = null)

public void Releasify(string package, string targetDir = null, string packagesDir = null, string bootstrapperExe = null, string backgroundGif = null, string signingOpts = null, string baseUrl = null, string setupIcon = null, bool generateMsi = true, string frameworkVersion = null, bool generateDeltas = true)
{
ensureConsole();
try {
this.Log().Debug("Begin Releasify");
ensureConsole();
ReleasifyValidateBaseUrl(ref baseUrl);
Horb marked this conversation as resolved.
Show resolved Hide resolved
ReleasifyValidatePaths(ref targetDir, ref packagesDir, ref bootstrapperExe);
ReleasifyPrepareFiles(package, targetDir, out var di, out var toProcess, out var processed, out var releaseFilePath, out var previousReleases);
Horb marked this conversation as resolved.
Show resolved Hide resolved
ReleasifyProcessFiles(targetDir, packagesDir, signingOpts, generateDeltas, toProcess, di, processed, previousReleases);
ReleasifyCleanupFiles(toProcess);
ReleasifyWriteReleaseFile(baseUrl, processed, previousReleases, releaseFilePath, out var releaseEntries);
ReleasifyCreateSetupExe(package, bootstrapperExe, backgroundGif, signingOpts, setupIcon, frameworkVersion, di, releaseEntries, out var targetSetupExe);
ReleasifyGenerateMsi(package, signingOpts, generateMsi, targetSetupExe);
this.Log().Debug("Completed Releasify");
} catch (Exception ex) {
this.Log().Error(ex);
throw;
}
}

private void ReleasifyValidateBaseUrl(ref string baseUrl)
Horb marked this conversation as resolved.
Show resolved Hide resolved
{
this.Log().Debug("Validating BaseUrl");
if (baseUrl != null) {
if (!Utility.IsHttpUrl(baseUrl)) {
throw new Exception(string.Format("Invalid --baseUrl '{0}'. A base URL must start with http or https and be a valid URI.", baseUrl));
Expand All @@ -356,7 +375,11 @@ public void Releasify(string package, string targetDir = null, string packagesDi
baseUrl += "/";
}
}
}

private void ReleasifyValidatePaths(ref string targetDir, ref string packagesDir, ref string bootstrapperExe)
{
this.Log().Debug("Validating Paths");
targetDir = targetDir ?? Path.Combine(".", "Releases");
packagesDir = packagesDir ?? ".";
bootstrapperExe = bootstrapperExe ?? Path.Combine(".", "Setup.exe");
Expand All @@ -370,24 +393,33 @@ public void Releasify(string package, string targetDir = null, string packagesDi
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
"Setup.exe");
}

this.Log().Info("Bootstrapper EXE found at:" + bootstrapperExe);
}

var di = new DirectoryInfo(targetDir);
private void ReleasifyPrepareFiles(string package, string targetDir, out DirectoryInfo di,
out IEnumerable<FileInfo> toProcess, out List<string> processed, out string releaseFilePath, out List<ReleaseEntry> previousReleases)
{
this.Log().Debug("Preparing Files");
di = new DirectoryInfo(targetDir);
File.Copy(package, Path.Combine(di.FullName, Path.GetFileName(package)), true);

var allNuGetFiles = di.EnumerateFiles()
.Where(x => x.Name.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase));

var toProcess = allNuGetFiles.Where(x => !x.Name.Contains("-delta") && !x.Name.Contains("-full"));
var processed = new List<string>();
toProcess = allNuGetFiles.Where(x => !x.Name.Contains("-delta") && !x.Name.Contains("-full"));
processed = new List<string>();

var releaseFilePath = Path.Combine(di.FullName, "RELEASES");
var previousReleases = new List<ReleaseEntry>();
releaseFilePath = Path.Combine(di.FullName, "RELEASES");
previousReleases = new List<ReleaseEntry>();
if (File.Exists(releaseFilePath)) {
previousReleases.AddRange(ReleaseEntry.ParseReleaseFile(File.ReadAllText(releaseFilePath, Encoding.UTF8)));
}
}

private void ReleasifyProcessFiles(string targetDir, string packagesDir, string signingOpts, bool generateDeltas,
IEnumerable<FileInfo> toProcess, DirectoryInfo di, List<string> processed, List<ReleaseEntry> previousReleases)
{
this.Log().Debug("Processing Files");
foreach (var file in toProcess) {
this.Log().Info("Creating release package: " + file.FullName);

Expand Down Expand Up @@ -428,19 +460,33 @@ public void Releasify(string package, string targetDir = null, string packagesDi
processed.Insert(0, dp.InputPackageFile);
}
}
}

private void ReleasifyCleanupFiles(IEnumerable<FileInfo> toProcess)
{
this.Log().Debug("Cleaning Up Files");
foreach (var file in toProcess) { File.Delete(file.FullName); }
}

private void ReleasifyWriteReleaseFile(string baseUrl, List<string> processed, List<ReleaseEntry> previousReleases, string releaseFilePath,
out List<ReleaseEntry> releaseEntries)
{
this.Log().Debug("Writing RELEASES file");
var newReleaseEntries = processed
.Select(packageFilename => ReleaseEntry.GenerateFromFile(packageFilename, baseUrl))
.ToList();
var distinctPreviousReleases = previousReleases
.Where(x => !newReleaseEntries.Select(e => e.Version).Contains(x.Version));
var releaseEntries = distinctPreviousReleases.Concat(newReleaseEntries).ToList();
releaseEntries = distinctPreviousReleases.Concat(newReleaseEntries).ToList();

ReleaseEntry.WriteReleaseFile(releaseEntries, releaseFilePath);
}

var targetSetupExe = Path.Combine(di.FullName, "Setup.exe");
private void ReleasifyCreateSetupExe(string package, string bootstrapperExe, string backgroundGif, string signingOpts,
string setupIcon, string frameworkVersion, DirectoryInfo di, List<ReleaseEntry> releaseEntries, out string targetSetupExe)
{
this.Log().Debug("Creating Setup.exe");
targetSetupExe = Path.Combine(di.FullName, "Setup.exe");
var newestFullRelease = releaseEntries.MaxBy(x => x.Version).Where(x => !x.IsDelta).First();

File.Copy(bootstrapperExe, targetSetupExe, true);
Expand All @@ -458,14 +504,20 @@ public void Releasify(string package, string targetDir = null, string packagesDi
File.Delete(zipPath);
}

// Alias parameter because cannot pass to anonymous lambda otherwise
var targetSetupExeAlias = targetSetupExe;
Utility.Retry(() =>
setPEVersionInfoAndIcon(targetSetupExe, new ZipPackage(package), setupIcon).Wait());
setPEVersionInfoAndIcon(targetSetupExeAlias, new ZipPackage(package), setupIcon).Wait());

if (signingOpts != null) {
signPEFile(targetSetupExe, signingOpts).Wait();
}
}

private void ReleasifyGenerateMsi(string package, string signingOpts, bool generateMsi, string targetSetupExe)
{
if (generateMsi) {
this.Log().Debug("Generating .msi");
createMsiPackage(targetSetupExe, new ZipPackage(package)).Wait();

if (signingOpts != null) {
Expand All @@ -474,6 +526,7 @@ public void Releasify(string package, string targetDir = null, string packagesDi
}
}


public void Shortcut(string exeName, string shortcutArgs, string processStartArgs, string icon)
{
if (String.IsNullOrWhiteSpace(exeName)) {
Expand Down