NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

dotnet nuget push to GPR -- Invalid or unrecognized response #8580

Closed jwillmer closed 4 years ago

jwillmer commented 5 years ago

I run the following script in GitHub Actions:

      - name: Publish Nuget to GitHub registry
        run: dotnet nuget push ./MyNugetPackage.3.4.24.nupk -s https://nuget.pkg.github.com/USERNAME/index.json -k ${GITHUB_TOKEN}  
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

and I get the following output:


Run nuget push ./MyNugetPackage.3.4.24.nupk -Source https://nuget.pkg.github.com/USERNAME/index.json
Pushing MyNugetPackage.3.4.24.3.4.24.nupkg to 'https://nuget.pkg.github.com/USERNAME'...
  PUT https://nuget.pkg.github.com/USERNAME/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/USERNAME/'. The request will now be retried.
An error occurred while sending the request.
  The server returned an invalid or unrecognized response.
  PUT https://nuget.pkg.github.com/USERNAME/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/USERNAME/'. The request will now be retried.
An error occurred while sending the request.
  The server returned an invalid or unrecognized response.
  PUT https://nuget.pkg.github.com/USERNAME/
An error occurred while sending the request.
  The server returned an invalid or unrecognized response.
##[error]Process completed with exit code 1.

I'm running my code inside of ubuntu-latest (18.04) that has the following versions installed: software-in-virtual-environments-for-github-actions

Can someone help me explain what this error means? I don't know how to solve this.

rrelyea commented 5 years ago

@anangaur - has your experience with GPR given you wisdom on how to reply here?

anangaur commented 5 years ago

/cc: @infin8x

Unfortunately, GPR does not work with API keys as we would have expected it to work. I have provided this feedback to GitHub.

You would need to use nuget sources add command to add GPR as a source with the creds (GITHUB.TOKEN). See an example here: https://github.com/anangaur/entropy-packages/blob/master/.github/workflows/workflow.yml

    steps:
    - uses: actions/checkout@v1
    - name: Setup Nuget.exe
      uses: warrenbuckley/Setup-Nuget@v1
    - name: Add GPR Source
      run: nuget sources add -name "GPR" -Source https://nuget.pkg.github.com/anangaur/index.json -Username anangaur -Password ${{ secrets.GITHUB_TOKEN }}
    - name: dotnet build
      run: dotnet build
    - name: nuget push
      run: nuget push my.sample.lib\**\*.nupkg -Source "GPR" -SkipDuplicate

Btw, there is a typo in your yaml file. Look for use of nupk instead of nupkg (missing 'g').

jwillmer commented 5 years ago

warrenbuckley/Setup-Nuget@v1 only installs nuget for Windows. Using your workaround on Linux via sudo apt install nuget does not work. WARNING: No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/NAME'. To save an API Key for a source use the 'setApiKey' command.

anangaur commented 5 years ago

@jwillmer, you are right. We need to support dotnet sources command: https://github.com/NuGet/Home/issues/4126

Talento90 commented 5 years ago

When I execute the following command: nuget push "ProjectFolder\nupkgs\MyPackage.1.0.0.nupkg" -Source "GitHub"

I get this error: WARNING: No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/Company'. To save an API Key for a source use the 'setApiKey' command.

Can anyone explain why? Since it's related with @jwillmer problem.

jwillmer commented 5 years ago

Can anyone explain why? Since it's related with @jwillmer problem.

Please read the thread and you will find your answer.

cilerler commented 5 years ago

@rrelyea, It should work in non-windows builds. Would you please change this as a bug and not a question? Thanks in advance.

mhutch commented 5 years ago

I'm also seeing this using mono nuget.exe to publish to GPR on the Ubuntu image.

anangaur commented 5 years ago

Did you check my comment above https://github.com/NuGet/Home/issues/8580#issuecomment-531997703? Does it work?

mavaa commented 5 years ago

Managed to get this working for linux by creating a nuget.config "template" in my repo like this one: https://gist.github.com/marza91/06dd1a8af3abd85dd0c1972f22bbfc2d

