Skip to content

Commit

Permalink
Refactored StrawberryShake code-generation. (ChilliCream#2708)
Browse files Browse the repository at this point in the history
- Switched to Source Generators
- Abstracted the code generators
- reimplemented server communication

Co-authored-by: Frederic Birke <fred@freds.garden>
Co-authored-by: PascalSenn <senn.pasc@gmail.com>
  • Loading branch information
3 people authored Feb 9, 2021
1 parent dc1e317 commit 712d3bd
Show file tree
Hide file tree
Showing 1,880 changed files with 46,780 additions and 98,866 deletions.
5 changes: 4 additions & 1 deletion .build/Build.Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
partial class Build : NukeBuild
{
AbsolutePath SourceDirectory => RootDirectory / "src";

AbsolutePath AllSolutionFile => SourceDirectory / "All.sln";

AbsolutePath SgSolutionFile => SourceDirectory / "StrawberryShake" / "SourceGenerator" / "StrawberryShake.SourceGenerator.sln";

AbsolutePath OutputDirectory => RootDirectory / "output";
AbsolutePath TestResultDirectory => OutputDirectory / "test-results";
AbsolutePath CoverageReportDirectory => OutputDirectory / "coberage-reports";
Expand All @@ -21,4 +25,3 @@ partial class Build : NukeBuild

AbsolutePath EmptyServerProj => RootDirectory / "templates" / "Server" / "content" / "HotChocolate.Server.Template.csproj";
}

2 changes: 1 addition & 1 deletion .build/Build.GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
partial class Build : NukeBuild
{
[GitRepository] readonly GitRepository GitRepository;
[GitVersion] readonly GitVersion GitVersion;
[GitVersion(Framework = "net5.0")] readonly GitVersion GitVersion;
}

91 changes: 56 additions & 35 deletions .build/Build.Publish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,18 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Build.Evaluation;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AppVeyor;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.TeamCity;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Coverlet;
using Nuke.Common.Tools.DotCover;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitHub;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.InspectCode;
using Nuke.Common.Tools.NuGet;
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Tools.Slack;
using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.ChangeLog.ChangelogTasks;
using static Nuke.Common.ControlFlow;
using static Nuke.Common.Gitter.GitterTasks;
using static Nuke.Common.IO.CompressionTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;
using static Nuke.Common.Tools.InspectCode.InspectCodeTasks;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.ReportGenerator.ReportGeneratorTasks;
using static Nuke.Common.Tools.Slack.SlackTasks;
using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks;
using static Helpers;
using static Nuke.Common.Tools.NuGet.NuGetTasks;
using Project = Microsoft.Build.Evaluation.Project;


partial class Build : NukeBuild
Expand All @@ -48,10 +23,23 @@ partial class Build : NukeBuild
[Parameter("NuGet Api Key")] readonly string NuGetApiKey;

Target Pack => _ => _
.DependsOn(PackLocal)
.Produces(PackageDirectory / "*.nupkg")
.Produces(PackageDirectory / "*.snupkg")
.Requires(() => Configuration.Equals("Release"))
.Executes(() =>
{
var projFile = File.ReadAllText(StarWarsProj);
File.WriteAllText(StarWarsProj, projFile.Replace("11.0.0-rc.1", GitVersion.SemVer));

projFile = File.ReadAllText(EmptyServerProj);
File.WriteAllText(EmptyServerProj, projFile.Replace("11.0.0-rc.1", GitVersion.SemVer));
});

Target PackLocal => _ => _
.DependsOn(Restore)
.Produces(PackageDirectory / "*.nupkg")
.Produces(PackageDirectory / "*.snupkg")
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() =>
{
if (!InvokedTargets.Contains(Restore))
Expand All @@ -66,12 +54,6 @@ partial class Build : NukeBuild
.SetOutputDirectory(PackageDirectory)
.SetVersion(GitVersion.SemVer));

var projFile = File.ReadAllText(StarWarsProj);
File.WriteAllText(StarWarsProj, projFile.Replace("11.0.0-rc.1", GitVersion.SemVer));

projFile = File.ReadAllText(EmptyServerProj);
File.WriteAllText(EmptyServerProj, projFile.Replace("11.0.0-rc.1", GitVersion.SemVer));

NuGetPack(c => c
.SetVersion(GitVersion.SemVer)
.SetOutputDirectory(PackageDirectory)
Expand All @@ -80,6 +62,43 @@ partial class Build : NukeBuild
t => t.SetTargetPath(StarWarsTemplateNuSpec),
t => t.SetTargetPath(EmptyServerTemplateNuSpec)));

