Add osx keychain argument

This commit is contained in:
Caelan Sayler
2024-03-26 19:29:22 +00:00
parent 4e32b08ee2
commit e746c9bd37
7 changed files with 42 additions and 15 deletions

View File

@@ -70,6 +70,8 @@ public class PackTask : MSBuildAsyncTask
public string? NotaryProfile { get; set; }
public string? Keychain { get; set; }
public string? BundleId { get; set; }
public string? InfoPlistPath { get; set; }
@@ -119,7 +121,7 @@ public class PackTask : MSBuildAsyncTask
var runner = new WindowsPackCommandRunner(Logger, Logger);
await runner.Run(options).ConfigureAwait(false);
} else if (VelopackRuntimeInfo.IsOSX) {
var options = this.ToOSXPackOptions();
var options = this.ToOsxPackOptions();
var runner = new OsxPackCommandRunner(Logger, Logger);
await runner.Run(options).ConfigureAwait(false);
} else if (VelopackRuntimeInfo.IsLinux) {

View File

@@ -14,7 +14,7 @@ public static partial class TaskOptionsMapper
{
public static partial WindowsPackOptions ToWinPackOptions(this PackTask cmd);
public static partial LinuxPackOptions ToLinuxPackOptions(this PackTask cmd);
public static partial OsxPackOptions ToOSXPackOptions(this PackTask cmd);
public static partial OsxPackOptions ToOsxPackOptions(this PackTask cmd);
private static DirectoryInfo StringToDirectoryInfo(string t)
{

View File

@@ -22,7 +22,7 @@
<VelopackPackTitle Condition="'$(VelopackPackTitle)' == ''">$(Product)</VelopackPackTitle>
<VelopackPackAuthors Condition="'$(VelopackPackAuthors)' == ''">$(Authors)</VelopackPackAuthors>
<VelopackTargetRuntime Condition="'$(VelopackTargetRuntime)' == ''">$(RuntimeIdentifier)</VelopackTargetRuntime>
<!-- Allows a cross platform app (eg. Avalonia) to specify all three via csproj and have them applied correctly -->
<!-- TODO: this should probably switch based on the target RID and not the current OS, but we currently don't
support packing for an OS != target RID so we're probably okay for now. -->
@@ -56,7 +56,7 @@
Text="Only SelfContained=true releases are supported on MacOS. Please dotnet publish with the --self-contained option." />
<Error Condition=" '$(SelfContained)' != 'true' and $([System.OperatingSystem]::IsLinux()) "
Text="Only SelfContained=true releases are supported on Linux. Please dotnet publish with the --self-contained option." />
<PackTask
SelfContained="$(SelfContained)"
TargetFramework="$(TargetFramework)"
@@ -85,6 +85,7 @@
SignInstallIdentity="$(VelopackSignInstallIdentity)"
SignEntitlements="$(VelopackSignEntitlements)"
NotaryProfile="$(VelopackNotaryProfile)"
Keychain="$(VelopackKeychain)"
BundleId="$(VelopackBundleId)"
InfoPlistPath="$(VelopackInfoPlistPath)"
SplashImage="$(VelopackSplashImage)"

View File

@@ -58,13 +58,14 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
protected override Task CodeSign(Action<int> progress, string packDir)
{
var helper = new OsxBuildTools(Log);
var keychainPath = Options.Keychain;
// code signing all mach-o binaries
if (!string.IsNullOrEmpty(Options.SignAppIdentity) && !string.IsNullOrEmpty(Options.NotaryProfile)) {
progress(-1); // indeterminate
var zipPath = Path.Combine(TempDir.FullName, "notarize.zip");
helper.CodeSign(Options.SignAppIdentity, Options.SignEntitlements, packDir);
helper.CodeSign(Options.SignAppIdentity, Options.SignEntitlements, packDir, keychainPath);
helper.CreateDittoZip(packDir, zipPath);
helper.Notarize(zipPath, Options.NotaryProfile);
helper.Notarize(zipPath, Options.NotaryProfile, keychainPath);
helper.Staple(packDir);
helper.SpctlAssessCode(packDir);
File.Delete(zipPath);
@@ -72,7 +73,7 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
} else if (!string.IsNullOrEmpty(Options.SignAppIdentity)) {
progress(-1); // indeterminate
Log.Warn("Package will be signed, but [underline]not notarized[/]. Missing the --notaryProfile option.");
helper.CodeSign(Options.SignAppIdentity, Options.SignEntitlements, packDir);
helper.CodeSign(Options.SignAppIdentity, Options.SignEntitlements, packDir, keychainPath);
progress(100);
} else {
Log.Warn("Package will not be signed or notarized. Missing the --signAppIdentity and --notaryProfile options.");
@@ -98,7 +99,7 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
if (!string.IsNullOrEmpty(Options.SignInstallIdentity) && !string.IsNullOrEmpty(Options.NotaryProfile)) {
helper.CreateInstallerPkg(packDir, packTitle, packId, pkgContent, pkgPath, Options.SignInstallIdentity, Utility.CreateProgressDelegate(progress, 0, 60));
progress(-1); // indeterminate
helper.Notarize(pkgPath, Options.NotaryProfile);
helper.Notarize(pkgPath, Options.NotaryProfile, Options.Keychain);
progress(80);
helper.Staple(pkgPath);
progress(90);

View File

@@ -30,6 +30,9 @@ public class OsxPackOptions : OsxBundleOptions, IPackOptions
public string NotaryProfile { get; set; }
public string Keychain { get; set; }
public string Channel { get; set; }
public string Exclude { get; set; }
}

View File

@@ -15,7 +15,7 @@ public class OsxBuildTools
Log = logger;
}
public void CodeSign(string identity, string entitlements, string filePath)
public void CodeSign(string identity, string entitlements, string filePath, string keychainPath)
{
if (String.IsNullOrEmpty(entitlements)) {
Log.Info("No entitlements specified, using default: " +
@@ -35,13 +35,18 @@ public class OsxBuildTools
"--timestamp",
"--options", "runtime",
"--entitlements", entitlements,
filePath
};
if (!String.IsNullOrEmpty(keychainPath)) {
Log.Info($"Using non-default keychain at '{keychainPath}'");
args.Add("--keychain");
args.Add(keychainPath);
}
args.Add(filePath);
Log.Info($"Beginning codesign for package...");
Log.Info(Exe.InvokeAndThrowIfNonZero("codesign", args, null));
Log.Info("codesign completed successfully");
}
@@ -179,7 +184,7 @@ exit 0
Log.Info("Installer created successfully");
}
public void Notarize(string filePath, string keychainProfileName)
public void Notarize(string filePath, string keychainProfileName, string keychainPath)
{
Log.Info($"Preparing to Notarize. This will upload to Apple and usually takes minutes, [underline]but could take hours.[/]");
@@ -187,11 +192,18 @@ exit 0
"notarytool",
"submit",
"-f", "json",
"--keychain-profile", keychainProfileName,
"--wait",
filePath
"--keychain-profile", keychainProfileName,
};
if (!String.IsNullOrEmpty(keychainPath)) {
Log.Info($"Using non-default keychain at '{keychainPath}'");
args.Add("--keychain");
args.Add(keychainPath);
}
args.Add(filePath);
var ntresultjson = Exe.InvokeProcess("xcrun", args, null);
Log.Info(ntresultjson.StdOutput);

View File

@@ -18,6 +18,8 @@ public class OsxPackCommand : OsxBundleCommand
public string NotaryProfile { get; private set; }
public string Keychain { get; private set; }
public OsxPackCommand()
: base("pack", "Converts application files into a release and installer.")
{
@@ -58,5 +60,11 @@ public class OsxPackCommand : OsxBundleCommand
AddOption<string>((v) => NotaryProfile = v, "--notaryProfile")
.SetDescription("Name of profile containing Apple credentials stored with notarytool.")
.SetArgumentHelpName("NAME");
AddOption<FileInfo>((v) => Keychain = v.ToFullNameOrNull(), "--keychain")
.SetDescription("Path to keychain file to use for codesign and notarytool.")
.SetArgumentHelpName("PATH")
.MustExist()
.SetHidden(true);
}
}