From 0bab09c6e4da444ae46799de2661c28478c3abc7 Mon Sep 17 00:00:00 2001 From: Flepp Jann Date: Wed, 31 May 2023 10:02:14 +0200 Subject: [PATCH] Add Azure Pipelines group logging commands --- .../AzurePipelinesCommandTests.cs | 28 +++++++++++++++++++ .../AzurePipelines/AzurePipelinesCommands.cs | 12 ++++++++ .../AzurePipelines/IAzurePipelinesCommands.cs | 11 ++++++++ 3 files changed, 51 insertions(+) diff --git a/src/Cake.Common.Tests/Unit/Build/AzurePipelines/AzurePipelinesCommandTests.cs b/src/Cake.Common.Tests/Unit/Build/AzurePipelines/AzurePipelinesCommandTests.cs index c57c4ba62a..d13e6905af 100644 --- a/src/Cake.Common.Tests/Unit/Build/AzurePipelines/AzurePipelinesCommandTests.cs +++ b/src/Cake.Common.Tests/Unit/Build/AzurePipelines/AzurePipelinesCommandTests.cs @@ -127,6 +127,34 @@ public void Should_Log_Error_Message_With_Data() Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[task.logissue sourcepath=./code.cs;linenumber=1;columnnumber=2;code=3;type=error;]build error"); } + [Fact] + public void Should_Begin_Group_With_Name() + { + // Given + var fixture = new AzurePipelinesFixture(); + var service = fixture.CreateAzurePipelinesService(); + + // When + service.Commands.BeginGroup("Example Group"); + + // Then + Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[group ]Example Group"); + } + + [Fact] + public void Should_End_Group() + { + // Given + var fixture = new AzurePipelinesFixture(); + var service = fixture.CreateAzurePipelinesService(); + + // When + service.Commands.EndGroup(); + + // Then + Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[endgroup ]"); + } + [Fact] public void Should_Set_Current_Progress() { diff --git a/src/Cake.Common/Build/AzurePipelines/AzurePipelinesCommands.cs b/src/Cake.Common/Build/AzurePipelines/AzurePipelinesCommands.cs index ecef614c78..fd31cdf76b 100644 --- a/src/Cake.Common/Build/AzurePipelines/AzurePipelinesCommands.cs +++ b/src/Cake.Common/Build/AzurePipelines/AzurePipelinesCommands.cs @@ -69,6 +69,18 @@ public void WriteError(string message, AzurePipelinesMessageData data) WriteLoggingCommand("task.logissue", properties, message); } + /// + public void BeginGroup(string name) + { + WriteLoggingCommand("group", name); + } + + /// + public void EndGroup() + { + WriteLoggingCommand("endgroup", string.Empty); + } + /// public void SetProgress(int progress, string currentOperation) { diff --git a/src/Cake.Common/Build/AzurePipelines/IAzurePipelinesCommands.cs b/src/Cake.Common/Build/AzurePipelines/IAzurePipelinesCommands.cs index 9adf93515b..a75c8cb9fa 100644 --- a/src/Cake.Common/Build/AzurePipelines/IAzurePipelinesCommands.cs +++ b/src/Cake.Common/Build/AzurePipelines/IAzurePipelinesCommands.cs @@ -39,6 +39,17 @@ public interface IAzurePipelinesCommands /// The message data. void WriteError(string message, AzurePipelinesMessageData data); + /// + /// Begin a collapsible group. + /// + /// The name of the group. + public void BeginGroup(string name); + + /// + /// End a collapsible group. + /// + public void EndGroup(); + /// /// Set progress and current operation for current task. ///