Skip to content

Commit

Permalink
Merge pull request cake-contrib#292 from nils-a/feature/cake-contribG…
Browse files Browse the repository at this point in the history
…H-290

(cake-contrib#290) Update Guidelines to include Cake 4.0.0
  • Loading branch information
nils-a authored Nov 20, 2023
2 parents 0766743 + 0a6938e commit 04276d4
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 7 deletions.
29 changes: 29 additions & 0 deletions docs/input/guidelines/CakeInternalReferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Title: Target Frameworks
- [Cake v3.0.0](#cake-v300)
- [Related rules](#related-rules)
- [Usage](#usage)
- [Settings](#settings)
- [Cake Version](#cake-version)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -89,6 +91,27 @@ Also, the reference of the package in the addin/module should be set as private
| System.Reflection.Metadata | 7.0.0 |
| xunit | 2.4.2 |

#### Cake v4.0

| Reference | Version |
| ---------------------------------------- | ------------- |
| Autofac | 7.1.0 |
| Microsoft.CodeAnalysis.CSharp.Scripting | 4.8.0-3.final |
| Microsoft.CSharp | 4.7.0 |
| Microsoft.Extensions.DependencyInjection | 8.0.0 |
| Microsoft.NETCore.Platforms | 7.0.4 |
| Microsoft.Win32.Registry | 5.0.0 |
| Newtonsoft.Json | 13.0.3 |
| NuGet.Common | 6.7.0 |
| NuGet.Frameworks | 6.7.0 |
| NuGet.Packaging | 6.7.0 |
| NuGet.Protocol | 6.7.0 |
| NuGet.Resolver | 6.7.0 |
| NuGet.Versioning | 6.7.0 |
| System.Collections.Immutable | 8.0.0 |
| System.Reflection.Metadata | 8.0.0 |
| xunit | 2.6.1 |

## Related rules

* [CCG0010](../rules/ccg0010)
Expand All @@ -98,3 +121,9 @@ These rules are only applied for [project types](../settings#projecttype) `addin
## Usage

Using this package automatically enables this guideline.

## Settings

### Cake Version

<?! Include "../settings/fragments/OverrideCakeVersion.md" /?>
7 changes: 7 additions & 0 deletions docs/input/guidelines/TargetFramework.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ while missing a suggested target version will raise [CCG0007](../rules/ccg0007)
* Cake.Core >= 3.0.0
* Required: `net6.0`
* Required: `net7.0`
* Cake.Core >= 4.0.0
* Required: `net6.0`
* Required: `net7.0`
* Required: `net8.0`
* Package type: module
* Cake.Core < 2.0.0
* Required: `netstandard2.0`
Expand All @@ -54,6 +58,9 @@ while missing a suggested target version will raise [CCG0007](../rules/ccg0007)
* Cake.Core >= 3.0.0
* Required: `net6.0`
* No additional targets are allowed.
* Cake.Core >= 4.0.0
* Required: `net6.0`
* No additional targets are allowed.

For package type recipe no framework reference is required or suggested.

Expand Down
18 changes: 18 additions & 0 deletions src/Tasks.Tests/CheckCakeInternalReferencesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,23 @@ public void Should_Warn_If_Cake_Version_is_Out_Of_Range()
fixture.BuildEngine.WarningEvents.First().Message.ShouldNotContain("6.3.1");
fixture.BuildEngine.WarningEvents.First().Message.ShouldContain("no matching list of Cake provided references could be found");
}

[Fact]
public void Should_Warn_If_Newtonsoft_Is_Wrong_For_Cake_4()
{
// given
var fixture = new CheckCakeInternalReferencesFixture();
fixture.WithReference("Newtonsoft.Json", "13.0.1");
fixture.WithReference("Cake.Core", "4.0.0");
fixture.WithCakeVersion(string.Empty);

// when
fixture.Execute();

// then
fixture.BuildEngine.WarningEvents.Count.ShouldBe(1);
fixture.BuildEngine.WarningEvents.First().Code.ShouldBe(CcgRule10);
fixture.BuildEngine.WarningEvents.First().Message.ShouldContain("13.0.3"); // the required version for NuGet.Common
}
}
}
50 changes: 50 additions & 0 deletions src/Tasks.Tests/TargetFrameworkVersionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TargetFrameworkVersionsTests
private const string Net50 = "net5.0";
private const string Net60 = "net6.0";
private const string Net70 = "net7.0";
private const string Net80 = "net8.0";

[Fact]
public void Should_Error_If_RequiredTargetFramework_Is_Not_Targeted()
Expand Down Expand Up @@ -335,6 +336,39 @@ public static IEnumerable<object[]> Should_Error_If_RequiredTargetFramework_Is_N
yield return new object[] { new[] { Net60, Net70 }, false, string.Empty };
}

[Theory]
[MemberData(nameof(Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Cake_4_Data))]
public void Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Cake_4(string[] targetFrameworks, bool expectedError, string missingTargetFramework)
{
// given
var fixture = new TargetFrameworkVersionsFixture();
fixture.WithCakeCoreReference(4);
fixture.WithTargetFrameworks(targetFrameworks);

// when
fixture.Execute();

// then
if (expectedError)
{
fixture.BuildEngine.ErrorEvents.Count.ShouldBe(1);
fixture.BuildEngine.ErrorEvents.First().Message.ShouldContain(missingTargetFramework);
}
else
{
fixture.BuildEngine.ErrorEvents.Count.ShouldBe(0);
}
}

public static IEnumerable<object[]> Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Cake_4_Data()
{
yield return new object[] { Array.Empty<string>(), true, Net60 };
yield return new object[] { new[] { Net60 }, true, Net70 };
yield return new object[] { new[] { Net70 }, true, Net60 };
yield return new object[] { new[] { Net60, Net70 }, true, Net80 };
yield return new object[] { new[] { Net60, Net70, Net80 }, false, string.Empty };
}

[Fact]
public void Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Cake_2_Module()
{
Expand Down Expand Up @@ -367,6 +401,22 @@ public void Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Cake_3_Modul
fixture.BuildEngine.ErrorEvents.First().Message.ShouldContain(Net60);
}

[Fact]
public void Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Cake_4_Module()
{
// given
var fixture = new TargetFrameworkVersionsFixture();
fixture.WithProjectType("module");
fixture.WithCakeCoreReference("4.0.0");

// when
fixture.Execute();

// then
fixture.BuildEngine.ErrorEvents.Count.ShouldBe(1);
fixture.BuildEngine.ErrorEvents.First().Message.ShouldContain(Net60);
}

[Fact]
public void Should_Error_If_RequiredTargetFramework_Is_Not_Targeted_Module_Explicit_Version()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Tasks/CakeVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ internal static class CakeVersions
// Cake 3.0.0
internal static readonly Version V3 = new Version(3, 0, 0);

// Cake 4.0.0
public static readonly Version V4 = new Version(4, 0, 0);

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (macos-12)

Check warning on line 20 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (macos-12)


// The next, currently non-existing cake version
public static Version VNext = new Version(4, 0, 0);
public static Version VNext = new Version(5, 0, 0);

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (macos-12)

Check warning on line 23 in src/Tasks/CakeVersions.cs

View workflow job for this annotation

GitHub Actions / build (macos-12)

}
}
27 changes: 26 additions & 1 deletion src/Tasks/CheckCakeInternalReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ public class CheckCakeInternalReferences : Task
{ "xunit", "2.4.2" },
};

