Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point smoke-test branch back at main #9473

Merged
merged 40 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8e1762c
Move to central package management
JoeRobich Mar 5, 2024
bbb5305
Bring GlobalJsonUpdater into alignment with DotNetToolsJsonUpdater
JoeRobich Mar 8, 2024
39dae40
Enable implicit usings
JoeRobich Mar 12, 2024
2c805e7
Add some test helpers
JoeRobich Mar 12, 2024
2fa3d70
Add NuGetUpdater Discover command
JoeRobich Mar 12, 2024
762b8ed
Return additional information about properties and evaluted dependenc…
JoeRobich Mar 12, 2024
6f9e89c
Support Discovery from a directory path
JoeRobich Mar 13, 2024
07c04a5
Allow discovery output path to be specified.
JoeRobich Mar 14, 2024
3871719
Use the discovery results in the updater
JoeRobich Mar 14, 2024
962f70c
Fix typo
JoeRobich Mar 14, 2024
7c56580
PR Feedback
JoeRobich Mar 14, 2024
738d211
Returns paths which are relative to the target folder.
JoeRobich Mar 15, 2024
c015e39
Include transitive packages from all TFMs
JoeRobich Mar 15, 2024
010c4c1
Fixup remaining .NET tests
JoeRobich Mar 18, 2024
9960749
Parse MSBuild SDKs, Restore MSBuild SDKs, Read Properties from all bu…
JoeRobich Mar 23, 2024
d9c904a
Updated ruby side. Made progress on tests.
JoeRobich Mar 23, 2024
cc2ace0
Fix up remaining tests
JoeRobich Mar 23, 2024
b154de9
Merge remote-tracking branch 'origin/main' into jorobich/NativeFilePa…
JoeRobich Mar 23, 2024
df9e1fa
Remove test code from discovery_json_reader
JoeRobich Mar 23, 2024
6c48a7f
Fix sorbet type info in compatibility_checker
JoeRobich Mar 23, 2024
172b4fa
Fix filename capitalization
JoeRobich Mar 23, 2024
32c9817
Fix logging test
JoeRobich Mar 24, 2024
972546e
Merge remote-tracking branch 'origin/main' into jorobich/NativeFilePa…
JoeRobich Apr 1, 2024
a3bfea0
Merge remote-tracking branch 'origin/main' into jorobich/NativeFilePa…
JoeRobich Apr 1, 2024
5bd0745
Ensure we are including indirect dependencies from props and targets …
JoeRobich Apr 2, 2024
c550413
Fix up reported requirements in tests
JoeRobich Apr 2, 2024
f45dc78
TEMP: Fetch modified smoke tests
JoeRobich Apr 2, 2024
8604689
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 2, 2024
abd85c7
Fix tests
JoeRobich Apr 2, 2024
e9c24eb
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 3, 2024
f101f87
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 4, 2024
db238b4
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 5, 2024
73b3bb2
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 5, 2024
9341ab9
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 9, 2024
07ce69d
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 9, 2024
61b87d1
Merge branch 'main' into jorobich/NativeFileParser
Nishnha Apr 9, 2024
654bbb7
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 9, 2024
6beb821
Merge branch 'main' into jorobich/NativeFileParser
JoeRobich Apr 10, 2024
05992c0
point smoke-test branch back at main
Nishnha Apr 10, 2024
d0d42db
Merge branch 'main' into nishnha/fix-smoke-test-yml
Nishnha Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Return additional information about properties and evaluted dependenc…
…y versions
  • Loading branch information
