Skip to content
This repository has been archived by the owner on Nov 28, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/0.32.1'
Browse files Browse the repository at this point in the history
* release/0.32.1:
  (GH-60) Update to Cake 0.32.1
  Add support for asynchronous tasks
  (maint) Update readme and nuget feeds
  • Loading branch information
devlead committed Apr 9, 2019
2 parents f1b75c4 + 064456b commit 083570d
Show file tree
Hide file tree
Showing 25 changed files with 234 additions and 51 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

[![AppVeyor branch](https://img.shields.io/appveyor/ci/cakebuild/frosting/develop.svg)](https://ci.appveyor.com/project/cakebuild/frosting/branch/develop)
[![MyGet](https://img.shields.io/myget/cake/vpre/Cake.Frosting.svg?label=myget)](https://www.myget.org/feed/cake/package/nuget/Cake.Frosting)
[![NuGet](https://img.shields.io/nuget/v/Cake.Frosting.svg)](https://www.nuget.org/packages/Cake.Frosting)

A .NET Core host for Cake, that allows you to write your build scripts as a
(portable) console application (`netcoreapp1.1` or `net461`). Frosting is currently
in alpha, but more information, documentation and samples will be added soon.
(portable) console application (`netcoreapp2.0` or `net461`). Frosting is currently
in pre-release / incubation.

**Expect things to move around initially. Especially naming of things.**

Expand All @@ -20,17 +21,14 @@ in alpha, but more information, documentation and samples will be added soon.

## Example

### 1. Install .NET Core SDK 1.0.4 or later
### 1. Install .NET Core SDK 2.1.500 or later

You can find the SDK at [https://www.microsoft.com/net/download/core](https://www.microsoft.com/net/download/core).
You can find the SDK at [https://dotnet.microsoft.com/download](https://dotnet.microsoft.com/download).

### 2. Install the template

Cake.Frosting is currently in preview, so you will have to specify the
template version explicitly.

```
> dotnet new --install Cake.Frosting.Template::0.1.0-*
> dotnet new --install Cake.Frosting.Template
```

### 3. Create a new Frosting project
Expand Down Expand Up @@ -58,7 +56,7 @@ The above command is what you're expected to run from your bootstrapper.
### .NET Core SDK

To build from source, you will need to have
[.NET Core SDK 1.0.4](https://www.microsoft.com/net/download/core)
[.NET Core SDK 2.1.4](https://dotnet.microsoft.com/download)
installed on your machine.

### Visual Studio 2017 (optional)
Expand Down
2 changes: 1 addition & 1 deletion build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="0.30.0" />
<PackageReference Include="Cake.Frosting" Version="0.31.0" />
</ItemGroup>

</Project>
6 changes: 1 addition & 5 deletions build/Tasks/Restore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ public override void Run(Context context)
{
context.DotNetCoreRestore("./src", new DotNetCoreRestoreSettings
{
MSBuildSettings = context.MSBuildSettings,
Sources = new [] {
"https://api.nuget.org/v3/index.json",
"https://www.myget.org/F/cake/api/v3/index.json"
}
MSBuildSettings = context.MSBuildSettings
});
}
}
6 changes: 0 additions & 6 deletions build/nuget.config

This file was deleted.

10 changes: 9 additions & 1 deletion src/Cake.Frosting.Example/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;

Expand All @@ -12,8 +13,15 @@ public sealed class Hello : FrostingTask<Settings>
}

[Dependency(typeof(Hello))]
public sealed class World : FrostingTask<Settings>
public sealed class World : AsyncFrostingTask<Settings>
{
// Tasks can be asynchronous
public override async Task RunAsync(Settings context)
{
context.Log.Information("About to do something expensive");
await Task.Delay(1500);
context.Log.Information("Done");
}
}

[Dependency(typeof(World))]
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Frosting.Tests/Cake.Frosting.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="Cake.Testing" Version="0.31.0" />
<PackageReference Include="Cake.Testing" Version="0.32.1" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/Cake.Frosting.Tests/Data/Tasks/OnErrorRunAsyncFailedTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;

namespace Cake.Frosting.Tests.Data.Tasks
{
[TaskName("On-Error-RunAsync-Failed")]
public sealed class OnErrorRunAsyncFailedTask : AsyncFrostingTask<ICakeContext>
{
public override Task RunAsync(ICakeContext context)
{
throw new InvalidOperationException("On test exception");
}

public override void OnError(Exception exception, ICakeContext context)
{
context.Log.Error("An error has occurred. {0}", exception.Message);
}
}
}
15 changes: 15 additions & 0 deletions src/Cake.Frosting.Tests/Unit/CakeHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,21 @@ public void Should_Execute_OnError_Method_If_Run_Failed()
fixture.Log.Received(1).Error("An error has occurred. {0}", "On test exception");
}

[Fact]
public void Should_Execute_OnError_Method_If_RunAsync_Failed()
{
// Given
var fixture = new CakeHostBuilderFixture();
fixture.RegisterTask<OnErrorRunAsyncFailedTask>();
fixture.Options.Target = "On-Error-RunAsync-Failed";

// When
fixture.Run();

// Then
fixture.Log.Received(1).Error("An error has occurred. {0}", "On test exception");
}

[Fact]
public void Should_Not_Execute_OnError_Method_If_Run_Completed()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Cake.Frosting/Abstractions/IFrostingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Threading.Tasks;
using Cake.Core;

// ReSharper disable once CheckNamespace
Expand All @@ -17,7 +18,7 @@ public interface IFrostingTask
/// Runs the task using the specified context.
/// </summary>
/// <param name="context">The context.</param>
void Run(ICakeContext context);
Task RunAsync(ICakeContext context);

/// <summary>
/// Gets whether or not the task should be run.
Expand Down
100 changes: 100 additions & 0 deletions src/Cake.Frosting/AsyncFrostingTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Cake.Core;
using Cake.Frosting.Internal;

namespace Cake.Frosting
{
/// <summary>
/// Base class for an asynchronous Frosting task using the standard context.
/// </summary>
/// <seealso cref="ICakeContext" />
public abstract class AsyncFrostingTask : AsyncFrostingTask<ICakeContext>
{
}

/// <summary>
/// Base class for an asynchronous Frosting task using a custom context.
/// </summary>
/// <typeparam name="T">The context type.</typeparam>
/// <seealso cref="IFrostingTask" />
public abstract class AsyncFrostingTask<T> : IFrostingTask
where T : ICakeContext
{
/// <summary>
/// Runs the task using the specified context.
/// </summary>
/// <param name="context">The context.</param>
public virtual Task RunAsync(T context)
{
return Task.CompletedTask;
}

/// <summary>
/// Gets whether or not the task should be run.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>
/// <c>true</c> if the task should run; otherwise <c>false</c>.
/// </returns>
public virtual bool ShouldRun(T context)
{
return true;
}

/// <summary>
/// The error handler to be executed using the specified context if an exception occurs in the task.
/// </summary>
/// <param name="exception">The exception.</param>
/// <param name="context">The context.</param>
public virtual void OnError(Exception exception, T context)
{
}

/// <summary>
/// The finally handler to be executed using the specified context after the task has finished executing.
/// </summary>
/// <param name="context">The context.</param>
public virtual void Finally(T context)
{
}

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Explicit implementation.")]
Task IFrostingTask.RunAsync(ICakeContext context)
{
Guard.ArgumentNotNull(context, nameof(context));

return RunAsync((T)context);
}

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Explicit implementation.")]
bool IFrostingTask.ShouldRun(ICakeContext context)
{
Guard.ArgumentNotNull(context, nameof(context));

return ShouldRun((T)context);
}

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Explicit implementation.")]
void IFrostingTask.OnError(Exception exception, ICakeContext context)
{
Guard.ArgumentNotNull(exception, nameof(exception));
Guard.ArgumentNotNull(context, nameof(context));

OnError(exception, (T)context);
}

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Explicit implementation.")]
void IFrostingTask.Finally(ICakeContext context)
{
Guard.ArgumentNotNull(context, nameof(context));

Finally((T)context);
}
}
}
4 changes: 2 additions & 2 deletions src/Cake.Frosting/Cake.Frosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.31.0" />
<PackageReference Include="Cake.Common" Version="0.31.0" />
<PackageReference Include="Cake.Core" Version="0.32.1" />
<PackageReference Include="Cake.Common" Version="0.32.1" />
<None Include="../../LICENSE" Pack="true" PackagePath="$(PackageLicenseFile)"/>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Frosting/CakeHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public int Run()

// Get the command and execute.
var command = _commandFactory.GetCommand(_options);
var result = command.Execute(_engine, _options);
var result = command.ExecuteAsync(_engine, _options).GetAwaiter().GetResult();

// Return success.
return result ? 0 : 1;
Expand Down
4 changes: 3 additions & 1 deletion src/Cake.Frosting/FrostingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Cake.Core;
using Cake.Frosting.Internal;

Expand Down Expand Up @@ -63,11 +64,12 @@ public virtual void Finally(T context)
}

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Explicit implementation.")]
void IFrostingTask.Run(ICakeContext context)
Task IFrostingTask.RunAsync(ICakeContext context)
{
Guard.ArgumentNotNull(context, nameof(context));

Run((T)context);
return Task.CompletedTask;
}

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Explicit implementation.")]
Expand Down
3 changes: 2 additions & 1 deletion src/Cake.Frosting/Internal/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;

namespace Cake.Frosting.Internal.Commands
{
internal abstract class Command
{
public abstract bool Execute(ICakeEngine engine, CakeHostOptions options);
public abstract Task<bool> ExecuteAsync(ICakeEngine engine, CakeHostOptions options);
}
}
7 changes: 4 additions & 3 deletions src/Cake.Frosting/Internal/Commands/DryRunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;

Expand All @@ -20,16 +21,16 @@ public DryRunCommand(IFrostingContext context, ICakeLog log)
_executionSettings = new ExecutionSettings();
}

public override bool Execute(ICakeEngine engine, CakeHostOptions options)
public override async Task<bool> ExecuteAsync(ICakeEngine engine, CakeHostOptions options)
{
_executionSettings.SetTarget(options.Target);

_log.Information("Performing dry run...");
_log.Information("Target is: {0}", options.Target);
_log.Information(string.Empty);

var strategy = new DryRunExecutionStrategy(_log);
engine.RunTargetAsync(_context, strategy, _executionSettings).GetAwaiter().GetResult();
await engine.RunTargetAsync(_context, strategy, _executionSettings).ConfigureAwait(false);

_log.Information(string.Empty);
_log.Information("This was a dry run.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Task ExecuteAsync(CakeTask task, ICakeContext context)
_log.Information("{0}. {1}", _counter, task.Name);
_counter++;
}

return Task.CompletedTask;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Cake.Frosting/Internal/Commands/ErrorDecoratorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;

namespace Cake.Frosting.Internal.Commands
Expand All @@ -15,9 +16,9 @@ public ErrorDecoratorCommand(Command command)
_command = command;
}

public override bool Execute(ICakeEngine engine, CakeHostOptions options)
public override async Task<bool> ExecuteAsync(ICakeEngine engine, CakeHostOptions options)
{
_command.Execute(engine, options);
await _command.ExecuteAsync(engine, options).ConfigureAwait(false);
return false;
}
}
Expand Down
Loading

0 comments on commit 083570d

Please sign in to comment.