// parsed from Cake: v4.0
private static readonly Dictionary<string, string> CakeV40 = new Dictionary<string, string>
{
{ "Autofac", "7.1.0" },
{ "Microsoft.CodeAnalysis.CSharp.Scripting", "4.8.0-3.final" },
{ "Microsoft.CSharp", "4.7.0" },
{ "Microsoft.Extensions.DependencyInjection", "8.0.0" },
{ "Microsoft.NETCore.Platforms", "7.0.4" },
{ "Microsoft.Win32.Registry", "5.0.0" },
{ "Newtonsoft.Json", "13.0.3" },
{ "NuGet.Common", "6.7.0" },
{ "NuGet.Frameworks", "6.7.0" },
{ "NuGet.Packaging", "6.7.0" },
{ "NuGet.Protocol", "6.7.0" },
{ "NuGet.Resolver", "6.7.0" },
{ "NuGet.Versioning", "6.7.0" },
{ "System.Collections.Immutable", "8.0.0" },
{ "System.Reflection.Metadata", "8.0.0" },
{ "xunit", "2.6.1" },
};

private readonly Dictionary<Predicate<Version>, Dictionary<string, string>> allInternalReferences =
new Dictionary<Predicate<Version>, Dictionary<string, string>>
{
Expand All @@ -123,9 +144,13 @@ public class CheckCakeInternalReferences : Task
CakeV20
},
{
x => x.GreaterEqual(CakeVersions.V3) && x.LessThan(CakeVersions.VNext),
x => x.GreaterEqual(CakeVersions.V3) && x.LessThan(CakeVersions.V4),
CakeV30
},
{
x => x.GreaterEqual(CakeVersions.V4) && x.LessThan(CakeVersions.VNext),
CakeV40
},
};

