-
Notifications
You must be signed in to change notification settings - Fork 689
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
Add --config-file param to dotnet nuget push command #4819
Conversation
string.Join(" ", args), | ||
true); | ||
|
||
// TODO: The bad config file is ignored, so I need to confirm this is expected behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in chat, it does feel like a bug. My first guess would have been that the config file isn't actually being read, but then I'd expect the next test, PushCommand_ConfigFile_ExpectedFormat
, to fail.
Anyway, this PR clearly didn't introduce that behaviour, so we should create a new issue, and skip this test until that other issue is fixed.
3061517
to
4b2d8b6
Compare
1fd1699
to
ef202fd
Compare
@@ -105,7 +110,9 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger) | |||
} | |||
|
|||
#pragma warning disable CS0618 // Type or member is obsolete | |||
var sourceProvider = new PackageSourceProvider(XPlatUtility.GetSettingsForCurrentWorkingDirectory(), enablePackageSourcesChangedEvent: false); | |||
var sourceProvider = new PackageSourceProvider( | |||
XPlatUtility.ProcessConfigFile(configurationFile.Value()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a validation to ensure file path exists before accessing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does XPlatUtility.ProcessConfigFile
fall back to GetSettingsForCurrentWorkingDirectory
when configurationFile.Value()
is null or empty (was not provided on the command line)?
This code, the way it's written, makes it look like a breaking change and that passing the --config-file
is becoming mandatory. edit: reading the tests, it appears that it does maintain backwards compatibility. It's just not obvious to me.
@@ -105,7 +110,9 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger) | |||
} | |||
|
|||
#pragma warning disable CS0618 // Type or member is obsolete | |||
var sourceProvider = new PackageSourceProvider(XPlatUtility.GetSettingsForCurrentWorkingDirectory(), enablePackageSourcesChangedEvent: false); | |||
var sourceProvider = new PackageSourceProvider( | |||
XPlatUtility.ProcessConfigFile(configurationFile.Value()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does XPlatUtility.ProcessConfigFile
fall back to GetSettingsForCurrentWorkingDirectory
when configurationFile.Value()
is null or empty (was not provided on the command line)?
This code, the way it's written, makes it look like a breaking change and that passing the --config-file
is becoming mandatory. edit: reading the tests, it appears that it does maintain backwards compatibility. It's just not obvious to me.
@@ -36,6 +36,11 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger) | |||
Strings.SymbolSource_Description, | |||
CommandOptionType.SingleValue); | |||
|
|||
var configurationFile = push.Option( | |||
"--config-file <source>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like most other dotnet commands use --configfile
, not --config-file
<SingleValueOption Name="configfile" Help="Option_ConfigFile" /> |
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x#options
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source#options
@@ -34,7 +40,7 @@ public void PushCommand_PushToV2FileSystemSource() | |||
var packageFileName = Util.CreateTestPackage("testPackage1", "1.1.0", packageDirectory); | |||
|
|||
// Act | |||
string[] args = new string[] { "push", packageFileName, "-Source", source }; | |||
string[] args = new string[] { Command_Push, packageFileName, Param_Source, source }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, but I don't find this easier. Command_Push
is many more characters than just "push"
, similar for Param_Source
. And given they're in constants, my gut feeling is that this means it's a non-obvious value. Like, maybe Command_Push
is maybe not just "push"
, so now I feel obligated to go to the top of the file to find out what it is.
I get this this could be useful if we ever rename push
to something else, then it's just a single place to change for all the tests in this file. However, renaming it would be a breaking change that I just don't see happening. So, my opinion is that we optimize for readability, which in my opinion, means prefer the string literals. But this is 100% opinionated.
@@ -2078,6 +2084,339 @@ public void PushCommand_PushToServerV3_WithSymbols_ApiKey_SymbolApiKey_BothFromC | |||
} | |||
} | |||
|
|||
[Theory] | |||
[InlineData(">")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's only a single InlineData, I think we may as well just use [Fact]
instead of [Theory]
.
@@ -36,6 +36,11 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger) | |||
Strings.SymbolSource_Description, | |||
CommandOptionType.SingleValue); | |||
|
|||
var configurationFile = push.Option( | |||
"--config-file <source>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"--config-file <source>", | |
"--config-file <file>", |
In NuGet vocabulary, a source is a feed of packages. I don't know if this was a copy-paste issue, but source really doesn't feel right to me. I don't know if we should say path
instead of file
.
dotnet restore -h
says --configile <FILE>
, while dotnet list package -h
says --config <CONFIG_FILE>
. Clear as mud. As consistent as flipping a coin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just fyi --configfile <File>
is used for dotnet nuget trust.
string.Join(" ", args), | ||
true); | ||
|
||
// TODO: The bad config file is ignored, so I need to confirm this is expected behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in chat, it does feel like a bug. My first guess would have been that the config file isn't actually being read, but then I'd expect the next test, PushCommand_ConfigFile_ExpectedFormat
, to fail.
Anyway, this PR clearly didn't introduce that behaviour, so we should create a new issue, and skip this test until that other issue is fixed.
FileSystemUtils.CreateFile( | ||
configFilePath, | ||
configFileName, | ||
string.Format( | ||
CultureInfo.InvariantCulture, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike nested method calls, because it's harder to read (where is the end )
for string.Format
? Are there any additional parameters to FileSystemUtils.CreateFile
, or just the 3? Also, when debugging, maybe I want to see the result of string.Format
without stepping into the outer method call. If string.Format
was a method from our own code, rather than the BCL (or if I disabled "Just My Code" in the debugger), then it's also harder to step into FileSystemUtils.CreateFile
without stepping into the nested method call.
Therefore, I suggest extracting the string.Format
into a variable, and then have a simple method call to FileSystemUtils.CreateFile
.
@@ -310,6 +310,7 @@ public static string CreateUAPProject(string directory, string projectJsonConten | |||
return projectFile; | |||
} | |||
|
|||
// TODO: Remove CreateFile methods from this utility class. Will require changes to all classes in NuGet.CommandLine.Test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coding guidelines number 22: https://github.com/NuGet/NuGet.Client/blob/dev/docs/coding-guidelines.md
Adding TODOs is not recommended and should be avoided whenever possible. In cases in which they do get added each TODO needs to be linked to an issue. Use the full url to the GitHub issue.
private const string Command_Push = "push"; | ||
private const string Param_ApiKey = "--api-key"; | ||
private const string Param_ConfigFile = "--config-file"; | ||
private const string Param_Source = "--source"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as the other file. My personal opinion is that this does not aid readability, and the risk of any of these is so low that putting them all in a constant is not worth the reduction in readability.
[PackageSourceTheory] | ||
[PackageSourceData(TestSources.MyGet)] | ||
[PackageSourceData(TestSources.ProGet, Skip = "No such host is known")] | ||
[PackageSourceData(TestSources.Klondike, Skip = "401 (Invalid API key)")] | ||
[PackageSourceData(TestSources.NuGetServer, Skip = "No such host is known")] | ||
public async Task PushToServerSucceeds(PackageSource packageSource) | ||
{ | ||
// Arrange | ||
// Setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/NuGet/NuGet.Client/blob/dev/docs/coding-guidelines.md#unit-test-structure
We use Arrange, Act, Assert as the coding guidelines unit test structure. This is known as the AAA pattern. Perhaps not well known (I never heard of it before joining NuGet), but doing a web search in multiple search engines finds many results, so I can't claim it's made up just for NuGet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see push improvements! I'm blocking on the comments/upvotes I put on coding guideline violations and several code changes or refactorings.
@@ -70,7 +76,7 @@ public void PushCommand_PushToV3FileSystemSource() | |||
var packageFileName = Util.CreateTestPackage(packageId, version, packageDirectory); | |||
|
|||
// Act | |||
string[] args = new string[] { "push", packageFileName, "-Source", source }; | |||
string[] args = new string[] { Command_Push, packageFileName, Param_Source, source }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As others have commented, I don't think introducing variables helps readability or maintainability, so should be reverted.
|
||
Assert.True( | ||
exitCode != 0, | ||
"The run did not fail as desired. Simply got this output:" + log.ShowMessages()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another area where I'm not sure adding strings is helpful.
"The run did not fail as desired. Simply got this output:" + log.ShowMessages()); | |
log.ShowMessages()); |
This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch. |
Bug
Fixes: NuGet/Home#4879
Regression? Last working version: No.
Description
Adding support for the --config-file option in dotnet nuget push.
As part of this change, adding automated test coverage for the --config-file (-configfile) option in both NuGet.exe and dotnet.exe as follows:
Also:
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation