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

Adding support for pushing multiple packages #3739

Merged
merged 19 commits into from
Nov 4, 2020

Conversation

marcin-krystianc
Copy link
Contributor

Bug

Fixes: NuGet/Home#4393
Regression: No

Fix

Details: Following the advice from the NuGet/Home#4393 (comment).
After this change, the push command takes one or more paths. So it still works as expected even when the dotnet nuget push *.nupkg command is run from the shell that supports globbing and *.nupkg is being expanded to multiple arguments.

Testing/Validation

Tests Added: Yes

@marcin-krystianc marcin-krystianc requested a review from a team as a code owner October 27, 2020 13:49
@zivkan zivkan added the Community PRs created by someone not in the NuGet team label Oct 27, 2020
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I'll go ahead and run CI on your branch to get some early feedback until you can address my comments...

In #3140, I added tests to ensure wildcard of * works correctly when automatically pushing .snupkg's. I'd like some sort of functional test (or additional assertions) to make sure your PR doesn't regress that behavior.

Specifically, how will these scenarios fit with your change? (see my PR above)
PushCommand_Server_Nupkg_ByWildcard_SnupkgDoesNotExist_NoFileNotFoundError()
PushCommand_Server_Snupkg_ByFilename_DoesNotExist_FileNotFoundError()

@donnie-msft
Copy link
Contributor

The dotnet formatting analyzers are failing for some of your changes. Try running dotnet format --check --exclude submodules to see them.

CI failed to build your changes. It looks like your [Obsolete] methods are the culprits:

##[error]test\NuGet.Core.Tests\NuGet.Protocol.Tests\Resources\PackageUpdateResourceTests.cs(810,23): Error CS0618: 'PackageUpdateResource.Push(string, string, int, bool, Func<string, string>, Func<string, string>, bool, bool, SymbolPackageUpdateResourceV3, ILogger)' is obsolete: 'Use Push method which takes multiple package paths.'

Did you run .\build.ps1 (see docs)? Curious if that somehow succeeded.

@marcin-krystianc
Copy link
Contributor Author

Did you run .\build.ps1 (see docs)? Curious if that somehow succeeded.

No, my mistake. But still it shouldn't happen as I was running PackageUpdateResourceTests anyway. I cannot explain how I missed it 🤷

Copy link
Contributor Author

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

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

@donnie-msft I hope I addressed all your comments, can you have another look ?

donnie-msft
donnie-msft previously approved these changes Oct 30, 2020
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

Thanks for contributing! Running CI...

{
var errorMsg = string.Format(MESSAGE_FILE_DOES_NOT_EXIST, snupkgsToPush[i]);

// Only the first file that is missing should be mentioned in logs
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -68,5 +69,36 @@ public static class PushRunner
symbolPackageUpdateResource,
logger);
}

[Obsolete("Use Run method which takes multiple package paths.")]
public static Task Run(
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't understand logic of adding public also same time obsolete method. If it's doesn't exist before then why bother to add now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks wrong but only because of how the diff is being shown.
Actually my change is deprecating the previously existing method which takes string packagePath and adding a new one which takes IList<string> packagePaths.

}
}
}

