Skip to content

Commit

Permalink
Fixed interface inference. (#3812)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jun 8, 2021
1 parent 4d8ddbb commit 7770890
Show file tree
Hide file tree
Showing 33 changed files with 657 additions and 78 deletions.
1 change: 1 addition & 0 deletions .build/Build.Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ partial class Build : NukeBuild
AbsolutePath AllSolutionFile => SourceDirectory / "All.sln";
AbsolutePath SonarSolutionFile => SourceDirectory / "Sonar.sln";
AbsolutePath TestSolutionFile => TemporaryDirectory / "All.Test.sln";
AbsolutePath PackSolutionFile => SourceDirectory / "All.Pack.sln";
AbsolutePath SgSolutionFile => SourceDirectory / "StrawberryShake" / "SourceGenerator" / "StrawberryShake.SourceGenerator.sln";

AbsolutePath OutputDirectory => RootDirectory / "output";
Expand Down
177 changes: 177 additions & 0 deletions .build/Build.PublicApiAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System.IO;
using System.Linq;
using Colorful;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;
using static Helpers;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System;
using System.Drawing;

partial class Build : NukeBuild
{
private readonly string _shippedApiFile = "PublicAPI.Shipped.txt";
private readonly string _unshippedApiFile = "PublicAPI.Unshipped.txt";
private readonly string _removedApiPrefix = "*REMOVED*";

[Parameter] readonly string From;
[Parameter] readonly string To;
[Parameter] readonly bool Breaking;

Target CheckPublicApi => _ => _
.DependsOn(Restore)
.Executes(() =>
{
if (!InvokedTargets.Contains(Restore))
{
DotNetBuildSonarSolution(AllSolutionFile);
}

DotNetBuild(c => c
.SetProjectFile(AllSolutionFile)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(Configuration)
.SetProperty("RequireDocumentationOfPublicApiChanges", true));
});

Target AddUnshipped => _ => _
.DependsOn(Restore)
.Executes(() =>
{
// first we ensure that the All.sln exists.
if (!InvokedTargets.Contains(Restore))
{
DotNetBuildSonarSolution(AllSolutionFile);
}

// new we restore our local dotnet tools including dotnet-format
DotNetToolRestore(c => c.SetProcessWorkingDirectory(RootDirectory));

// last we run the actual dotnet format command.
DotNet($@"format ""{AllSolutionFile}"" --fix-analyzers warn --diagnostics RS0016", workingDirectory: RootDirectory);
});

Target DiffShippedApi => _ => _
.Executes(() =>
{
var from = string.IsNullOrEmpty(From) ? GitRepository.Branch : From;
var to = string.IsNullOrEmpty(To) ? "main" : To;

if (from == to)
{
Colorful.Console.WriteLine("Nothing to diff here.", Color.Yellow);
return;
}

AbsolutePath shippedPath = SourceDirectory / "**" / _shippedApiFile;

Git($@" --no-pager diff --minimal -U0 --word-diff ""{from}"" ""{to}"" -- ""{shippedPath}""", RootDirectory);
});

Target DisplayUnshippedApi => _ => _
.Executes(async () =>
{
var unshippedFiles = Directory.GetFiles(SourceDirectory, _unshippedApiFile, SearchOption.AllDirectories);

if (Breaking)
{
Colorful.Console.WriteLine("Unshipped breaking changes:", Color.Red);
}
else
{
Colorful.Console.WriteLine("Unshipped changes:");
}

Colorful.Console.WriteLine();

foreach (var unshippedFile in unshippedFiles)
{
IEnumerable<string> unshippedApis = await GetNonEmptyLinesAsync(unshippedFile);

if (Breaking)
{
unshippedApis = unshippedApis.Where(u => u.StartsWith(_removedApiPrefix)).ToList();
}

if (!unshippedApis.Any())
{
continue;
}

foreach (var unshippedApi in unshippedApis)
{
if (unshippedApi.StartsWith(_removedApiPrefix))
{
var value = unshippedApi[_removedApiPrefix.Length..];
Colorful.Console.WriteLine(value);
}
else
{
Colorful.Console.WriteLine(unshippedApi);
}
}
}
});

Target MarkApiShipped => _ => _
.Executes(async () =>
{
var shippedFiles = Directory.GetFiles(SourceDirectory, _shippedApiFile, SearchOption.AllDirectories);

foreach (var shippedFile in shippedFiles)
{
var projectDir = Path.GetDirectoryName(shippedFile);
var unshippedFile = Path.Join(projectDir, _unshippedApiFile);

if (!File.Exists(unshippedFile))
{
continue;
}

List<string> unshippedApis = await GetNonEmptyLinesAsync(unshippedFile);

if (!unshippedApis.Any())
{
continue;
}

List<string> shippedApis = await GetNonEmptyLinesAsync(shippedFile);

List<string> removedApis = new();

foreach (var unshippedApi in unshippedApis)
{
if (unshippedApi.StartsWith(_removedApiPrefix))
{
var value = unshippedApi[_removedApiPrefix.Length..];
removedApis.Add(value);
}
else
{
shippedApis.Add(unshippedApi);
}
}

IOrderedEnumerable<string> newShippedApis = shippedApis
.Where(s => !removedApis.Contains(s))
.Distinct()
.OrderBy(s => s);

await File.WriteAllLinesAsync(shippedFile, newShippedApis, Encoding.ASCII);
await File.WriteAllTextAsync(unshippedFile, "", Encoding.ASCII);
}
});

private static async Task<List<string>> GetNonEmptyLinesAsync(string filepath)
{
var lines = await File.ReadAllLinesAsync(filepath);

return lines.Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
}
}
24 changes: 17 additions & 7 deletions .build/Build.Publish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ partial class Build : NukeBuild
[Parameter("NuGet Api Key")] readonly string NuGetApiKey;

Target Pack => _ => _
.DependsOn(Restore, PackLocal)
.DependsOn(PackLocal)
.Produces(PackageDirectory / "*.nupkg")
.Produces(PackageDirectory / "*.snupkg")
.Requires(() => Configuration.Equals(Release))
Expand All @@ -41,14 +41,24 @@ partial class Build : NukeBuild
.Produces(PackageDirectory / "*.snupkg")
.Executes(() =>
{
if (!InvokedTargets.Contains(Restore))
{
DotNetBuildSonarSolution(AllSolutionFile);
}
DotNetBuildSonarSolution(
PackSolutionFile,
include: file =>
!Path.GetFileNameWithoutExtension(file)
.EndsWith("tests", StringComparison.OrdinalIgnoreCase));

DotNetBuild(c => c
.SetProjectFile(PackSolutionFile)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer));

DotNetPack(c => c
.SetProject(AllSolutionFile)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetProject(PackSolutionFile)
.SetNoRestore(true)
.SetNoBuild(true)
.SetConfiguration(Configuration)
.SetOutputDirectory(PackageDirectory)
.SetVersion(GitVersion.SemVer));
Expand Down
3 changes: 1 addition & 2 deletions .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ partial class Build : NukeBuild
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer)
.SetProperty("RequireDocumentationOfPublicApiChanges", true));
.SetVersion(GitVersion.SemVer));
});
}
2 changes: 1 addition & 1 deletion .build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="5.0.2" />
<PackageReference Include="Nuke.Common" Version="5.1.2" />
<PackageDownload Include="GitVersion.Tool" Version="[5.6.3]" />
<PackageDownload Include="NuGet.CommandLine" Version="[5.5.1]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.0.4]" />
Expand Down
12 changes: 7 additions & 5 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Helpers
public static readonly string[] Directories =
{
"GreenDonut",
// Path.Combine("HotChocolate", "ApolloFederation"),
Path.Combine("HotChocolate", "AspNetCore"),
Path.Combine("HotChocolate", "Core"),
Path.Combine("HotChocolate", "Language"),
Expand All @@ -29,14 +28,16 @@ class Helpers

public static IEnumerable<string> GetAllProjects(
string sourceDirectory,
IEnumerable<string> directories)
IEnumerable<string> directories,
Func<string, bool> include = null)
{
foreach (var directory in directories)
{
var fullDirectory = Path.Combine(sourceDirectory, directory);
foreach (var file in Directory.EnumerateFiles(fullDirectory, "*.csproj", SearchOption.AllDirectories))
{
if (file.Contains("benchmark", StringComparison.OrdinalIgnoreCase)
if (!(include?.Invoke(file) ?? true)
|| file.Contains("benchmark", StringComparison.OrdinalIgnoreCase)
|| file.Contains("demo", StringComparison.OrdinalIgnoreCase)
|| file.Contains("sample", StringComparison.OrdinalIgnoreCase)
|| file.Contains("HotChocolate.Core.Tests", StringComparison.OrdinalIgnoreCase)
Expand All @@ -52,7 +53,8 @@ public static IEnumerable<string> GetAllProjects(

public static IReadOnlyCollection<Output> DotNetBuildSonarSolution(
string solutionFile,
IEnumerable<string> directories = null)
IEnumerable<string> directories = null,
Func<string, bool> include = null)
{
if (File.Exists(solutionFile))
{
Expand All @@ -61,7 +63,7 @@ public static IReadOnlyCollection<Output> DotNetBuildSonarSolution(

directories ??= Directories;

IEnumerable<string> projects = GetAllProjects(Path.GetDirectoryName(solutionFile), directories);
IEnumerable<string> projects = GetAllProjects(Path.GetDirectoryName(solutionFile), directories, include);
var workingDirectory = Path.GetDirectoryName(solutionFile);
var list = new List<Output>();

Expand Down
14 changes: 13 additions & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@
"dotnet-sonarscanner"
]
},
"boost.tool": {
"version": "0.2.2",
"commands": [
"boo"
]
},
"dotnet-format": {
"version": "5.1.225507",
"commands": [
"dotnet-format"
]
},
"nuke.globaltool": {
"version": "0.24.11",
"version": "5.1.2",
"commands": [
"nuke"
]
Expand Down
45 changes: 45 additions & 0 deletions .devops/azure-pipelines.release-hotchocolate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ stages:
strategy:
parallel: 5
steps:
- task: UseDotNet@2
displayName: "Install .NET Core 2.1"
inputs:
packageType: 'sdk'
version: '2.1.816'
- task: UseDotNet@2
displayName: "Install .NET Core 3.1"
inputs:
packageType: 'sdk'
version: '3.1.409'
- task: UseDotNet@2
displayName: "Install .NET 5.0"
inputs:
packageType: 'sdk'
version: '5.0.300'
- task: UseDotNet@2
displayName: "Install .NET Core"
inputs:
Expand All @@ -32,6 +47,21 @@ stages:
displayName: "Pack"
dependsOn: []
steps:
- task: UseDotNet@2
displayName: "Install .NET Core 2.1"
inputs:
packageType: 'sdk'
version: '2.1.816'
- task: UseDotNet@2
displayName: "Install .NET Core 3.1"
inputs:
packageType: 'sdk'
version: '3.1.409'
- task: UseDotNet@2
displayName: "Install .NET 5.0"
inputs:
packageType: 'sdk'
version: '5.0.300'
- task: UseDotNet@2
displayName: "Install .NET Core"
inputs:
Expand All @@ -50,6 +80,21 @@ stages:
displayName: "Publish"
dependsOn: [Test, Pack]
steps:
- task: UseDotNet@2
displayName: "Install .NET Core 2.1"
inputs:
packageType: 'sdk'
version: '2.1.816'
- task: UseDotNet@2
displayName: "Install .NET Core 3.1"
inputs:
packageType: 'sdk'
version: '3.1.409'
- task: UseDotNet@2
displayName: "Install .NET 5.0"
inputs:
packageType: 'sdk'
version: '5.0.300'
- task: UseDotNet@2
displayName: "Install .NET Core"
inputs:
Expand Down
Loading

0 comments on commit 7770890

Please sign in to comment.