diff --git a/Build/Affected.cs b/Build/Affected.cs index d2e680195..b88fc3b2a 100644 --- a/Build/Affected.cs +++ b/Build/Affected.cs @@ -1,3 +1,4 @@ +using GlobExpressions; using Microsoft.Build.Construction; using Semver; using static SimpleExec.Command; @@ -9,6 +10,26 @@ public static class Affected public static readonly string Root = Environment.CurrentDirectory; public const string AFFECTED_PROJECT = "affected.proj"; + private static IEnumerable GetAffectedProjects() + { + var projFile = Path.Combine(Root, AFFECTED_PROJECT); + Console.WriteLine("Affected project file: " + projFile); + var project = ProjectRootElement.Open(projFile) ?? throw new InvalidOperationException(); + var references = project.ItemGroups.SelectMany(x => x.Items).Where(x => x.ItemType == "ProjectReference"); + + foreach (var refe in references) + { + var referencePath = refe.Include[(Root.Length + 1)..]; + referencePath = Path.GetDirectoryName(referencePath) ?? throw new InvalidOperationException(); + if (Path.DirectorySeparatorChar != '/') + { + referencePath = referencePath.Replace(Path.DirectorySeparatorChar, '/'); + } + + yield return referencePath; + } + } + public static async Task GetSolutions() { await ComputeAffected(); @@ -23,37 +44,37 @@ public static class Affected return Consts.Solutions; } + public static async Task> GetProjects() + { + await ComputeAffected(); + var projFile = Path.Combine(Root, AFFECTED_PROJECT); + if (File.Exists(projFile)) + { + var references = GetAffectedProjects(); + return references.Where(x => x.EndsWith(".Tests.csproj")); + } + return Glob.Files(Root, "**/*.Tests.csproj"); + } + public static async Task GetInstallerProjects() { await ComputeAffected(); var projFile = Path.Combine(Root, AFFECTED_PROJECT); if (File.Exists(projFile)) { - Console.WriteLine("Affected project file: " + projFile); - var project = ProjectRootElement.Open(projFile) ?? throw new InvalidOperationException(); - var references = project - .ItemGroups.SelectMany(x => x.Items) - .Where(x => x.ItemType == "ProjectReference") - .ToList(); + var references = GetAffectedProjects().ToList(); var projs = new List(); - foreach (var refe in references) + foreach (var referencePath in references) { - Console.WriteLine($"Candidate project: {refe.Include}"); + Console.WriteLine($"Candidate project: {referencePath}"); } foreach (var manifest in Consts.InstallerManifests) { var assets = new List(); - foreach (var refe in references) + foreach (var referencePath in references) { - var referencePath = refe.Include[(Root.Length + 1)..]; - referencePath = Path.GetDirectoryName(referencePath) ?? throw new InvalidOperationException(); - if (Path.DirectorySeparatorChar != '/') - { - referencePath = referencePath.Replace(Path.DirectorySeparatorChar, '/'); - } - foreach (var proj in manifest.Projects) { if (proj.ProjectPath.Contains(referencePath)) @@ -84,16 +105,18 @@ public static class Affected return Consts.InstallerManifests; } + private static bool s_affectedComputed; + public static async Task ComputeAffected() { - var projFile = Path.Combine(Root, AFFECTED_PROJECT); - if (File.Exists(projFile)) + if (s_affectedComputed) { return; } + var (currentTag, _) = await ReadAsync("git", "describe --tags"); currentTag = currentTag.Trim(); - var version = await Affected.ComputeVersion(); + var version = await Versions.ComputeVersion(); var currentVersion = SemVersion.Parse(version).WithoutPrereleaseOrMetadata(); var (lastTag, _) = await ReadAsync("git", $"describe --abbrev=0 --tags {currentTag}^"); lastTag = lastTag.Trim(); @@ -101,8 +124,10 @@ public static class Affected if (!SemVersion.TryParse(lastTag, SemVersionStyles.AllowLowerV, out var lastVersion)) { Console.WriteLine($"Could not parse version: '{lastTag}'"); + s_affectedComputed = true; return; } + Console.WriteLine($"Last tag: {lastTag}, Current tag: {currentTag}"); lastVersion = lastVersion.WithoutPrereleaseOrMetadata(); @@ -113,11 +138,14 @@ public static class Affected if (sort == 0) { Console.WriteLine($"Current version {currentVersion} is equal to: {lastVersion}"); + s_affectedComputed = true; return; } + if (sort != 1) { Console.WriteLine($"Current version {currentVersion} is not greater than: {lastVersion}"); + s_affectedComputed = true; return; } @@ -126,6 +154,7 @@ public static class Affected if (!majorEquals) { Console.WriteLine($"Current version {currentVersion} is not matching major version: {lastVersion}"); + s_affectedComputed = true; return; } @@ -135,38 +164,7 @@ public static class Affected var (lastCommit, _) = await ReadAsync("git", $"rev-list -n 1 {lastTag.Trim()}"); await RunAsync("dotnet", $"affected --from {currentCommit.Trim()} --to {lastCommit.Trim()}", Root); } - } - private static string? s_currentVersion; - - public static async Task ComputeVersion() - { - if (s_currentVersion is not null) - { - return s_currentVersion; - } - var (currentTag, _) = await ReadAsync("git", "describe --tags"); - currentTag = currentTag.Trim(); - - if (!SemVersion.TryParse(currentTag, SemVersionStyles.AllowLowerV, out var currentVersion)) - { - throw new InvalidOperationException($"Could not parse version: '{currentTag}'"); - } - s_currentVersion = currentVersion.ToString(); - return s_currentVersion; - } - - private static string? s_currentFileVersion; - - public static async Task ComputeFileVersion() - { - if (s_currentFileVersion is not null) - { - return s_currentFileVersion; - } - var version = await Affected.ComputeVersion(); - var currentVersion = SemVersion.Parse(version).WithoutPrereleaseOrMetadata(); - s_currentFileVersion = currentVersion.ToString() + ".0"; - return s_currentFileVersion; + s_affectedComputed = true; } } diff --git a/Build/Program.cs b/Build/Program.cs index 5714123b9..1485f6039 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -145,8 +145,8 @@ Target( DependsOn(FORMAT), async () => { - var version = await Affected.ComputeVersion(); - var fileVersion = await Affected.ComputeFileVersion(); + var version = await Versions.ComputeVersion(); + var fileVersion = await Versions.ComputeFileVersion(); foreach (var s in await Affected.GetSolutions()) { Console.WriteLine($"Restoring: {s} - Version: {version} & {fileVersion}"); @@ -160,8 +160,8 @@ Target( DependsOn(RESTORE), async () => { - var version = await Affected.ComputeVersion(); - var fileVersion = await Affected.ComputeFileVersion(); + var version = await Versions.ComputeVersion(); + var fileVersion = await Versions.ComputeFileVersion(); foreach (var s in await Affected.GetSolutions()) { Console.WriteLine($"Restoring: {s} - Version: {version} & {fileVersion}"); @@ -178,13 +178,16 @@ Target(CHECK_SOLUTIONS, Solutions.CompareConnectorsToLocal); Target( TEST, DependsOn(BUILD, CHECK_SOLUTIONS), - Glob.Files(".", "**/*.Tests.csproj"), - file => + async () => { - Run("dotnet", $"test {file} -c Release --no-build --no-restore --verbosity=minimal"); + foreach (var file in await Affected.GetProjects()) + { + await RunAsync("dotnet", $"test {file} -c Release --no-build --no-restore --verbosity=minimal"); + } } ); +//all tests on purpose Target( TEST_ONLY, DependsOn(FORMAT), @@ -206,8 +209,8 @@ Target( async file => { await RunAsync("dotnet", $"restore {file} --locked-mode"); - var version = await Affected.ComputeVersion(); - var fileVersion = await Affected.ComputeFileVersion(); + var version = await Versions.ComputeVersion(); + var fileVersion = await Versions.ComputeFileVersion(); Console.WriteLine($"Version: {version} & {fileVersion}"); await RunAsync( "dotnet", @@ -226,8 +229,7 @@ Target( DependsOn(TEST), async () => { - await Affected.ComputeAffected(); - var version = await Affected.ComputeVersion(); + var version = await Versions.ComputeVersion(); foreach (var x in await Affected.GetInstallerProjects()) { Console.WriteLine($"Zipping: {x} as {version}"); diff --git a/Build/Versions.cs b/Build/Versions.cs new file mode 100644 index 000000000..2e377952c --- /dev/null +++ b/Build/Versions.cs @@ -0,0 +1,40 @@ +using Semver; +using static SimpleExec.Command; + +namespace Build; + +public static class Versions +{ + private static string? s_currentVersion; + + public static async Task ComputeVersion() + { + if (s_currentVersion is not null) + { + return s_currentVersion; + } + var (currentTag, _) = await ReadAsync("git", "describe --tags"); + currentTag = currentTag.Trim(); + + if (!SemVersion.TryParse(currentTag, SemVersionStyles.AllowLowerV, out var currentVersion)) + { + throw new InvalidOperationException($"Could not parse version: '{currentTag}'"); + } + s_currentVersion = currentVersion.ToString(); + return s_currentVersion; + } + + private static string? s_currentFileVersion; + + public static async Task ComputeFileVersion() + { + if (s_currentFileVersion is not null) + { + return s_currentFileVersion; + } + var version = await ComputeVersion(); + var currentVersion = SemVersion.Parse(version).WithoutPrereleaseOrMetadata(); + s_currentFileVersion = currentVersion.ToString() + ".0"; + return s_currentFileVersion; + } +} diff --git a/Sdk/Speckle.Connectors.Common.Tests/CancellationManagerTests.cs b/Sdk/Speckle.Connectors.Common.Tests/CancellationManagerTests.cs index 06aa34bd1..5c5201960 100644 --- a/Sdk/Speckle.Connectors.Common.Tests/CancellationManagerTests.cs +++ b/Sdk/Speckle.Connectors.Common.Tests/CancellationManagerTests.cs @@ -7,7 +7,7 @@ namespace Speckle.Connectors.Common.Tests; public class CancellationManagerTests { [Test] - public void CancelOne() + public void CancelOne2() { var manager = new CancellationManager(); manager.NumberOfOperations.Should().Be(0);