Skip to content

Commit

Permalink
feat: Skip execution of the "ValidateCodeFormatting" task when build …
Browse files Browse the repository at this point in the history
…is running on Azure Pipelines

Running dotnet format on Azure Pipelines when using the .NET 9 SDK and Nerdbank.GitVersioning is installed causes the build to hang (see dotnet/sdk#44951).
To work around this, skip the task when running on Azure Pipelines and emit a warning about the task being skipped
  • Loading branch information
ap0llo committed Dec 19, 2024
1 parent 060d30b commit 55d9696
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/SharedBuild/Tasks/ValidateCodeFormattingCodeTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Format;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;

namespace Grynwald.SharedBuild.Tasks
Expand All @@ -10,7 +11,25 @@ namespace Grynwald.SharedBuild.Tasks
[IsDependeeOf(typeof(ValidateTask))]
public class ValidateCodeFormattingTask : FrostingTask<IBuildContext>
{
public override bool ShouldRun(IBuildContext context) => context.CodeFormattingSettings.EnableAutomaticFormatting;
public override bool ShouldRun(IBuildContext context)
{
if (!context.CodeFormattingSettings.EnableAutomaticFormatting)
{
return false;
}


// Running dotnet format on Azure Pipelines when using the .NET 9 SDK and Nerdbank.GitVersioning causes the build to hang
// See: https://github.com/dotnet/sdk/issues/44951
// To work around this, skip the task when running on Azure Pipelines
if (context.AzurePipelines.IsRunningOnAzurePipelines)
{
context.Log.Warning($"Skipping task {TaskNames.ValidateCodeFormatting} since the build is running on Azure Pipelines. This is a workaround for https://github.com/dotnet/sdk/issues/44951");
return false;
}

return true;
}

public override void Run(IBuildContext context)
{
Expand Down

0 comments on commit 55d9696

Please sign in to comment.