Skip to content

Commit

Permalink
Support Cake 0.38.0
Browse files Browse the repository at this point in the history
TFBuild was renamed to AzurePipelines
  • Loading branch information
bdukes committed Feb 4, 2021
1 parent e876ce2 commit 01d3931
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 95 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This module will introduce a number of features for running in hosted CI build e

Currently this module supports:

### TF Build
### Azure Pipelines

> This applies to TFS and VSTS
> This applies to TFS, Azure Pipelines, and Azure DevOps Server
- Individual timeline records for each task
- Percentage reporting on build progress
Expand Down
7 changes: 6 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@

- Supports Cake 0.34.1
- Fixes errors writing summary report when run in Azure Pipelines container (#21)
- Thanks again to @flcdrg for contributions!
- Thanks again to @flcdrg for contributions!

# 0.4.0

- Supports Cake 0.38.0
- Rename TF Build to Azure Pipelines
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ trigger:

variables:
buildConfiguration: 'Release'
cakeVersion: 0.34.1
cakeVersion: 0.38.5
sdkVersion: '2.2.300'
target: NuGet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
using System.Collections.Generic;
using System.Linq;
using Cake.Common.Build;
using Cake.Common.Build.TFBuild.Data;
using Cake.Common.Build.AzurePipelines.Data;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Module.Shared;

namespace Cake.TFBuild.Module
namespace Cake.AzurePipelines.Module
{
using Cake.Common.Build.AzurePipelines.Data;

/// <summary>
/// Represents a Cake engine for use with the TF Build engine.
/// Represents a Cake engine for use with the Azure Pipelines engine.
/// </summary>
public sealed class TFBuildEngine : CakeEngineBase
public sealed class AzurePipelinesEngine : CakeEngineBase
{
/// <summary>
/// Initializes a new instance of the <see cref="TFBuildEngine"/> type.
/// Initializes a new instance of the <see cref="AzurePipelinesEngine"/> type.
/// </summary>
/// <param name="dataService"></param>
/// <param name="log">The log.</param>
public TFBuildEngine(ICakeDataService dataService, ICakeLog log) : base(new CakeEngine(dataService, log))
public AzurePipelinesEngine(ICakeDataService dataService, ICakeLog log) : base(new CakeEngine(dataService, log))
{
_engine.Setup += BuildSetup;
_engine.TaskSetup += OnTaskSetup;
Expand All @@ -32,11 +34,11 @@ private void OnBuildTeardown(object sender, TeardownEventArgs e)
var b = e.TeardownContext.BuildSystem();
if (b.IsRunningOnPipelines())
{
b.TFBuild.Commands.UpdateRecord(_parentRecord, new TFBuildRecordData
b.AzurePipelines.Commands.UpdateRecord(_parentRecord, new AzurePipelinesRecordData
{
FinishTime = DateTime.Now,
Status = TFBuildTaskStatus.Completed,
Result = e.TeardownContext.Successful ? TFBuildTaskResult.Succeeded : TFBuildTaskResult.Failed,
Status = AzurePipelinesTaskStatus.Completed,
Result = e.TeardownContext.Successful ? AzurePipelinesTaskResult.Succeeded : AzurePipelinesTaskResult.Failed,
Progress = GetProgress(TaskRecords.Count, _engine.Tasks.Count),
});
}
Expand All @@ -49,10 +51,10 @@ private void OnTaskTeardown(object sender, TaskTeardownEventArgs e)
{
var currentTask = _engine.Tasks.First(t => t.Name == e.TaskTeardownContext.Task.Name);
var currentIndex = _engine.Tasks.ToList().IndexOf(currentTask);
//b.TFBuild.UpdateProgress(_parentRecord, GetProgress(currentIndex, _engine.Tasks.Count));
//b.AzurePipelines.UpdateProgress(_parentRecord, GetProgress(currentIndex, _engine.Tasks.Count));
var g = TaskRecords[currentTask.Name];
b.TFBuild.Commands.UpdateRecord(g,
new TFBuildRecordData
b.AzurePipelines.Commands.UpdateRecord(g,
new AzurePipelinesRecordData
{
FinishTime = DateTime.Now,
Progress = 100,
Expand All @@ -61,12 +63,12 @@ private void OnTaskTeardown(object sender, TaskTeardownEventArgs e)
}
}

private TFBuildTaskResult? GetTaskResult(ITaskTeardownContext taskTeardownContext)
private AzurePipelinesTaskResult? GetTaskResult(ITaskTeardownContext taskTeardownContext)
{
if (taskTeardownContext.Skipped) return TFBuildTaskResult.Skipped;
if (taskTeardownContext.Skipped) return AzurePipelinesTaskResult.Skipped;

// TODO: this logic should be improved but is difficult without task status in the context
return TFBuildTaskResult.Succeeded;
return AzurePipelinesTaskResult.Succeeded;
}

private void OnTaskSetup(object sender, TaskSetupEventArgs e)
Expand All @@ -77,12 +79,12 @@ private void OnTaskSetup(object sender, TaskSetupEventArgs e)
var currentTask =
_engine.Tasks.First(t => t.Name == e.TaskSetupContext.Task.Name);
var currentIndex = _engine.Tasks.ToList().IndexOf(currentTask);
b.TFBuild.UpdateProgress(_parentRecord, GetProgress(currentIndex, _engine.Tasks.Count));
//b.TFBuild.Commands.SetProgress(GetProgress(currentIndex, _engine.Tasks.Count), e.TaskSetupContext.Task.Name);
b.TFBuild.Commands.SetProgress(GetProgress(currentIndex, _engine.Tasks.Count), string.Empty);
var g = e.TaskSetupContext.TFBuild()
b.AzurePipelines.UpdateProgress(_parentRecord, GetProgress(currentIndex, _engine.Tasks.Count));
//b.AzurePipelines.Commands.SetProgress(GetProgress(currentIndex, _engine.Tasks.Count), e.TaskSetupContext.Task.Name);
b.AzurePipelines.Commands.SetProgress(GetProgress(currentIndex, _engine.Tasks.Count), string.Empty);
var g = e.TaskSetupContext.AzurePipelines()
.Commands.CreateNewRecord(currentTask.Name, "build", TaskRecords.Count + 1,
new TFBuildRecordData() {StartTime = DateTime.Now, ParentRecord = _parentRecord, Progress = 0});
new AzurePipelinesRecordData() {StartTime = DateTime.Now, ParentRecord = _parentRecord, Progress = 0});
TaskRecords.Add(currentTask.Name, g);
}
}
Expand All @@ -98,10 +100,10 @@ private void BuildSetup(object sender, SetupEventArgs e)
var b = e.Context.BuildSystem();
if (b.IsRunningOnPipelines())
{
//e.Context.TFBuild().Commands.SetProgress(0, "Build Setup");
e.Context.TFBuild().Commands.SetProgress(0, string.Empty);
var g = e.Context.TFBuild()
.Commands.CreateNewRecord("Cake Build", "build", 0, new TFBuildRecordData {StartTime = DateTime.Now});
//e.Context.AzurePipelines().Commands.SetProgress(0, "Build 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using Cake.Core.Diagnostics;
using Cake.Module.Shared;

namespace Cake.TFBuild.Module
namespace Cake.AzurePipelines.Module
{
public class TFBuildLog : ICakeLog
public class AzurePipelinesLog : ICakeLog
{
public TFBuildLog(IConsole console, Verbosity verbosity = Verbosity.Normal)
public AzurePipelinesLog(IConsole console, Verbosity verbosity = Verbosity.Normal)
{
_cakeLogImplementation = new Core.Diagnostics.CakeBuildLog(console, verbosity);
}
Expand Down
22 changes: 22 additions & 0 deletions src/Cake.AzurePipelines.Module/AzurePipelinesModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.Composition;
using Cake.Core.Diagnostics;

[assembly: CakeModule(typeof(Cake.AzurePipelines.Module.AzurePipelinesModule))]

namespace Cake.AzurePipelines.Module
{
public class AzurePipelinesModule : ICakeModule
{
public void Register(ICakeContainerRegistrar registrar)
{
if (!string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable("TF_BUILD")))
{
registrar.RegisterType<AzurePipelinesEngine>().As<ICakeEngine>().Singleton();
registrar.RegisterType<AzurePipelinesLog>().As<ICakeLog>().Singleton();
registrar.RegisterType<AzurePipelinesReportPrinter>().As<ICakeReportPrinter>().Singleton();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
using Cake.Core.IO;
using Cake.Module.Shared;

namespace Cake.TFBuild.Module
namespace Cake.AzurePipelines.Module
{
/// <summary>
/// The TF Build/Azure Pipelines report printer.
/// </summary>
public class TFBuildReportPrinter : CakeReportPrinterBase
public class AzurePipelinesReportPrinter : CakeReportPrinterBase
{
/// <summary>
/// Initializes a new instance of the <see cref="TFBuildReportPrinter"/> class.
/// Initializes a new instance of the <see cref="AzurePipelinesReportPrinter"/> class.
/// </summary>
/// <param name="console">The console.</param>
/// <param name="context">The context.</param>
public TFBuildReportPrinter(IConsole console, ICakeContext context) : base(console, context)
public AzurePipelinesReportPrinter(IConsole console, ICakeContext context) : base(console, context)
{
}

Expand All @@ -36,7 +36,7 @@ public override void Write(CakeReport report)
try
{

if (_context.TFBuild().IsRunningOnAzurePipelines || _context.TFBuild().IsRunningOnAzurePipelinesHosted) {
if (_context.AzurePipelines().IsRunningOnAzurePipelines || _context.AzurePipelines().IsRunningOnAzurePipelinesHosted) {
WriteToMarkdown(report);
}
WriteToConsole(report);
Expand Down Expand Up @@ -74,7 +74,7 @@ private void WriteToMarkdown(CakeReport report)
}
}
sb.AppendLine("");
var b = _context.BuildSystem().TFBuild;
var b = _context.BuildSystem().AzurePipelines;
FilePath agentWorkPath = b.Environment.Build.ArtifactStagingDirectory + "/tasksummary.md";
var absFilePath = agentWorkPath.MakeAbsolute(_context.Environment);
var file = _context.FileSystem.GetFile(absFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Cake.TFBuild.Module</AssemblyName>
<PackageId>Cake.TFBuild.Module</PackageId>
<AssemblyName>Cake.AzurePipelines.Module</AssemblyName>
<PackageId>Cake.AzurePipelines.Module</PackageId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Cake.Module.Shared\Cake.Module.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="0.38.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.38.0" PrivateAssets="All" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/Cake.AzurePipelines.Module/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cake.Common.Build.AzurePipelines;
using Cake.Common.Build.AzurePipelines.Data;

namespace Cake.AzurePipelines.Module
{
public static class Extensions
{
public static void UpdateProgress(this IAzurePipelinesProvider provider, Guid parent, int progress)
{
provider.Commands.UpdateRecord(parent, new AzurePipelinesRecordData {Progress = progress, Status = AzurePipelinesTaskStatus.InProgress});
}

internal static bool IsRunningOnPipelines(this Common.Build.BuildSystem b) => b.IsRunningOnAzurePipelines || b.IsRunningOnAzurePipelinesHosted;
}
}
2 changes: 1 addition & 1 deletion src/Cake.BuildSystems.Module.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Module.Shared", "Cake.Module.Shared\Cake.Module.Shared.csproj", "{19079E09-A53C-4D38-ACC6-66DECAC59372}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.TFBuild.Module", "Cake.TFBuild.Module\Cake.TFBuild.Module.csproj", "{2534AB29-02D3-43FB-B4B8-F19CF7CE2FB1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.AzurePipelines.Module", "Cake.AzurePipelines.Module\Cake.AzurePipelines.Module.csproj", "{2534AB29-02D3-43FB-B4B8-F19CF7CE2FB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.TeamCity.Module", "Cake.TeamCity.Module\Cake.TeamCity.Module.csproj", "{F30233D0-D123-49A1-90CD-FD69C0ABC45A}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Module.Shared/Cake.Module.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="0.38.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.38.0" PrivateAssets="All" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/Cake.MyGet.Module/Cake.MyGet.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="0.38.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.38.0" PrivateAssets="All" />
</ItemGroup>

</Project>
</Project>
19 changes: 0 additions & 19 deletions src/Cake.TFBuild.Module/Extensions.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/Cake.TFBuild.Module/TFBuildModule.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Cake.TeamCity.Module/Cake.TeamCity.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="0.38.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.38.0" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Cake.TeamCity.Module/TeamCityModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Register(ICakeContainerRegistrar registrar)
{
registrar.RegisterType<TeamCityEngine>().As<ICakeEngine>().Singleton();
registrar.RegisterType<TeamCityLog>().As<ICakeLog>().Singleton();
//registrar.RegisterType<TFBuildReportPrinter>().As<ICakeReportPrinter>().Singleton();
//registrar.RegisterType<TeamCityReportPrinter>().As<ICakeReportPrinter>().Singleton();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.TravisCI.Module/Cake.TravisCI.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.34.1" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="0.38.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.38.0" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Cake.TravisCI.Module/TravisCIModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Register(ICakeContainerRegistrar registrar)
{
registrar.RegisterType<TravisCIEngine>().As<ICakeEngine>().Singleton();
registrar.RegisterType<TravisCILog>().As<ICakeLog>().Singleton();
//registrar.RegisterType<TFBuildReportPrinter>().As<ICakeReportPrinter>().Singleton();
//registrar.RegisterType<TravisCIReportPrinter>().As<ICakeReportPrinter>().Singleton();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.34.1" />
<package id="Cake" version="0.38.0" />
</packages>

0 comments on commit 01d3931

Please sign in to comment.