Skip to content

Commit

Permalink
Updated build project to net80 and new nugets
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Jan 22, 2024
1 parent ab695ac commit 613627e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 36 deletions.
58 changes: 32 additions & 26 deletions tools/build/BuildDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace build
{
public static class BuildDefinition
{
public static GitVersion ResolveVersion(Options options, PreviousReleases releases)
public static async Task<GitVersion> ResolveVersion(Options options, PreviousReleases releases)
{
GitVersion version;
if (ForcedVersion != null)
Expand All @@ -36,9 +36,10 @@ public static GitVersion ResolveVersion(Options options, PreviousReleases releas
string versionJson;
try
{
versionJson = Read("dotnet", $"gitversion /nofetch{(options.Verbose ? " /diag" : "")}", BasePath);
var result = await ReadAsync("dotnet", $"gitversion /nofetch{(options.Verbose ? " /diag" : "")}", BasePath);
versionJson = result.StandardOutput;
}
catch (NonZeroExitCodeException)
catch (ExitCodeException)
{
Run("dotnet", "gitversion /nofetch /diag", BasePath);
throw;
Expand Down Expand Up @@ -90,7 +91,7 @@ public static GitVersion ResolveVersion(Options options, PreviousReleases releas
return version;
}

public static void SetBuildVersion(Options options, GitVersion version)
public static Task SetBuildVersion(Options options, GitVersion version)
{
switch (options.Host)
{
Expand All @@ -99,9 +100,11 @@ public static void SetBuildVersion(Options options, GitVersion version)
Run("appveyor", $"UpdateBuild -Version {version.NuGetVersion}.{buildNumber}");
break;
}

return Task.CompletedTask;
}

public static MetadataSet SetMetadata(GitVersion version)
public static Task<MetadataSet> SetMetadata(GitVersion version)
{
var templatePath = Path.Combine(BasePath, "YamlDotNet", "Properties", "AssemblyInfo.template");
WriteVerbose($"Using template {templatePath}");
Expand All @@ -116,26 +119,26 @@ public static MetadataSet SetMetadata(GitVersion version)
WriteVerbose($"Writing metadata to {asssemblyInfoPath}");
File.WriteAllText(asssemblyInfoPath, assemblyInfo);

return default;
return Task.FromResult(new MetadataSet());
}

public static SuccessfulBuild Build(Options options, MetadataSet _)
public static Task<SuccessfulBuild> Build(Options options, MetadataSet _)
{
var verbosity = options.Verbose ? "detailed" : "minimal";
Run("dotnet", $"build YamlDotNet.sln --configuration Release --verbosity {verbosity}", BasePath);

return default;
return Task.FromResult(new SuccessfulBuild());
}

public static SuccessfulUnitTests UnitTest(Options options, SuccessfulBuild _)
public static Task<SuccessfulUnitTests> UnitTest(Options options, SuccessfulBuild _)
{
var verbosity = options.Verbose ? "detailed" : "minimal";
Run("dotnet", $"test YamlDotNet.Test.csproj --no-build --configuration Release --verbosity {verbosity}", Path.Combine(BasePath, "YamlDotNet.Test"));

return default;
return Task.FromResult(new SuccessfulUnitTests());
}

public static List<NuGetPackage> Pack(Options options, GitVersion version, SuccessfulUnitTests _)
public static Task<List<NuGetPackage>> Pack(Options options, GitVersion version, SuccessfulUnitTests _)
{
var result = new List<NuGetPackage>();
var verbosity = options.Verbose ? "detailed" : "minimal";
Expand All @@ -152,10 +155,10 @@ public static List<NuGetPackage> Pack(Options options, GitVersion version, Succe
result.Add(new NuGetPackage(packagePath, "YamlDotNet.Analyzers.StaticGenerator"));
}

return result;
return Task.FromResult(result);
}

public static void Publish(Options options, GitVersion version, List<NuGetPackage> packages)
public static Task Publish(Options options, GitVersion version, List<NuGetPackage> packages)
{
var apiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY");
if (string.IsNullOrEmpty(apiKey))
Expand Down Expand Up @@ -187,6 +190,8 @@ public static void Publish(Options options, GitVersion version, List<NuGetPackag
}
}
}

return Task.CompletedTask;
}

public static async Task TweetRelease(GitVersion version)
Expand All @@ -209,7 +214,7 @@ public static async Task TweetRelease(GitVersion version)
WriteVerbose(result);
}

public static ScaffoldedRelease ScaffoldReleaseNotes(GitVersion version, PreviousReleases releases)
public static async Task<ScaffoldedRelease> ScaffoldReleaseNotes(GitVersion version, PreviousReleases releases)
{
if (version.IsPreRelease)
{
Expand All @@ -220,7 +225,7 @@ public static ScaffoldedRelease ScaffoldReleaseNotes(GitVersion version, Previou

// Get the git log to scaffold the release notes
string? currentHash = null;
var commits = ReadLines("git", $"rev-list v{previousVersion}..HEAD --first-parent --reverse --pretty=tformat:%B")
var commits = (await ReadLines("git", $"rev-list v{previousVersion}..HEAD --first-parent --reverse --pretty=tformat:%B"))
.Select(l =>
{
var match = Regex.Match(l, "^commit (?<hash>[a-f0-9]+)$");
Expand Down Expand Up @@ -304,10 +309,10 @@ public static async Task LinkPullRequestsToReleases(GitVersion version)
}
}

public static PreviousReleases DiscoverPreviousReleases()
public static async Task<PreviousReleases> DiscoverPreviousReleases()
{
// Find previous release
var releases = ReadLines("git", "tag --list --merged origin/master --format=\"%(refname:short)\" v*")
var releases = (await ReadLines("git", "tag --list --merged origin/master --format=\"%(refname:short)\" v*"))
.Select(tag => Regex.Match(tag.TrimEnd('\r'), @"^v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$"))
.Where(m => m.Success)
.Select(match => new Version(
Expand All @@ -325,7 +330,7 @@ public static PreviousReleases DiscoverPreviousReleases()
return previousReleases;
}

public static void Document(Options options)
public static Task Document(Options options)
{
var samplesProjectDir = Path.Combine(BasePath, "YamlDotNet.Samples");
var samplesOutputDir = Path.Combine(BasePath, "..", "YamlDotNet.wiki");
Expand All @@ -338,16 +343,16 @@ public static void Document(Options options)
const string ns = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010";

var testDefinitions = report.Root
.Element(XName.Get("TestDefinitions", ns))
.Element(XName.Get("TestDefinitions", ns))!
.Elements(XName.Get("UnitTest", ns))
.Select(e =>
{
var testMethod = e.Element(XName.Get("TestMethod", ns));
var sampleClassName = testMethod.Attribute("className").Value;
var sampleMethodName = testMethod.Attribute("name").Value;
var sampleClassName = testMethod.Attribute("className")!.Value;
var sampleMethodName = testMethod.Attribute("name")!.Value;
var testMethodAssembly = Assembly.LoadFrom(testMethod.Attribute("codeBase").Value);
var testMethodAssembly = Assembly.LoadFrom(testMethod.Attribute("codeBase")!.Value);
var sampleClass = testMethodAssembly
.GetType(sampleClassName, true)!;
Expand All @@ -364,20 +369,20 @@ public static void Document(Options options)
return new
{
Id = e.Attribute("id").Value,
Name = e.Attribute("name").Value,
Id = e.Attribute("id")!.Value,
Name = e.Attribute("name")!.Value,
Description = description,
Code = File.ReadAllText(Path.Combine(samplesProjectDir, $"{sampleClass.Name}.cs")),
FileName = $"Samples.{sampleClass.Name}.md",
};
});

var testResults = report.Root
.Element(XName.Get("Results", ns))
.Element(XName.Get("Results", ns))!
.Elements(XName.Get("UnitTestResult", ns))
.Select(e => new
{
TestId = e.Attribute("testId").Value,
TestId = e.Attribute("testId")!.Value,
Output = e
.Element(XName.Get("Output", ns))
?.Element(XName.Get("StdOut", ns))
Expand Down Expand Up @@ -435,6 +440,7 @@ public static void Document(Options options)
* [Building Custom Formatters for .Net Core (Yaml Formatters)](http://www.fiyazhasan.me/building-custom-formatters-for-net-core-yaml-formatters/) by @FiyazBinHasan
");
return Task.CompletedTask;
}

private static string GitHubRepository
Expand Down
26 changes: 19 additions & 7 deletions tools/build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ private static void RegisterTargets()
providerTargets.Add(returnType, targetMethod.Name);
}

var action = Expression.Lambda<Action>(actionExpression);
targets.Add((targetMethod.Name, action.Compile(), dependencies));
try
{
var action = Expression.Lambda<Action>(actionExpression);
targets.Add((targetMethod.Name, action.Compile(), dependencies));
}
catch (Exception exception)
{
Console.WriteLine("Error: " + exception);
Console.WriteLine("TargetMethod: " + targetMethod.Name);
throw;
}
}

foreach (var (name, action, dependencies) in targets)
Expand Down Expand Up @@ -318,11 +327,14 @@ private static void Write(string text, string color)
Console.WriteLine($"{color}{text}{palette.Reset}");
}

public static IEnumerable<string> ReadLines(string name, string? args = null, string? workingDirectory = null) => SimpleExec.Command
.Read(name, args, workingDirectory)
.Split('\n')
.Select(l => l.TrimEnd('\r'));

public static async Task<IEnumerable<string>> ReadLines(string name, string args, string? workingDirectory = null)
{
var read = await SimpleExec.Command.ReadAsync(name, args, workingDirectory ?? string.Empty);
var result = read.StandardOutput
.Split('\n')
.Select(l => l.TrimEnd('\r'));
return result;
}
public static string UnIndent(string text)
{
var lines = text
Expand Down
6 changes: 3 additions & 3 deletions tools/build/build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net80</TargetFramework>
<Platforms>AnyCPU</Platforms>
<Nullable>Enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bullseye" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="SimpleExec" Version="6.4.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="SimpleExec" Version="12.0.0" />
</ItemGroup>

</Project>

0 comments on commit 613627e

Please sign in to comment.