var projects = ProjectModelTasks.ParseSolution(SgSolutionFile)
.AllProjects.Where(x => !x.Name.Contains("Tests"));

foreach (Nuke.Common.ProjectModel.Project project in projects)
{
Project parsedProject = ProjectModelTasks.ParseProject(project);
ProjectItem packageReference = parsedProject.Items
.FirstOrDefault(x => x.ItemType == "PackageReference" &&
!x.IsImported &&
x.EvaluatedInclude == "StrawberryShake.CodeGeneration.CSharp");

packageReference?.SetMetadataValue("Version", GitVersion.SemVer);

parsedProject.Save();
}

DotNetPack(c => c
.SetProject(SgSolutionFile)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetConfiguration(Configuration)
.SetOutputDirectory(PackageDirectory)
.SetIncludeSymbols(false)
.SetVersion(GitVersion.SemVer));

// update test projects that use the source generators
foreach (Nuke.Common.ProjectModel.Project project in projects)
{
Project parsedProject = ProjectModelTasks.ParseProject(project);
ProjectItem packageReference = parsedProject.Items
.FirstOrDefault(x => x.ItemType == "PackageReference" &&
!x.IsImported &&
x.EvaluatedInclude == "StrawberryShake.CodeGeneration.CSharp.Analyzers");

packageReference?.SetMetadataValue("Version", GitVersion.SemVer);

parsedProject.Save();
}

/*
NuGetPack(c => c
Expand All @@ -100,7 +119,7 @@ partial class Build : NukeBuild
.Consumes(Pack)
.Requires(() => NuGetSource)
.Requires(() => NuGetApiKey)
.Requires(() => Configuration.Equals(Configuration.Release))
.Requires(() => Configuration.Equals("Release"))
.Executes(() =>
{
IReadOnlyCollection<AbsolutePath> packages = PackageDirectory.GlobFiles("*.nupkg");
Expand All @@ -113,4 +132,6 @@ partial class Build : NukeBuild
degreeOfParallelism: 2,
completeOnFailure: true);
});


}
14 changes: 7 additions & 7 deletions .build/Build.Sonar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ partial class Build : NukeBuild

DotNetRestore(c => c
.SetProjectFile(AllSolutionFile)
.SetWorkingDirectory(RootDirectory));
.SetProcessWorkingDirectory(RootDirectory));

SonarScannerBegin(SonarBeginPrSettings);
DotNetBuild(SonarBuildAll);
Expand All @@ -60,7 +60,7 @@ partial class Build : NukeBuild

SonarScannerBeginSettings SonarBeginPrSettings(SonarScannerBeginSettings settings) =>
SonarBeginBaseSettings(settings)
.SetArgumentConfigurator(t => t
.SetProcessArgumentConfigurator(t => t
.Add("/o:{0}", "chillicream")
.Add("/d:sonar.pullrequest.provider={0}", "github")
.Add("/d:sonar.pullrequest.github.repository={0}", GitHubRepository)
Expand All @@ -80,19 +80,19 @@ SonarScannerBeginSettings SonarBeginBaseSettings(SonarScannerBeginSettings setti
.SetLogin(SonarToken)
.AddOpenCoverPaths(TestResultDirectory / "*.xml")
.SetVSTestReports(TestResultDirectory / "*.trx")
.SetArgumentConfigurator(t => t
.SetProcessArgumentConfigurator(t => t
.Add("/o:{0}", "chillicream")
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"));

SonarScannerBeginSettings SonarBaseSettings(SonarScannerBeginSettings settings) =>
settings
.SetLogin(SonarToken)
.SetWorkingDirectory(RootDirectory);
.SetProcessWorkingDirectory(RootDirectory);

SonarScannerEndSettings SonarEndSettings(SonarScannerEndSettings settings) =>
settings
.SetLogin(SonarToken)
.SetWorkingDirectory(RootDirectory);
.SetProcessWorkingDirectory(RootDirectory);

DotNetBuildSettings SonarBuildAll(DotNetBuildSettings settings) =>
SonarBuildBaseSettings(settings)
Expand All @@ -101,6 +101,6 @@ DotNetBuildSettings SonarBuildAll(DotNetBuildSettings settings) =>
DotNetBuildSettings SonarBuildBaseSettings(DotNetBuildSettings settings) =>
settings
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(Configuration.Debug)
.SetWorkingDirectory(RootDirectory);
.SetConfiguration("Debug")
.SetProcessWorkingDirectory(RootDirectory);
}
38 changes: 7 additions & 31 deletions .build/Build.Tests.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AppVeyor;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.TeamCity;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Coverlet;
using Nuke.Common.Tools.DotCover;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.InspectCode;
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Tools.Slack;
using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.ChangeLog.ChangelogTasks;
using static Nuke.Common.ControlFlow;
using static Nuke.Common.Gitter.GitterTasks;
using static Nuke.Common.IO.CompressionTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;
using static Nuke.Common.Tools.InspectCode.InspectCodeTasks;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.ReportGenerator.ReportGeneratorTasks;
using static Nuke.Common.Tools.Slack.SlackTasks;
using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks;
using static Helpers;


partial class Build : NukeBuild
{
readonly HashSet<string> ExcludedTests= new HashSet<string>
readonly HashSet<string> ExcludedTests = new()
{
"HotChocolate.Types.Selections.PostgreSql.Tests"
};
Expand All @@ -61,12 +38,12 @@ partial class Build : NukeBuild
{
DotNetBuildSonarSolution(AllSolutionFile);
}
try

try
{
DotNetTest(TestSettings);
}
finally
finally
{
TestResultDirectory.GlobFiles("*.trx").ForEach(x =>
DevOpsPipeLine?.PublishTestResults(
Expand All @@ -75,7 +52,7 @@ partial class Build : NukeBuild
files: new string[] { x }));
}
});

Target Cover => _ => _.DependsOn(Restore)
.Produces(TestResultDirectory / "*.trx")
.Produces(TestResultDirectory / "*.xml")
Expand Down Expand Up @@ -105,8 +82,7 @@ partial class Build : NukeBuild
.SetReports(TestResultDirectory / "*.xml")
.SetReportTypes(ReportTypes.Cobertura, ReportTypes.HtmlInline_AzurePipelines)
.SetTargetDirectory(CoverageReportDirectory)
.SetAssemblyFilters("-*Tests")
.SetFramework("netcoreapp2.1"));
.SetAssemblyFilters("-*Tests"));

if (DevOpsPipeLine is { })
{
Expand Down Expand Up @@ -160,7 +136,7 @@ IEnumerable<DotNetTestSettings> CoverSettings(DotNetTestSettings settings) =>

DotNetTestSettings TestBaseSettings(DotNetTestSettings settings) =>
settings
.SetConfiguration(Configuration.Debug)
.SetConfiguration("Debug")
.SetNoRestore(InvokedTargets.Contains(Restore))
.ResetVerbosity()
.SetResultsDirectory(TestResultDirectory);
Expand Down
2 changes: 1 addition & 1 deletion .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ partial class Build : NukeBuild
public static int Main() => Execute<Build>(x => x.Compile);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
readonly string Configuration = IsLocalBuild ? "Debug" : "Release";

[CI] readonly AzurePipelines DevOpsPipeLine;

Expand Down
10 changes: 5 additions & 5 deletions .build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
<NukeScriptDirectory>..</NukeScriptDirectory>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="0.24.11" />
<PackageDownload Include="GitVersion.Tool" Version="[5.1.1]" />
<PackageReference Include="Nuke.Common" Version="5.0.2" />
<PackageDownload Include="GitVersion.Tool" Version="[5.6.3]" />
<PackageDownload Include="NuGet.CommandLine" Version="[5.5.1]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[4.7.1]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.0.4]" />
<PackageDownload Include="OpenCover" Version="[4.7.922]" />
<PackageDownload Include="ReportGenerator" Version="[4.2.16]" />
<PackageDownload Include="ReportGenerator" Version="[4.8.4]" />
<PackageDownload Include="xunit.runner.console" Version="[2.4.1]" />
</ItemGroup>

Expand Down
6 changes: 4 additions & 2 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Helpers
{
static readonly string[] _directories = new string[]
static readonly string[] _directories =
{
"GreenDonut",
// Path.Combine("HotChocolate", "ApolloFederation"),
Expand All @@ -20,7 +20,9 @@ class Helpers
Path.Combine("HotChocolate", "Filters"),
Path.Combine("HotChocolate", "MongoDb"),
Path.Combine("HotChocolate", "Stitching"),
Path.Combine("HotChocolate", "Spatial")
Path.Combine("HotChocolate", "Spatial"),
Path.Combine("StrawberryShake", "Client"),
Path.Combine("StrawberryShake", "CodeGeneration")
};

public static IEnumerable<string> GetAllProjects(string sourceDirectory)
Expand Down
5 changes: 0 additions & 5 deletions .devbots/lock-issue.yml

This file was deleted.

Loading

0 comments on commit 712d3bd

Please sign in to comment.