JoeRobich committed Mar 15, 2024
commit 762b8ed5398cc164d4c47cf7c0dce5eda11f44e6
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ await RunAsync(path =>
Dependencies = [
new("Newtonsoft.Json", "7.0.1", DependencyType.PackageConfig)
],
Properties = new Dictionary<string, string>()
Properties = new Dictionary<string, Property>()
{
["TargetFrameworkVersion"] = "v4.5",
["TargetFrameworkVersion"] = new("TargetFrameworkVersion", "v4.5", "path/to/my.csproj"),
}.ToImmutableDictionary()
}
]
Expand Down Expand Up @@ -153,9 +153,9 @@ await RunAsync(path =>
Dependencies = [
new("Newtonsoft.Json", "7.0.1", DependencyType.PackageConfig)
],
Properties = new Dictionary<string, string>()
Properties = new Dictionary<string, Property>()
{
["TargetFrameworkVersion"] = "v4.5",
["TargetFrameworkVersion"] = new("TargetFrameworkVersion", "v4.5", "path/to/my.csproj"),
}.ToImmutableDictionary()
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ void ValidateDependencies(ImmutableArray<Dependency> expectedDependencies, Immut
foreach (var expectedDependency in expectedDependencies)
{
var actualDependency = actualDependencies.Single(d => d.Name == expectedDependency.Name);
Assert.Equal(expectedDependency, actualDependency);
Assert.Equal(expectedDependency.Name, actualDependency.Name);
Assert.Equal(expectedDependency.Version, actualDependency.Version);
Assert.Equal(expectedDependency.Type, actualDependency.Type);
Assert.Equal(expectedDependency.IsDirect, actualDependency.IsDirect);
Assert.Equal(expectedDependency.IsTransitive, actualDependency.IsTransitive);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ await TestDiscovery(
Dependencies = [
new("Newtonsoft.Json", "9.0.1", DependencyType.PackageReference, IsDirect: true)
],
Properties = new Dictionary<string, string>()
Properties = new Dictionary<string, Property>()
{
["NewtonsoftJsonPackageVersion"] = "9.0.1",
["TargetFramework"] = "netstandard2.0",
["NewtonsoftJsonPackageVersion"] = new("NewtonsoftJsonPackageVersion", "9.0.1", projectPath),
["TargetFramework"] = new("TargetFramework", "netstandard2.0", projectPath),
}.ToImmutableDictionary()
}
]
Expand Down Expand Up @@ -104,9 +104,9 @@ await TestDiscovery(
Dependencies = [
new("Newtonsoft.Json", "7.0.1", DependencyType.PackageConfig)
],
Properties = new Dictionary<string, string>()
Properties = new Dictionary<string, Property>()
{
["TargetFrameworkVersion"] = "v4.5",
["TargetFrameworkVersion"] = new("TargetFrameworkVersion", "v4.5", projectPath),
}.ToImmutableDictionary()
}
]
Expand Down Expand Up @@ -162,11 +162,11 @@ await TestDiscovery(
Dependencies = [
new("Newtonsoft.Json", "9.0.1", DependencyType.PackageReference, IsDirect: true)
],
Properties = new Dictionary<string, string>()
Properties = new Dictionary<string, Property>()
{
["ManagePackageVersionsCentrally"] = "true",
["NewtonsoftJsonPackageVersion"] = "9.0.1",
["TargetFramework"] = "netstandard2.0",
["ManagePackageVersionsCentrally"] = new("ManagePackageVersionsCentrally", "true", "Directory.Packages.props"),
["NewtonsoftJsonPackageVersion"] = new("NewtonsoftJsonPackageVersion", "9.0.1", "Directory.Packages.props"),
["TargetFramework"] = new("TargetFramework", "netstandard2.0", projectPath),
}.ToImmutableDictionary()
}
],
Expand Down Expand Up @@ -284,11 +284,11 @@ await TestDiscovery(
Dependencies = [
new("Newtonsoft.Json", "9.0.1", DependencyType.PackageReference, IsDirect: true)
],
Properties = new Dictionary<string, string>()
Properties = new Dictionary<string, Property>()
{
["ManagePackageVersionsCentrally"] = "true",
["NewtonsoftJsonPackageVersion"] = "9.0.1",
["TargetFramework"] = "netstandard2.0",
["ManagePackageVersionsCentrally"] = new("ManagePackageVersionsCentrally", "true", "Directory.Packages.props"),
["NewtonsoftJsonPackageVersion"] = new("NewtonsoftJsonPackageVersion", "9.0.1", "Directory.Packages.props"),
["TargetFramework"] = new("TargetFramework", "netstandard2.0", "src/project.csproj"),
}.ToImmutableDictionary()
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public record ExpectedWorkspaceDiscoveryResult : IDiscoveryResult
public record ExpectedSdkProjectDiscoveryResult : IDiscoveryResultWithDependencies
{
public required string FilePath { get; init; }
public required ImmutableDictionary<string, string> Properties { get; init; }
public required ImmutableDictionary<string, Property> Properties { get; init; }
public ImmutableArray<string> TargetFrameworks { get; init; }
public ImmutableArray<string> ReferencedProjectPaths { get; init; }
public ImmutableArray<Dependency> Dependencies { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void PackagesConfig_GetDependencies_ReturnsDependencies()
var expectedDependencies = new List<Dependency>
{
new("Microsoft.CodeDom.Providers.DotNetCompilerPlatform", "1.0.0", DependencyType.PackageConfig),
new("Microsoft.Net.Compilers", "1.0.0", DependencyType.PackageConfig, true),
new("Microsoft.Net.Compilers", "1.0.0", DependencyType.PackageConfig, IsDevDependency: true),
new("Newtonsoft.Json", "8.0.3", DependencyType.PackageConfig)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace NuGetUpdater.Core.Test.Utilities;

using TestFile = (string Path, string Content);

public class MSBuildHelperTests
{
public MSBuildHelperTests()
Expand All @@ -25,15 +27,15 @@ public void GetRootedValue_FindsValue()
</ItemGroup>
</Project>
""";
var propertyInfo = new Dictionary<string, string>
var propertyInfo = new Dictionary<string, Property>
{
{ "PackageVersion1", "1.1.1" },
{ "PackageVersion1", new("PackageVersion1", "1.1.1", "Packages.props") },
};

// Act
var (resultType, evaluatedValue, _) = MSBuildHelper.GetEvaluatedValue(projectContents, propertyInfo);
var (resultType, _, evaluatedValue, _, _, _) = MSBuildHelper.GetEvaluatedValue(projectContents, propertyInfo);

Assert.Equal(MSBuildHelper.EvaluationResultType.Success, resultType);
Assert.Equal(EvaluationResultType.Success, resultType);

// Assert
Assert.Equal("""
Expand Down Expand Up @@ -62,19 +64,19 @@ public async Task GetRootedValue_DoesNotRecurseAsync()
</ItemGroup>
</Project>
""";
var propertyInfo = new Dictionary<string, string>
var propertyInfo = new Dictionary<string, Property>
{
{ "PackageVersion1", "$(PackageVersion2)" },
{ "PackageVersion2", "$(PackageVersion1)" }
{ "PackageVersion1", new("PackageVersion1", "$(PackageVersion2)", "Packages.props") },
{ "PackageVersion2", new("PackageVersion2", "$(PackageVersion1)", "Packages.props") }
};
// This is needed to make the timeout work. Without that we could get caugth in an infinite loop.
await Task.Delay(1);

// Act
var (resultType, _, errorMessage) = MSBuildHelper.GetEvaluatedValue(projectContents, propertyInfo);
var (resultType, _, _, _, _, errorMessage) = MSBuildHelper.GetEvaluatedValue(projectContents, propertyInfo);

// Assert
Assert.Equal(MSBuildHelper.EvaluationResultType.CircularReference, resultType);
Assert.Equal(EvaluationResultType.CircularReference, resultType);
Assert.Equal("Property 'PackageVersion1' has a circular reference.", errorMessage);
}

Expand Down Expand Up @@ -127,7 +129,7 @@ public void TfmsCanBeDeterminedFromProjectContents(string projectContents, strin

[Theory]
[MemberData(nameof(GetTopLevelPackageDependencyInfosTestData))]
public async Task TopLevelPackageDependenciesCanBeDetermined((string Path, string Content)[] buildFileContents, Dependency[] expectedTopLevelDependencies)
public async Task TopLevelPackageDependenciesCanBeDetermined(TestFile[] buildFileContents, Dependency[] expectedTopLevelDependencies)
{
using var testDirectory = new TemporaryDirectory();
var buildFiles = new List<ProjectBuildFile>();
Expand Down Expand Up @@ -510,7 +512,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
EvaluationResult: new(EvaluationResultType.Success, "12.0.1", "12.0.1", null, null, null))
}
];

Expand All @@ -533,7 +539,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
EvaluationResult: new(EvaluationResultType.Success, "12.0.1", "12.0.1", null, null, null))
}
];

Expand All @@ -557,7 +567,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
new(EvaluationResultType.Success, "$(NewtonsoftJsonVersion)", "12.0.1", "NewtonsoftJsonVersion", "NewtonsoftJsonVersion", null))
}
];

Expand All @@ -583,7 +597,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
new(EvaluationResultType.Success, "$(NewtonsoftJsonVersion)", "12.0.1", "NewtonsoftJsonVersion", "NewtonsoftJsonVersion", null))
}
];

Expand All @@ -609,7 +627,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
new(EvaluationResultType.Success, "$(NewtonsoftJsonVersion)", "12.0.1", "NewtonsoftJsonVersion", "NewtonsoftJsonVersion", null))
}
};

Expand All @@ -635,7 +657,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
new(EvaluationResultType.Success, "$(NewtonsoftJsonVersion)", "12.0.1", "NewtonsoftJsonVersion", "NewtonsoftJsonVersion", null))
}
];

Expand All @@ -661,7 +687,11 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
new(
"Newtonsoft.Json",
"12.0.1",
DependencyType.Unknown,
new(EvaluationResultType.Success, "$(NewtonsoftJsonVersion)", "12.0.1", "NewtonsoftJsonVersion", "NewtonsoftJsonVersion", null))
}
};

Expand Down Expand Up @@ -693,8 +723,17 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Azure.Identity", "1.6.0", DependencyType.Unknown),
new("Microsoft.Data.SqlClient", "5.1.4", DependencyType.Unknown, IsUpdate: true)
new(
"Azure.Identity",
"1.6.0",
DependencyType.Unknown,
EvaluationResult: new(EvaluationResultType.Success, "1.6.0", "1.6.0", null, null, null)),
new(
"Microsoft.Data.SqlClient",
"5.1.4",
DependencyType.Unknown,
EvaluationResult: new(EvaluationResultType.Success, "5.1.4", "5.1.4", null, null, null),
IsUpdate: true),
}
];

Expand Down Expand Up @@ -726,8 +765,17 @@ public static IEnumerable<object[]> GetTopLevelPackageDependencyInfosTestData()
// expected dependencies
new Dependency[]
{
new("Azure.Identity", "1.6.0", DependencyType.Unknown),
new("Microsoft.Data.SqlClient", "5.1.4", DependencyType.Unknown, IsUpdate: true)
new(
"Azure.Identity",
"1.6.0",
DependencyType.Unknown,
EvaluationResult: new(EvaluationResultType.Success, "1.6.0", "1.6.0", null, null, null)),
new(
"Microsoft.Data.SqlClient",
"5.1.4",
DependencyType.Unknown,
EvaluationResult: new(EvaluationResultType.Success, "5.1.4", "5.1.4", null, null, null),
IsUpdate: true),
}
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public sealed record Dependency(
string Name,
string? Version,
DependencyType Type,
EvaluationResult? EvaluationResult = null,
bool IsDevDependency = false,
bool IsDirect = false,
bool IsTransitive = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal static class DirectoryPackagesPropsDiscovery
{
public static DirectoryPackagesPropsDiscoveryResult? Discover(string repoRootPath, string workspacePath, ImmutableArray<ProjectDiscoveryResult> projectResults, Logger logger)
{
var projectResult = projectResults.FirstOrDefault(p => p.Properties.TryGetValue("ManagePackageVersionsCentrally", out var value) && string.Equals(value, "true", StringComparison.OrdinalIgnoreCase));
var projectResult = projectResults.FirstOrDefault(p => p.Properties.TryGetValue("ManagePackageVersionsCentrally", out var property) && string.Equals(property.Value, "true", StringComparison.OrdinalIgnoreCase));
if (projectResult is null)
{
return null;
Expand All @@ -29,7 +29,7 @@ internal static class DirectoryPackagesPropsDiscovery

logger.Log($" Discovered [{directoryPackagesPropsFile.FilePath}] file.");

var isTransitivePinningEnabled = projectResult.Properties.TryGetValue("EnableTransitivePinning", out var value) && string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
var isTransitivePinningEnabled = projectResult.Properties.TryGetValue("EnableTransitivePinning", out var property) && string.Equals(property.Value, "true", StringComparison.OrdinalIgnoreCase);
return new()
{
FilePath = directoryPackagesPropsFile.FilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NuGetUpdater.Core.Discover;
public record ProjectDiscoveryResult : IDiscoveryResultWithDependencies
{
public required string FilePath { get; init; }
public required ImmutableDictionary<string, string> Properties { get; init; }
public required ImmutableDictionary<string, Property> Properties { get; init; }
public ImmutableArray<string> TargetFrameworks { get; init; } = [];
public ImmutableArray<string> ReferencedProjectPaths { get; init; } = [];
public required ImmutableArray<Dependency> Dependencies { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static async Task<ImmutableArray<ProjectDiscoveryResult>> DiscoverAsync(s
results.Add(new()
{
FilePath = buildFile.RepoRelativePath,
Properties = ImmutableDictionary<string, string>.Empty,
Properties = ImmutableDictionary<string, Property>.Empty,
Dependencies = directDependencies,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NuGetUpdater.Core;

public record EvaluationResult(
EvaluationResultType ResultType,
string OriginalValue,
string EvaluatedValue,
string? FirstPropertyName,
string? LastPropertyName,
string? ErrorMessage);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NuGetUpdater.Core;

public enum EvaluationResultType
{
Success,
PropertyIgnored,
CircularReference,
PropertyNotFound,
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public IEnumerable<Dependency> GetDependencies() => Packages
p.GetAttributeValue("id", StringComparison.OrdinalIgnoreCase),
p.GetAttributeValue("version", StringComparison.OrdinalIgnoreCase),
DependencyType.PackageConfig,
(p.GetAttribute("developmentDependency", StringComparison.OrdinalIgnoreCase)?.Value ?? "false").Equals(true.ToString(), StringComparison.OrdinalIgnoreCase)));
IsDevDependency: (p.GetAttribute("developmentDependency", StringComparison.OrdinalIgnoreCase)?.Value ?? "false").Equals(true.ToString(), StringComparison.OrdinalIgnoreCase)));
}
6 changes: 6 additions & 0 deletions nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Property.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace NuGetUpdater.Core;

public sealed record Property(
string Name,
string Value,
string SourceFilePath);
Loading