Skip to content

C#: Check fallback nuget feeds before trying to use them in the fallb… #16164

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

Merged

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Apr 9, 2024

…ack restore process

This PR is improving the fallback nuget restore process by checking if the used nuget feeds are reachable or not. Currently the fallback restore process doesn't use a nuget.config file. This PR is changing this. The generated nuget.config uses the reachable fallback feeds in the <packageSources>. Additionally, we're logging the nuget feeds that are inherited from the user level nuget.config, but we're not (yet) checking their reachability.

@github-actions github-actions bot added the C# label Apr 9, 2024
Comment on lines +598 to +616
catch (Exception exc)
{
logger.LogWarning($"Failed to get directory of '{config}': {exc}");
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
@@ -32,6 +33,12 @@
return Success;
}

public bool RunCommand(string args, string? workingDirectory, out IList<string> output)

Check notice

Code scanning / CodeQL

Local scope variable shadows member

Local scope variable 'output' shadows [DotNetCliInvokerStub.output](1).
@tamasvajk
Copy link
Contributor Author

Ahh, the test failure is due to the way we test for timeouts:

[build-stdout] [001] Warning: Didn't receive answer from Nuget feed 'https://api.nuget.org/v3/index.json' in 1ms.
[build-stdout] [001] Warning: Didn't receive answer from Nuget feed 'https://api.nuget.org/v3/index.json'. Tried it 1 times.

@tamasvajk tamasvajk marked this pull request as ready for review April 10, 2024 11:04
@tamasvajk tamasvajk requested a review from a team as a code owner April 10, 2024 11:04
@michaelnebel michaelnebel self-requested a review April 11, 2024 08:04
}
}

private HashSet<string> GetAllFeeds(List<FileInfo> allFiles)
private (HashSet<string>, HashSet<string>) GetAllFeeds(List<FileInfo> allFiles)
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though this method is private, maybe add some description of the return since it is a tuple of hashsets of the same type (to avoid confusing them)

return feeds;

// todo: this could be improved.
// We don't have to get the feeds from each of the folders from below, it would be enought to check the folders that recursively contain the others.
Copy link
Contributor

Choose a reason for hiding this comment

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

So you are thinking of removing all folder paths that are prefixes of other path before calling the CLI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would be an option. (But I won't do it for the time being, as it would add extra complexity)

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

LGTM. Added some minor questions and comments.

@tamasvajk tamasvajk force-pushed the buildless/nuget-feed-fallback-feed-check branch from 1fdabcb to c004f92 Compare April 11, 2024 12:47
@tamasvajk
Copy link
Contributor Author

@michaelnebel I've applied your suggestions and rebased the PR.

logger.LogInfo($"Getting Nuget feeds from '{nugetConfig}'...");
return dotnet.GetNugetFeeds(nugetConfig);
}
IList<string> GetNugetFeeds(string nugetConfig) => dotnet.GetNugetFeeds(nugetConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just call dotnet.GetNugetFeeds directly instead of declaring a local function (same comment below).

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Great work @tamasvajk !

@michaelnebel
Copy link
Contributor

I just saw the comment https://github.com/github/codeql-csharp-team/issues/432#issuecomment-2051098433
Do we need a follow up PR which reads the disabled package sources and only does nuget.org fallback in case it is not mentioned as a disabled package source?

@tamasvajk
Copy link
Contributor Author

I just saw the comment github/codeql-csharp-team#432 (comment) Do we need a follow up PR which reads the disabled package sources and only does nuget.org fallback in case it is not mentioned as a disabled package source?

There are definitely ways to improve this. Let's get some feedback from the field team before tackling it.

@tamasvajk tamasvajk merged commit 91f2ea5 into github:main Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants