Skip to content

Commit

Permalink
Merge pull request #113 from nils-a/release/4.1.0
Browse files Browse the repository at this point in the history
Release/4.1.0
  • Loading branch information
nils-a authored Jan 4, 2022
2 parents 6eac904 + 9f83f03 commit 09c7ce5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 33 deletions.
71 changes: 62 additions & 9 deletions src/Cake.AzurePipelines.Module/AzurePipelinesEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Cake.Common.Build;
Expand All @@ -24,17 +24,54 @@ public sealed class AzurePipelinesEngine : CakeEngineBase
public AzurePipelinesEngine(ICakeDataService dataService, ICakeLog log)
: base(new CakeEngine(dataService, log))
{
_engine.BeforeSetup += BuildSetup;
_engine.BeforeTaskSetup += OnTaskSetup;
_engine.BeforeTaskTeardown += OnTaskTeardown;
_engine.BeforeTeardown += OnBuildTeardown;
_log = log;
_engine.BeforeSetup += OnBeforeSetup;
_engine.AfterSetup += OnAfterSetup;

_engine.BeforeTaskSetup += OnBeforeTaskSetup;

_engine.BeforeTaskTeardown += OnBeforeTaskTeardown;

_engine.AfterTaskTeardown += OnAfterTaskTeardown;

_engine.BeforeTeardown += OnBeforeTeardown;
_engine.AfterTeardown += OnAfterTeardown;
}

private void OnAfterTaskTeardown(object sender, AfterTaskTeardownEventArgs e)
{
var b = e.TaskTeardownContext.BuildSystem();
if (b.IsRunningOnPipelines())
{
WriteGroupEndCommand();
}
}

private void OnAfterTeardown(object sender, AfterTeardownEventArgs e)
{
var b = e.TeardownContext.BuildSystem();
if (b.IsRunningOnPipelines())
{
WriteGroupEndCommand();
}
}

private void OnBuildTeardown(object sender, BeforeTeardownEventArgs e)
private void OnAfterSetup(object sender, AfterSetupEventArgs e)
{
var b = e.Context.BuildSystem();
if (b.IsRunningOnPipelines())
{
WriteGroupEndCommand();
}
}

private void OnBeforeTeardown(object sender, BeforeTeardownEventArgs e)
{
var b = e.TeardownContext.BuildSystem();
if (b.IsRunningOnPipelines())
{
WriteGroupCommand("Teardown");

b.AzurePipelines.Commands.UpdateRecord(_parentRecord, new AzurePipelinesRecordData
{
FinishTime = DateTime.Now,
Expand All @@ -45,7 +82,7 @@ private void OnBuildTeardown(object sender, BeforeTeardownEventArgs e)
}
}

private void OnTaskTeardown(object sender, BeforeTaskTeardownEventArgs e)
private void OnBeforeTaskTeardown(object sender, BeforeTaskTeardownEventArgs e)
{
var b = e.TaskTeardownContext.BuildSystem();
if (b.IsRunningOnPipelines())
Expand Down Expand Up @@ -74,11 +111,13 @@ private void OnTaskTeardown(object sender, BeforeTaskTeardownEventArgs e)
return AzurePipelinesTaskResult.Succeeded;
}

private void OnTaskSetup(object sender, BeforeTaskSetupEventArgs e)
private void OnBeforeTaskSetup(object sender, BeforeTaskSetupEventArgs e)
{
var b = e.TaskSetupContext.BuildSystem();
if (b.IsRunningOnPipelines())
{
WriteGroupCommand(e.TaskSetupContext.Task.Name);

var currentTask =
_engine.Tasks.First(t => t.Name == e.TaskSetupContext.Task.Name);
var currentIndex = _engine.Tasks.ToList().IndexOf(currentTask);
Expand All @@ -97,19 +136,33 @@ private int GetProgress(int currentTask, int count)
return Convert.ToInt32(Math.Truncate(f));
}

private void BuildSetup(object sender, BeforeSetupEventArgs e)
private void OnBeforeSetup(object sender, BeforeSetupEventArgs e)
{
var b = e.Context.BuildSystem();
if (b.IsRunningOnPipelines())
{
WriteGroupCommand("Setup");

e.Context.AzurePipelines().Commands.SetProgress(0, string.Empty);
var g = e.Context.AzurePipelines()
.Commands.CreateNewRecord("Cake Build", "build", 0, new AzurePipelinesRecordData { StartTime = DateTime.Now });
_parentRecord = g;
}
}

private void WriteGroupCommand(string groupName)
{
_log.Verbose(string.Empty);
_log.Information("##[group]{0}", groupName);
}

private void WriteGroupEndCommand()
{
_log.Information("##[endgroup]");
}

private Guid _parentRecord;
private ICakeLog _log;

private Dictionary<string, Guid> TaskRecords { get; } = new Dictionary<string, Guid>();
}
Expand Down
54 changes: 31 additions & 23 deletions src/Cake.AzurePipelines.Module/AzurePipelinesLog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Cake.Core;
using Cake.Core.Diagnostics;
using JetBrains.Annotations;
Expand All @@ -11,6 +11,9 @@ namespace Cake.AzurePipelines.Module
[UsedImplicitly]
public class AzurePipelinesLog : ICakeLog
{
private readonly ICakeLog _cakeLogImplementation;
private readonly IConsole _console;

/// <summary>
/// Initializes a new instance of the <see cref="AzurePipelinesLog"/> class.
/// </summary>
Expand All @@ -19,36 +22,41 @@ public class AzurePipelinesLog : ICakeLog
public AzurePipelinesLog(IConsole console, Verbosity verbosity = Verbosity.Normal)
{
_cakeLogImplementation = new CakeBuildLog(console, verbosity);
_console = console;
}

private readonly ICakeLog _cakeLogImplementation;

/// <inheritdoc />
public void Write(Verbosity verbosity, LogLevel level, string format, params object[] args)
{
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TF_BUILD")))
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TF_BUILD")))
{
switch (level)
{
case LogLevel.Fatal:
case LogLevel.Error:
_cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
"##vso[task.logissue type=error;]{0}", string.Format(format, args));
break;
case LogLevel.Warning:
_cakeLogImplementation.Write(Verbosity.Quiet, LogLevel.Information,
"##vso[task.logissue type=warning;]{0}", string.Format(format, args));
break;
case LogLevel.Information:
case LogLevel.Verbose:
case LogLevel.Debug:
break;
default:
throw new ArgumentOutOfRangeException(nameof(level), level, null);
}
_cakeLogImplementation.Write(verbosity, level, format, args);
}

_cakeLogImplementation.Write(verbosity, level, format, args);
if (verbosity > Verbosity)
{
return;
}

switch (level)
{
case LogLevel.Fatal:
case LogLevel.Error:
_console.WriteLine("##vso[task.logissue type=error;]{0}", string.Format(format, args));
break;
case LogLevel.Warning:
_console.WriteLine("##vso[task.logissue type=warning;]{0}", string.Format(format, args));
break;
case LogLevel.Information:
case LogLevel.Verbose:
_console.WriteLine(format, args);
break;
case LogLevel.Debug:
_console.WriteLine("##[debug]{0}", string.Format(format, args));
break;
default:
throw new ArgumentOutOfRangeException(nameof(level), level, null);
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand Down

0 comments on commit 09c7ce5

Please sign in to comment.