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

move nuget update analysis to native code #10025

Merged
merged 17 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ concurrency:

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SMOKE_TEST_BRANCH: main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! Making life simple down the road.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to re-figure this out too many times.

jobs:
discover:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -44,7 +45,7 @@ jobs:
cat filtered.json

# Curl the smoke-test tests directory to get a list of tests to run
URL=https://api.github.com/repos/dependabot/smoke-tests/contents/tests
URL=https://api.github.com/repos/dependabot/smoke-tests/contents/tests?ref=${{ env.SMOKE_TEST_BRANCH }}
curl $URL > tests.json

# Select the names that match smoke-$test*.yaml, where $test is the .text value from filtered.json
Expand Down Expand Up @@ -84,7 +85,7 @@ jobs:
- name: Download test
if: steps.cache-smoke-test.outputs.cache-hit != 'true'
run: |
URL=https://api.github.com/repos/dependabot/smoke-tests/contents/tests/${{ matrix.suite.name }}
URL=https://api.github.com/repos/dependabot/smoke-tests/contents/tests/${{ matrix.suite.name }}?ref=${{ env.SMOKE_TEST_BRANCH }}
curl $(gh api $URL --jq .download_url) -o smoke.yaml

- name: Cache Smoke Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using System.Text;
using System.Xml.Linq;

using NuGetUpdater.Core;
using NuGetUpdater.Core.Analyze;
using NuGetUpdater.Core.Test;
using NuGetUpdater.Core.Test.Analyze;
using NuGetUpdater.Core.Test.Update;

using Xunit;

namespace NuGetUpdater.Cli.Test;

using TestFile = (string Path, string Content);

public partial class EntryPointTests
{
public class Analyze : AnalyzeWorkerTestBase
{
[Fact]
public async Task FindsUpdatedPackageAndReturnsTheCorrectData()
{
var repositoryXml = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some.package" />""");
await RunAsync(path =>
[
"analyze",
"--repo-root",
path,
"--discovery-file-path",
Path.Join(path, "discovery.json"),
"--dependency-file-path",
Path.Join(path, "Some.Package.json"),
"--analysis-folder-path",
Path.Join(path, AnalyzeWorker.AnalysisDirectoryName),
"--verbose",
],
packages: [
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repositoryXml]),
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repositoryXml]),
],
dependencyName: "Some.Package",
initialFiles:
[
("discovery.json", """
{
"Path": "",
"IsSuccess": true,
"Projects": [
{
"FilePath": "project.csproj",
"Dependencies": [
{
"Name": "Microsoft.NET.Sdk",
"Version": null,
"Type": "MSBuildSdk",
"EvaluationResult": null,
"TargetFrameworks": null,
"IsDevDependency": false,
"IsDirect": false,
"IsTransitive": false,
"IsOverride": false,
"IsUpdate": false
},
{
"Name": "Some.Package",
"Version": "1.0.0",
"Type": "PackageReference",
"EvaluationResult": {
"ResultType": "Success",
"OriginalValue": "1.0.0",
"EvaluatedValue": "1.0.0",
"RootPropertyName": null,
"ErrorMessage": null
},
"TargetFrameworks": [
"net8.0"
],
"IsDevDependency": false,
"IsDirect": true,
"IsTransitive": false,
"IsOverride": false,
"IsUpdate": false
}
],
"IsSuccess": true,
"Properties": [
{
"Name": "TargetFramework",
"Value": "net8.0",
"SourceFilePath": "project.csproj"
}
],
"TargetFrameworks": [
"net8.0"
],
"ReferencedProjectPaths": []
}
],
"DirectoryPackagesProps": null,
"GlobalJson": null,
"DotNetToolsJson": null
}
"""),
("Some.Package.json", """
{
"Name": "Some.Package",
"Version": "1.0.0",
"IsVulnerable": false,
"IgnoredVersions": [],
"Vulnerabilities": []
}
"""),
("project.csproj", """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="1.0.0" />
</ItemGroup>
</Project>
"""),
],
expectedResult: new()
{
UpdatedVersion = "1.0.1",
CanUpdate = true,
VersionComesFromMultiDependencyProperty = false,
UpdatedDependencies =
[
new Dependency("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some.package")
],
}
);
}

private static async Task RunAsync(Func<string, string[]> getArgs, string dependencyName, TestFile[] initialFiles, ExpectedAnalysisResult expectedResult, MockNuGetPackage[]? packages = null)
{
var actualResult = await RunAnalyzerAsync(dependencyName, initialFiles, async path =>
{
var sb = new StringBuilder();
var writer = new StringWriter(sb);

var originalOut = Console.Out;
var originalErr = Console.Error;
Console.SetOut(writer);
Console.SetError(writer);

try
{
await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, path);
var args = getArgs(path);
var result = await Program.Main(args);
if (result != 0)
{
throw new Exception($"Program exited with code {result}.\nOutput:\n\n{sb}");
}
}
finally
{
Console.SetOut(originalOut);
Console.SetError(originalErr);
}
});

ValidateAnalysisResult(expectedResult, actualResult);
}
}
}
Loading
Loading