[Obsolete("Use Push method which takes multiple package paths.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same, it looks wrong but only because of how the diff is being shown.

@donnie-msft
Copy link
Contributor

Failing tests (on both Windows/Mac):

PushCommand_PushToServer_ApiKeyAsNamedArgument

Pushing testPackage1.1.1.0.nupkg to 'http://localhost:50231/8efafaf5-fe52-4a70-82f4-ed6e1a06e164/push'...\r\n PUT http://localhost:50231/8efafaf5-fe52-4a70-82f4-ed6e1a06e164/push/\r\n Created http://localhost:50231/8efafaf5-fe52-4a70-82f4-ed6e1a06e164/push/ 5ms\r\nYour package was pushed.\r\n File does not exist (should-be-ignored).\r\n\r\nExpected: True\r\nActual: False
Stack trace
at NuGet.CommandLine.Test.NuGetPushCommandTest.PushCommand_PushToServer_ApiKeyAsNamedArgument() in test\NuGet.Clients.Tests\NuGet.CommandLine.Test\NuGetPushCommandTest.cs:line 1653

PushCommand_PushToServer_ApiKeyAsThirdArgument

Pushing testPackage1.1.1.0.nupkg to 'http://localhost:50231/7fcbeab0-5495-42dc-acc7-ed78fc2f6e0d/nuget'...\r\n PUT http://localhost:50231/7fcbeab0-5495-42dc-acc7-ed78fc2f6e0d/nuget/\r\n Created http://localhost:50231/7fcbeab0-5495-42dc-acc7-ed78fc2f6e0d/nuget/ 23ms\r\nYour package was pushed.\r\n File does not exist (10ac98b0-2bbc-4d92-98ea-44d1439be955).\r\n\r\nExpected: True\r\nActual: False
Stack trace
at NuGet.CommandLine.Test.NuGetPushCommandTest.PushCommand_PushToServer_ApiKeyAsThirdArgument() in test\NuGet.Clients.Tests\NuGet.CommandLine.Test\NuGetPushCommandTest.cs:line 1578

@marcin-krystianc
Copy link
Contributor Author

Failing tests (on both Windows/Mac):
PushCommand_PushToServer_ApiKeyAsNamedArgument
PushCommand_PushToServer_ApiKeyAsThirdArgument

Well, it is more complicated than I thought.
I've updated both NuGet.exe (NuGet.CommandLine) and dotnet NuGet (NuGet.CommandLine.XPlat).
It turns out though, that extending push command for nuget.exe is rather not possible due to problems with backwards compatibility. There is some special ApiKey logic, which for cases where ApiKey is not specified, it assumes that second parameter is an ApiKey (https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Clients/NuGet.CommandLine/Commands/PushCommand.cs#L51-L58)
This behaviour is also documented here https://docs.microsoft.com/en-gb/nuget/reference/cli-reference/cli-ref-push#examples.

I think I'll revert changes for NuGet.exe and stick only to the dotnet nuget push scenario. Will such lack of symmetry be ok ?

@donnie-msft
Copy link
Contributor

I think I'll revert changes for NuGet.exe and stick only to the dotnet nuget push scenario. Will such lack of symmetry be ok ?

Yes, I've checked with the team and it's good to move forward with your dotnet changes. I'll create a follow-up issue for the nuget.exe breaking change ~6.0 timeframe.
Thanks for being attentive and flexible!

- Adding NuGet.XPlat tests
- Adding NuGet.XPlat tests
Copy link
Contributor Author

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

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

All right, I've reverted changes related to the nuget.exe.

@@ -68,5 +69,36 @@ public static class PushRunner
symbolPackageUpdateResource,
logger);
}

[Obsolete("Use Run method which takes multiple package paths.")]
public static Task Run(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks wrong but only because of how the diff is being shown.
Actually my change is deprecating the previously existing method which takes string packagePath and adding a new one which takes IList<string> packagePaths.

}
}
}

[Obsolete("Use Push method which takes multiple package paths.")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same, it looks wrong but only because of how the diff is being shown.

Copy link
Contributor

@zkat zkat left a comment

Choose a reason for hiding this comment

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

LGTM! I'm really excited that we're adding this, and also that we're not holding up dotnet.exe in order to do it. We'll deal with NuGet.exe eventually. Thanks for the PR!

@donnie-msft donnie-msft merged commit fa9fbcb into NuGet:dev Nov 4, 2020
@marcin-krystianc marcin-krystianc deleted the 20201027-marcink-multipush branch December 15, 2020 15:59
@AraHaan
Copy link

AraHaan commented Apr 25, 2021

Does this also include shells that by default does not do file globbing when you do dotnet nuget push *.nupkg?

@marcin-krystianc
Copy link
Contributor Author

@AraHaan NuGet can do globbing internally so your scenario was supported even before my change,

@AraHaan
Copy link

AraHaan commented Apr 26, 2021

@marcin-krystianc I was making sure as I will need some way to replace the github action that pushes since it only allows pushing one and it is not feasible as I would like to move my workflows and everything from a .github folder to an repository named .github as I heard it could provide defaults for all repositories on an "organization" on github.

However not sure if repositories could override only specific files from that repository if they need to while using the rest from that repository if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PRs created by someone not in the NuGet team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet nuget push *.nupkg doesn't push more than one file
6 participants