Add more progress to OSX commands

This commit is contained in:
caesay
2024-01-09 00:01:59 +00:00
committed by Caelan Sayler
parent 3ccde34083
commit 771cddec46
4 changed files with 18 additions and 7 deletions

View File

@@ -79,16 +79,20 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
var packTitle = Options.PackTitle ?? Options.PackId;
helper.CreateInstallerPkg(packDir, packTitle, pkgContent, pkgPath, Options.SigningInstallIdentity);
if (!string.IsNullOrEmpty(Options.SigningInstallIdentity) && !string.IsNullOrEmpty(Options.NotaryProfile)) {
helper.CreateInstallerPkg(packDir, packTitle, pkgContent, pkgPath, Options.SigningInstallIdentity, Utility.CreateProgressDelegate(progress, 0, 60));
helper.Notarize(pkgPath, Options.NotaryProfile);
progress(80);
helper.Staple(pkgPath);
progress(90);
helper.SpctlAssessInstaller(pkgPath);
} else {
Log.Warn("Package installer (.pkg) will not be Notarized. " +
"This is supported with the --signInstallIdentity and --notaryProfile arguments.");
helper.CreateInstallerPkg(packDir, packTitle, pkgContent, pkgPath, Options.SigningInstallIdentity, progress);
}
}
progress(100);
return Task.CompletedTask;
}
@@ -96,6 +100,7 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
{
var helper = new HelperExe(Log);
helper.CreateDittoZip(packDir, outputPath);
progress(100);
return Task.CompletedTask;
}
}

View File

@@ -75,7 +75,7 @@ public class HelperExe : HelperFile
[SupportedOSPlatform("osx")]
public void CreateInstallerPkg(string appBundlePath, string appTitle, IEnumerable<KeyValuePair<string, string>> extraContent,
string pkgOutputPath, string signIdentity)
string pkgOutputPath, string signIdentity, Action<int> progress)
{
// https://matthew-brett.github.io/docosx/flat_packages.html
@@ -93,17 +93,20 @@ public class HelperExe : HelperFile
var bundleName = Path.GetFileName(appBundlePath);
var tmpBundlePath = Path.Combine(tmpPayload1, bundleName);
Utility.CopyFiles(new DirectoryInfo(appBundlePath), new DirectoryInfo(tmpBundlePath));
progress(10);
// create postinstall scripts to open app after install
// https://stackoverflow.com/questions/35619036/open-app-after-installation-from-pkg-file-in-mac
var postinstall = Path.Combine(tmpScripts, "postinstall");
File.WriteAllText(postinstall, $"#!/bin/sh\nsudo -u \"$USER\" open \"$2/{bundleName}/\"\nexit 0");
Chmod.ChmodFileAsExecutable(postinstall);
progress(15);
// generate non-relocatable component pkg. this will be included into a product archive
var pkgPlistPath = Path.Combine(tmp, "tmp.plist");
InvokeAndThrowIfNonZero("pkgbuild", new[] { "--analyze", "--root", tmpPayload1, pkgPlistPath }, null);
InvokeAndThrowIfNonZero("plutil", new[] { "-replace", "BundleIsRelocatable", "-bool", "NO", pkgPlistPath }, null);
progress(50);
var pkg1Path = Path.Combine(tmpPayload2, "1.pkg");
string[] args1 = {
@@ -115,11 +118,13 @@ public class HelperExe : HelperFile
};
InvokeAndThrowIfNonZero("pkgbuild", args1, null);
progress(70);
// create final product package that contains app component
var distributionPath = Path.Combine(tmp, "distribution.xml");
InvokeAndThrowIfNonZero("productbuild", new[] { "--synthesize", "--package", pkg1Path, distributionPath }, null);
progress(80);
// https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html
var distXml = File.ReadAllLines(distributionPath).ToList();
@@ -154,6 +159,7 @@ public class HelperExe : HelperFile
}
InvokeAndThrowIfNonZero("productbuild", args2, null);
progress(100);
Log.Info("Installer created successfully");
}
@@ -161,7 +167,7 @@ public class HelperExe : HelperFile
[SupportedOSPlatform("osx")]
public void Notarize(string filePath, string keychainProfileName)
{
Log.Info($"Preparing to Notarize '{filePath}'. This will upload to Apple and usually takes minutes, but could take hours.");
Log.Info($"Preparing to Notarize '{filePath}'. This will upload to Apple and usually takes minutes, [underline]but could take hours.[/]");
var args = new List<string> {
"notarytool",
@@ -229,7 +235,7 @@ public class HelperExe : HelperFile
outputZip
};
Log.Info($"Creating ditto bundle '{outputZip}'");
Log.Debug($"Creating ditto bundle '{outputZip}'");
InvokeAndThrowIfNonZero("ditto", args, null);
}
}

View File

@@ -30,7 +30,7 @@ internal class PlistWriter
var path = Path.Combine(_outputDir, PlistFileName);
_logger.Info($"Writing property list file: {path}");
_logger.Debug($"Writing property list file: {path}");
using (var xmlWriter = XmlWriter.Create(path, settings)) {
xmlWriter.WriteStartDocument();

View File

@@ -16,7 +16,7 @@ namespace Velopack.Tests
var args = new List<string> { "get-version", "-v", "NuGetPackageVersion" };
var psi = new ProcessStartInfo("nbgv");
psi.AppendArgumentListSafe(args, out var _);
var current = psi.Output(3000);
var current = psi.Output(10_000);
Assert.Equal(current, VelopackRuntimeInfo.VelopackNugetVersion.ToString());
}