/// <summary>
Expand Down
34 changes: 29 additions & 5 deletions src/Tasks/TargetFrameworkVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class TargetFrameworkVersions : Task
private const string Net50 = "net5.0";
private const string Net60 = "net6.0";
private const string Net70 = "net7.0";
private const string Net80 = "net8.0";

private static readonly TargetsDefinitions DefaultTarget = new TargetsDefinitions
{
Expand Down Expand Up @@ -56,16 +57,25 @@ public class TargetFrameworkVersions : Task
d => d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V2) && d.Version.LessThan(CakeVersions.V3),
new TargetsDefinitions
{
Name = "Module and 2.0.0 <= CakeVersion < 3.0.0 ",
Name = "Module and 2.0.0 <= CakeVersion < 3.0.0",
RequiredTargets = new[] { TargetsDefinition.From(NetCore31) },
AllowAdditionalTargets = false,
}
},
{
d => d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V3),
d => d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V3) && d.Version.LessThan(CakeVersions.V4),
new TargetsDefinitions
{
Name = "Module and CakeVersion >= 3.0.0",
Name = "Module and 3.0.0 <= CakeVersion < 4.0.0",
RequiredTargets = new[] { TargetsDefinition.From(Net60) },
AllowAdditionalTargets = false,
}
},
{
d => d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V4),
new TargetsDefinitions
{
Name = "Module and CakeVersion >= 4.0.0",
RequiredTargets = new[] { TargetsDefinition.From(Net60) },
AllowAdditionalTargets = false,
}
Expand Down Expand Up @@ -107,14 +117,28 @@ public class TargetFrameworkVersions : Task
}
},
{
d => !d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V3),
d => !d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V3) && d.Version.LessThan(CakeVersions.V4),
new TargetsDefinitions
{
Name = "not module and 3.0.0 <= CakeVersion < 4.0.0",
RequiredTargets = new[]
{
TargetsDefinition.From(Net60),
TargetsDefinition.From(Net70),
},
SuggestedTargets = Array.Empty<TargetsDefinition>(),
}
},
{
d => !d.IsModuleProject && d.Version.GreaterEqual(CakeVersions.V4),
new TargetsDefinitions
{
Name = "not module and CakeVersion >= 3.0.0",
Name = "not module and CakeVersion >= 4.0.0",
RequiredTargets = new[]
{
TargetsDefinition.From(Net60),
TargetsDefinition.From(Net70),
TargetsDefinition.From(Net80),
},
SuggestedTargets = Array.Empty<TargetsDefinition>(),
}
Expand Down

0 comments on commit 04276d4

Please sign in to comment.