Files
sbox-public/engine/Tools/SboxBuild/Steps/SignBinaries.cs
Lorenz Junglas 8bb48bac56 Move Pipelines out of SboxBuild into GitHub yml
Allows us to get rid of a ton of abstraction in SboxBuild, and gets rid of a lot of GitHub API plumbing.
I feel like now that our workflows are more complex it's nicer to just use GitHub directly rather than having our own pipeline abstraction in SboxBuild.
This way we get nicer logging and error reporting, which we can\t achieve through GitHub API.
2026-06-19 13:49:41 +01:00

65 lines
2.1 KiB
C#

using static Facepunch.Constants;
namespace Facepunch.Steps;
/// <summary>
/// Signs all eligible binaries in the build output using the <c>sign</c> dotnet tool
/// with Azure Trusted Signing (artifact-signing). Auth is handled via DefaultAzureCredential
/// (expects AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET in the environment).
/// </summary>
internal class SignBinaries
{
internal ExitCode Run()
{
string rootDir = Directory.GetCurrentDirectory();
var endpointUrl = Environment.GetEnvironmentVariable( "CODESIGN_ENDPOINT_URL" );
var accountName = Environment.GetEnvironmentVariable( "CODESIGN_ACCOUNT_NAME" );
var certificateProfile = Environment.GetEnvironmentVariable( "CODESIGN_CERTIFICATE_PROFILE" );
if ( string.IsNullOrEmpty( endpointUrl ) || string.IsNullOrEmpty( accountName ) || string.IsNullOrEmpty( certificateProfile ) )
{
Log.Error( "Missing signing env vars — need CODESIGN_ENDPOINT_URL, CODESIGN_ACCOUNT_NAME, CODESIGN_CERTIFICATE_PROFILE" );
return ExitCode.Failure;
}
var filesToSign = CollectFilesToSign( rootDir );
if ( filesToSign.Count == 0 )
{
Log.Warning( "No files found to sign." );
return ExitCode.Success;
}
Log.Info( $"Signing {filesToSign.Count} files..." );
var fileArgs = string.Join( " ", filesToSign.Select( f => $"\"{f}\"" ) );
bool success = Utility.RunProcess(
"sign",
$"code artifact-signing -ase \"{endpointUrl}\" -asa \"{accountName}\" -ascp \"{certificateProfile}\" -v warning -m 16 {fileArgs}",
rootDir,
timeoutMs: 600000
);
if ( !success )
{
Log.Error( "Failed to sign files." );
return ExitCode.Failure;
}
Log.Info( $"Successfully signed {filesToSign.Count} files." );
return ExitCode.Success;
}
private static List<string> CollectFilesToSign( string rootDir )
{
var gamePath = Path.Combine( rootDir, "game" );
var files = new List<string>();
files.AddRange( Directory.EnumerateFiles( gamePath, "*.exe", SearchOption.AllDirectories ) );
files.AddRange( Directory.EnumerateFiles( gamePath, "*.dll", SearchOption.AllDirectories ) );
return files;
}
}