I added this file (replace "ourcompany" with your user/org) to the base of the repo as ".nuget.config", and then simply did the following:

name: Build & Publish nuget package

on:
  push:
    branches: 
      - release

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.0.100
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: Setup nuget config
      run: sed 's/GITHUB_TOKEN/${{ secrets.GITHUB_TOKEN }}/g' .nuget.config > nuget.config
    - name: Publish nuget
      run: dotnet nuget push src/bin/Release/*.nupkg -s "github"

The sed command simply copies the file to "nuget.config" and replaces "GITHUB_TOKEN" with the environment variable :slightly_smiling_face:

mhutch commented 5 years ago

@anangaur I was doing pretty much the exact same thing but running nuget.exe on Mono, because the host is Ubuntu - https://github.com/mono/t4/commit/863011b731d9743033d6b371eb1c2719fe93293b

Konard commented 5 years ago

I have the same issue here: https://github.com/linksplatform/Interfaces/commit/ccdd15f114e77246cfc9e26c98eb7fdd8bd21a58/checks?check_suite_id=272173602

mikkeljohnsen commented 5 years ago

When will this be fixed ?

anangaur commented 5 years ago

@mikkeljohnsen What are you blocked on? Restoring packages or publishing packages?

Did you check the current workarounds? https://github.com/NuGet/Home/issues/8580#issuecomment-542643681

Konard commented 5 years ago

@marza91 you don't need to install .NET Core 3.0 when using ubuntu-latest in GitHub Actions, it is already there (the latest version, and also mono). So can safely remove this step:

    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.0.100

Btw, I use windows as a workaround for now: https://github.com/mono/t4/blob/573d5bb32be4b2b8ae13230cbc7eb56fcd9f9f99/.github/workflows/build.yml#L54-L58 https://github.com/linksplatform/Hardware.Cpu/blob/2e536836dd94dcfa8aa9840c99f50a9eb4a2c5a6/.github/workflows/main.yml#L42-L53

But it would be much better to have it working on linux too, I don`t want to use separate job for just this steps.

mhutch commented 5 years ago

@Konard TBH though I was annoyed by this initially, after I set up a matrix build I'm fine with having it in a later job, because that way the package only gets uploaded if all the matrix builds pass

mikkeljohnsen commented 5 years ago

@anangaur I'm not familiar with that. But I assume it is something that is done on GitHub after you push your code to the branche "release".

I do not build my NuGet packages with dotnet/msbuild. I have +200 projects in my solution and using MSBuild is simple a pain, not to mention using NuGet for all +200 projects. It is simple to slow.

I use Makefiles (and mono "csc") to build my projects and also create NuGet packages with "nuget pack *.nuspec" and the "nuget push" to upload. But the "nuget push" is failing.

I'm on Linux (Fedora 30). Using Mono 6.0.

mikkeljohnsen commented 5 years ago

So now "dotnet nuget push *.pkpkg -s GitHub", works sometimes. I have uploaded 2 packages out of 20. So just have to run the command a 100 times, then maybe all packages will be successfully uploaded :)

Must be something wrong with the GitHub server, since it works sometimes.

anangaur commented 5 years ago

@mikkeljohnsen intermittent failures are hard to fix. Can you paste the error messages you have been getting?

jwillmer commented 5 years ago

I tried @marza91 script but I get

warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/COMPANY'. To save an API Key for a source use the 'setApiKey' command.
info: Pushing ...
error: An error occurred while sending the request.
error: The response ended prematurely.

I think the warning can be ignored since we provide user/pw in the NuGet file. But I don't know if this error is because I already have the current version of the NuGet package deployed or if it is something else. In my version is used -SkipDuplicate to ignore published duplicates but this is not possible with dotnet nuget

mikkeljohnsen commented 5 years ago

@anangaur

As you can see the first package is already uploaded and it reports correctly that there is a conflict.

warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/openmedicus'. To save an API Key for a source use the 'setApiKey' command.
info : Pushing OpenMedicus.WebService.Master.2.6.105.nupkg to 'https://nuget.pkg.github.com/openmedicus'...
info :   PUT https://nuget.pkg.github.com/openmedicus/
warn : Error: Version OpenMedicus.WebService.Master of "2.6.105" has already been pushed.
info :   Conflict https://nuget.pkg.github.com/openmedicus/ 445ms
error: Response status code does not indicate success: 409 (Conflict).

But pushing new packages almost always fails.

warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/openmedicus'. To save an API Key for a source use the 'setApiKey' command.
info : Pushing OpenMedicus.RosterHelper.2.6.105.nupkg to 'https://nuget.pkg.github.com/openmedicus'...
info :   PUT https://nuget.pkg.github.com/openmedicus/
info : An error was encountered when fetching 'PUT https://nuget.pkg.github.com/openmedicus/'. The request will now be retried.
info : An error occurred while sending the request.
info :   The response ended prematurely.
info :   PUT https://nuget.pkg.github.com/openmedicus/
info : An error was encountered when fetching 'PUT https://nuget.pkg.github.com/openmedicus/'. The request will now be retried.
info : An error occurred while sending the request.
info :   The response ended prematurely.
info :   PUT https://nuget.pkg.github.com/openmedicus/
error: An error occurred while sending the request.
error:   The response ended prematurely.

Somtimes I also get (this is using "nuget push" and not "dotnet nuget push" as above):

Pushing OpenMedicus.Data.2.6.105.nupkg to 'https://nuget.pkg.github.com/openmedicus'...
  PUT https://nuget.pkg.github.com/openmedicus/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/openmedicus/'. The request will now be retried.
Error while copying content to a stream.
  Unable to write data to the transport connection: The socket has been shut down.
  The socket has been shut down
  PUT https://nuget.pkg.github.com/openmedicus/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/openmedicus/'. The request will now be retried.
Error while copying content to a stream.
  Unable to write data to the transport connection: The socket has been shut down.
  The socket has been shut down
  PUT https://nuget.pkg.github.com/openmedicus/
Error while copying content to a stream.
  Unable to write data to the transport connection: The socket has been shut down.
  The socket has been shut down
anangaur commented 5 years ago

@mikkeljohnsen Are you using the right PAT while adding the GPR source? With nuget.exe you can run:

nuget sources add -name "GPR" -Source https://nuget.pkg.github.com/<account>/index.json -Username <user> -Password <PAT>

And for dotnet, see https://github.com/NuGet/Home/issues/8580#issuecomment-542643681

mikkeljohnsen commented 5 years ago

@anangaur Yes I do. I have managed to upload 2 packages.

It is a TOKEN you have to use, and it has all the possible security rights set.

Dids commented 4 years ago

So does this only work reliably on Windows, while macOS and Linux only work intermittently?

I've yet to see pushing work at all on macOS. Not locally and not on a CI/GitHub Actions.

It almost sounds like the NuGet specific endpoint/service is stuck in an exception loop:

Pushing <PKG>.<VER>.nupkg to 'https://nuget.pkg.github.com/<ORG>'...
  PUT https://nuget.pkg.github.com/<ORG>/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/<ORG>/'. The request will now be retried.
An error occurred while sending the request.
  Unable to write data to the transport connection: The socket has been shut down.
  The socket has been shut down
  PUT https://nuget.pkg.github.com/<ORG>/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/<ORG>/'. The request will now be retried.
An error occurred while sending the request.
  Unable to write data to the transport connection: The socket has been shut down.
  The socket has been shut down
  PUT https://nuget.pkg.github.com/<ORG>/
An error occurred while sending the request.
  The server returned an invalid or unrecognized response.
anangaur commented 4 years ago

/cc: @reybard ⬆️

harry-cpp commented 4 years ago

Ha, well this is a bummer, I was just setting up azure pipelines for one of my projects and came accross this issue :/

Dids commented 4 years ago

Isn't GitHub Package Registry supposed to launch in about a week? Seems like it'll be a rocky launch, unless they can somehow fix all of these issues before then.

mikkeljohnsen commented 4 years ago

I just found out that it work if you use Curl:

curl -vX PUT -u "openmedicus:TOKEN" -F package=@OpenMedicus.Data.2.6.109.nupkg https://nuget.pkg.github.com/openmedicus/

ptdel commented 4 years ago

thanks for the workaround @mikkeljohnsen good enough for cicd until they fix it x_x

Dids commented 4 years ago

I was just about to implement the workaround, but I noticed that at least on macOS-latest (eg. Mojave + latest mono/msbuild/nuget), publishing with the nuget binary seems to work again?

Can anyone else confirm whether or not this works on macOS?

ejsmith commented 4 years ago

I think the underlying service for GitHub Package Registry is Azure Artifacts and I believe they did some announcements for the MS Ignite conference going on right now. So maybe they've just recently fixed some things?

Legio1221 commented 4 years ago

I was just about to implement the workaround, but I noticed that at least on macOS-latest (eg. Mojave + latest mono/msbuild/nuget), publishing with the nuget binary seems to work again?

Can anyone else confirm whether or not this works on macOS?

I'm on Catalina, I can't get any nupkgs to publish now with the nuget binary. I get the socket errors on push attempts. I think GPR is out of beta now?

The curl option does work though. :\

Dids commented 4 years ago

Yeah, turns out it only worked for me for a short while, and it's back to being broken again.

vslee commented 4 years ago

curl -vX PUT -u "openmedicus:TOKEN" -F package=@OpenMedicus.Data.2.6.109.nupkg https://nuget.pkg.github.com/openmedicus/

I'd like to try this out. Is there a way to save the nupkg name (OpenMedicus.Data.2.6.109.nupkg in this case) to a variable from the build step? That way the curl command can reference the variable rather than a hardcoded filename.

mikkeljohnsen commented 4 years ago

@vslee Not sure how your setup is. But I just build all my packages and move them to dir and run script with this:

#!/usr/bin/bash

for f in *.nupkg
do
    curl -X PUT -u "openmedicus:`cat nugetpass`" -F package=@"$f" https://nuget.pkg.github.com/openmedicus/
done

I have a file named "nugetpass" in that directory, containing the TOKEN

vslee commented 4 years ago

Yes, that works for me. For reference of others, here is my code, using input from @mikkeljohnsen.

name: prerelease NuGet

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    # also works with windows-latest and macos-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v1
    - name: Build with dotnet
      run: dotnet build --configuration Release --version-suffix prerelease-$(date +%Y%m%d%H%M%S)
      shell: bash
    - name: Publish nuget
      run: |
           for f in ./[repository]/bin/Release/*.nupkg
           do
             curl -vX PUT -u "[user]:${{ secrets.GHPackagesToken }}" -F package=@$f https://nuget.pkg.github.com/[user]/
           done
      shell: bash

Notes:

nnyegaard commented 4 years ago

I'm still unable to push any packages to GitHub and I have tried all the workarounds:

I thought that maybe it was because I tried to get it to work with our Organization account, but I am also getting the error on my private account. Have anybody tried something like this?

vslee commented 4 years ago

@nnyegaard try creating a test repo w/ my solution. If it still doesn't work, post a link to the repo and I can take a look.

nnyegaard commented 4 years ago

@vslee I got it working from your repo. I think I located the error, I did not specify the Repository URL in the csproj file for NuGet and without that nothing is happening. GitHub properly need to document that

mavaa commented 4 years ago

Not a logical place to look for it, but the documentation actually mentions this under the "Publishing multiple packages to the same repository" topic: https://help.github.com/en/github/managing-packages-with-github-packages/configuring-nuget-for-use-with-github-packages#publishing-multiple-packages-to-the-same-repository

Github will try to derive the repo name from the package name, unless the repository url is specified. Usually you do this if you want to have multiple packages in the same repo, but I think it would be a good idea to also mention this in the "Publishing a package" topic, as not everyone is interested in publishing multiple packages.

MarcusOtter commented 4 years ago

I encountered this issue when using nuget/setup-nuget@v1 on ubuntu with the following steps:

    - uses: nuget/setup-nuget@v1
      with:
        nuget-api-key: ${{ secrets.NUGET_API_KEY }}
        nuget-version: 'latest'

    - name: Push package to the Github Package Registry
      run: |        
        nuget sources Add -Name "GPR" -Source "https://nuget.pkg.github.com/lemorrow/index.json" -UserName LeMorrow -Password ${{ secrets.GITHUB_TOKEN }}
        nuget setApiKey ${{ secrets.NUGET_API_KEY }} -Source "GPR"
        nuget push nupkg\*.nupkg -Source "GPR" -SkipDuplicate

Simply changing runs-on: ubuntu-latest to runs-on: windows-latest for the job fixed this for me.

anangaur commented 4 years ago

@rrelyea @zkat can you chime in on how to use setup-NuGet on Linux. Should this also use StorePasswordInClearText on platforms other than Windows, for it to work with Mono?

timheuer commented 4 years ago

@LeMorrow are you still seeing this? I'm not. You shouldn't need setApiKey if you are using UserName and Password option. See my sample here that works and publishes to GPR: https://github.com/timheuer/test-lib/blob/master/.github/workflows/build-and-deploy.yaml. It's the same as yours minus the setApiKey which is not needed in this case.

MarcusOtter commented 4 years ago

@timheuer The issue is still the same for me after upgrading NuGet/setup-nuget to 1.0.2 and removing setApiKey.

Results after just bumping the action version: https://github.com/LeMorrow/APOD.Net/runs/351453149#step:4:12

Results after removing the setApiKey line: https://github.com/LeMorrow/APOD.Net/runs/351536183#step:4:11

TL;DR: This

nuget sources Add -Name "GPR" -Source "https://nuget.pkg.github.com/lemorrow/index.json" -UserName LeMorrow -Password ***
nuget push nupkg/*.nupkg -Source "GPR" -SkipDuplicate

still throws the error

An error was encountered when fetching 'PUT https://nuget.pkg.github.com/lemorrow/'. The request will now be retried.
An error occurred while sending the request.
  The server returned an invalid or unrecognized response.
  PUT https://nuget.pkg.github.com/lemorrow/

but only on ubuntu-latest. Not windows-latest.

timheuer commented 4 years ago

@LeMorrow wow, certainly looks the same as mine and I'm not having issues. I wonder if you delete https://github.com/LeMorrow/APOD.Net/blob/master/.github/workflows/deploy.yml#L58 if that makes any difference. I can't imagine why it would and odd that you are seeing this just on ubuntu-latest. Also perhaps add -Verbosity detailed to see if anything more from nuget.exe comes across.

MarcusOtter commented 4 years ago

@timheuer Odd indeed! Removing line 58 did not make a difference as you hypothesized. The detailed verbosity provided a stack trace, hopefully that will be useful for anyone taking a look at this. Let me know if there's anything else I can do to help reproduce/debug this issue :)

Here's the result without line 58 and detailed verbosity: https://github.com/LeMorrow/APOD.Net/runs/352456423#step:4:1

aggieben commented 4 years ago

I've been struggling with this issue also; this is where I have ended up for now: https://github.com/bitthicket/AspNetCore/blob/master/.github/workflows/nuget_release.yml

And the latest results from this workflow: image

I've tried everything suggested in this thread and I'm just at a loss.

vslee commented 4 years ago

@aggieben did you try my solution?

aggieben commented 4 years ago

@vslee parts of it. I have some other moving parts that are different and would be tedious to change. For example, I'm using paket to build my project and package, executed from a fake script.

Update: I did try to use the curl command just now, and it failed in the same way: image

(although the exit code was apparently success? maybe because of invoking through the bash shell...)

vslee commented 4 years ago

Since you're using a different build system, are you sure that the .nupkg is in ./temp/*.nupkg? Can you do a 'ls' command there to verify?