Files
sbox-public/engine/Tools/SboxBuild/Steps/BuildShaders.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

77 lines
1.7 KiB
C#

using System.Diagnostics;
using static Facepunch.Constants;
namespace Facepunch.Steps;
internal class BuildShaders( bool forced = false )
{
internal ExitCode Run()
{
try
{
string rootDir = Directory.GetCurrentDirectory();
string gameDir = Path.Combine( rootDir, "game" );
string shaderCompilerPath = Path.Combine( gameDir, "bin", "managed", "shadercompiler.exe" );
// Verify shader compiler exists
if ( !File.Exists( shaderCompilerPath ) )
{
Log.Error( $"Error: Shader compiler executable not found at {shaderCompilerPath}" );
return ExitCode.Failure;
}
return RunShaderCompiler( shaderCompilerPath, gameDir );
}
catch ( Exception ex )
{
Log.Error( $"Shader compilation failed with error: {ex}" );
return ExitCode.Failure;
}
}
private ExitCode RunShaderCompiler( string shaderCompilerPath, string workingDirectory )
{
// Build arguments - only include -f if forced is true
string arguments = "*";
if ( forced )
{
arguments += " -f";
}
// Track if any shaders were compiled
var shaderCompiled = false;
bool success = Utility.RunProcess(
shaderCompilerPath,
arguments,
workingDirectory,
onDataReceived: ( sender, e ) =>
{
if ( e.Data != null )
{
Log.Info( e.Data );
if ( e.Data.Contains( "Compiled successfully in" ) )
{
shaderCompiled = true;
}
}
}
);
if ( !success )
{
Log.Error( $"Shader compiler failed" );
return ExitCode.Failure;
}
if ( shaderCompiled && Utility.IsCi() )
{
Log.Error( $"Step Failed because at least one shader had to be recompiled, please compile shaders locally before committing." );
return ExitCode.Failure;
}
return ExitCode.Success;
}
}