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.
@anangaur - has your experience with GPR given you wisdom on how to reply here?
/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').
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.
@jwillmer, you are right. We need to support dotnet sources
command: https://github.com/NuGet/Home/issues/4126
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.
Can anyone explain why? Since it's related with @jwillmer problem.
Please read the thread and you will find your answer.
@rrelyea, It should work in non-windows builds. Would you please change this as a bug and not a question? Thanks in advance.
I'm also seeing this using mono nuget.exe
to publish to GPR on the Ubuntu image.
Did you check my comment above https://github.com/NuGet/Home/issues/8580#issuecomment-531997703? Does it work?
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:
@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
When will this be fixed ?
@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
@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.
@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
@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.
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.
@mikkeljohnsen intermittent failures are hard to fix. Can you paste the error messages you have been getting?
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
@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
@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
@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.
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.
/cc: @reybard 猬嗭笍
Ha, well this is a bummer, I was just setting up azure pipelines for one of my projects and came accross this issue :/
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.
I just found out that it work if you use Curl:
curl -vX PUT -u "openmedicus:TOKEN" -F [email protected] https://nuget.pkg.github.com/openmedicus/
thanks for the workaround @mikkeljohnsen good enough for cicd until they fix it x_x
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 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?
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. :\
Yeah, turns out it only worked for me for a short while, and it's back to being broken again.
curl -vX PUT -u "openmedicus:TOKEN" -F [email protected] 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.
@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
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:
<VersionPrefix>
instead of <Version>
in your .csproj<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
in your .csprojdotnet pack
<RepositoryUrl>...</RepositoryUrl>
in your .csprojdotnet nuget push
command (see initial post), then we won't need this workaround anymoreI'm still unable to push any packages to GitHub and I have tried all the workarounds:
warn : The expected resource was not found.
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?
@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.
@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
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.
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.
@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?
@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.
@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
.
@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.
@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
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:
I've tried everything suggested in this thread and I'm just at a loss.
@aggieben did you try my solution?
@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:
(although the exit code was apparently success? maybe because of invoking through the bash shell...)
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?
@vslee
@aggieben do check if you have set the repository
/repositoryurl
property for the package. It is known to fail without having this URL pointing to the same repo you are publishing it to. More details
Sample: https://github.com/anangaur/entropy-packages/blob/master/my.sample.lib/my.sample.lib.csproj#L13
@anangaur should verbose detail output provide more info here that could point to the issue?
Ideally yes. While a lot of error messages have been improved, clearly not all. Will add this to the list of improvements.
Aha! I think my issue boils down to not having the repository
element in my nupkg metadata, which in turn was caused by paket
behavior, which requires both RepositoryUrl
_and_ RepositoryType
for that to be emitted as metadata. After fiddling with my paket.template
file and .fsproj
properties I was able to finally generate a nupkg which made it onto GPR.
For reference, this is where this behavior was implemented in Paket: https://github.com/fsprojects/Paket/pull/3708
Thanks for validating my hunch 馃憤 . I will follow with the GPR team to emit better error message for this situation.
I encountered a similar problem and hope to be helped.
https://github.com/NuGet/Home/issues/3406#issuecomment-588079375
Any news? It is possible to publish the NuGet package from ubuntu to GPR now?
It should be. Although I use "dotnet nuget push", I can definitely push to the registry by setting it up in the dotnet setup phase (other solutions/attempts failed), like so:
steps:
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
source-url: https://nuget.pkg.github.com/<organization>/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
It should be. Although I use "dotnet nuget push", I can definitely push to the registry by setting it up in the dotnet setup phase (other solutions/attempts failed), like so:
steps: - name: Setup .NET Core @ Latest uses: actions/setup-dotnet@v1 with: source-url: https://nuget.pkg.github.com/<organization>/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
I can confirm that this solution works
Works for me as well. Below is the whole workflow I'm using. Note the --no-symbols true
- Another bug, it doe not work with --no-symbols
.
name: NuGet Generation
on:
push:
branches:
- master
pull_request:
types: [closed]
branches:
- master
jobs:
build:
runs-on: ubuntu-18.04
name: Update NuGet package
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
source-url: https://nuget.pkg.github.com/<organization>/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Build solution and generate NuGet package
run: |
cd <project>
dotnet pack -c Release -o out
- name: Push generated package to GitHub registry
run: dotnet nuget push ./<project>/out/*.nupkg --skip-duplicate --no-symbols true
I've been attempting to upload dotnet nupkgs to GitHub packages. I've followed all of the troubleshooting advice, I've got my tokens, my repository url set, my nuget.config file configured, but I find that both pushing/pulling packages is relatively intermittent. Sometimes it just works - other times I get the following error:
Pushing <packageName> to "http://nuget.pkg.github.com/<Owner>
PUT https://nuget.pkg.github.com/<Owner>/
An error encountered when fetching PUT http://nuget.pkg.github.com/<Owner>. The request will now be retried.
An error occurred while sending the request.
The response ended prematurely.
PUT https://nuget.pkg.github.com/<Owner>
An error encountered when fetching PUT http://nuget.pkg.github.com/<Owner>. The request will now be retried.
An error occurred while sending the request.
The response ended prematurely.
PUT https://nuget.pkg.github.com/<Owner>
error: An error occurred while sending the request.
error: The response ended prematurely.
It's frustrating because sometimes it just works.
Package is pushed.
And other times I can keep re-submitting the same request and it will fail for a while, and eventually just push, without any changes/modification to my code/dotnet nuget push statement.
I see there's been a lot of discussion about this on the forums. I'm presuming it's just a temperamental fault that will be rectified?
Thanks
The method above shouldn't be failing, but all the other methods did fail for me, most of the time at least.
@JB101UK GitHub's current docs use https://nuget.pkg.github.com/OWNER/index.json
as the example. Make sure you use the trailing /index.json
for best luck.
Hi @zivkan thanks for your comments.
I have the key:value pair setup in my nuget.config file as stated in the GitHub docs you mentioned.
Please see code below.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="github" value="https://nuget.pkg.github.com/OWNER/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="USERNAME" />
<add key="ClearTextPassword" value="TOKEN" />
</github>
</packageSourceCredentials>
</configuration>
However, when I push the package it trims the index.json off of the end in the terminal output, so the error message ends up being the one I've provided above.
Do you have any further thoughts?
Still having the same problem at the moment! :(
Thanks
JB101UK
I'm having the exact same problem as @JB101UK. I have two private repos set up, they're both designed to build and push packages to GitHub and they're set up with near-identical scripts. In one of the repos the push succeeds 100% of the time, and in the other repo it only succeeds about 20-25% of the time. All I have to do in order to make it work is run the same action over and over until it goes through. I don't even have to create a new PR, I just keep clicking on the failed workflow -> "Re-run jobs" until it works.
My failing action looks like this:
name: Release
on:
push:
branches:
- master
jobs:
build:
name: Build & Publish
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.201' # SDK Version to use.
source-url: https://nuget.pkg.github.com/bjorhn/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Restore Nuget packages
run: dotnet restore
- name: Create the nuget package
run: dotnet pack MyProject.csproj --configuration Release --no-build --output bin/Release/Publish
- name: Publish to GitHub
run: dotnet nuget push bin/Release/Publish/**/*.nupkg --skip-duplicate
The only difference between the working and the failing repo/action is that the working one performs a dotnet build instead of a dotnet restore, and doesn't set the --no-build flag when calling dotnet pack.
So I've tried everything.. I've been in all the posts and all the issue threads and there is just no way to get this to work without applying some good old fashioned brute force 馃敤馃敤馃敤
The following is the only thing that works for me, without having to re-run the job.
- name: Publish backend with force 馃敤馃敤馃敤
shell: bash
run: |
until dotnet nuget push Publish/**/*.nupkg --skip-duplicate --no-symbols true; do echo "Retrying"; sleep 1; done
It might urk some but at this point I don't care.
Is there something broken with nuget CLI or is it the reliability of GPR service? Did you try reaching out to GPR folks through https://github.community?
Better late then never: Link (back) to StackOverflow discussion
Hi!
Is it possible to somehow list the packages using the nuget cli tool, like:
nuget.exe list * -Source github
?
My _nuget.config_ file has the package source:
<packageSources>
<add key="github" value="https://nuget.pkg.github.com/laheller/index.json" />
</packageSources>
For me it always returns with:
WARNING: This version of nuget.exe does not support listing packages from package source 'https://nuget.pkg.github.com/laheller/index.json'.
No packages found.
I have the latest v5.5.1 version and there is 1 package published to my github packages feed.
BR,
Ladislav
No matter what I try I only ever get this reply:
warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/ORG'. To save an API Key for a source use the 'setApiKey' command.
info : Pushing pkg.0.0.5.nupkg to 'https://nuget.pkg.github.com/ORG'...
info : PUT https://nuget.pkg.github.com/ORG/
info : NotFound https://nuget.pkg.github.com/ORG/ 519ms
error: Response status code does not indicate success: 404 (Not Found).
I can manually go to the nuget.pkg.github.com url and there is definitely something there. But the PUT request 404s
I spent some time trying all the approaches explained in this thread, I could not get it to work in any case and I still get the same error reported by many others:
warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/myorg'. To save an API Key for a source use the 'setApiKey' command. info : Pushing pkg.0.0.1.nupkg to 'https://nuget.pkg.github.com/myorg'... info : PUT https://nuget.pkg.github.com/myorg/ info : NotFound https://nuget.pkg.github.com/myorg/ 519ms error: Response status code does not indicate success: 404 (Not Found).
I executed the same job several times (~30 times) and it consistently fails.
I cannot push any packages to the registry, it would be nice to get this solved soon...
Also been through a few iterations and approaches to this. Sometimes the following works, other times I get errors:
- name: Publish to github
run: dotnet nuget push **/*.nupkg -s https://nuget.pkg.github.com/[USERNAME]/index.json -k ${{ secrets.GITHUB_TOKEN }} --skip-duplicate --no-symbols true
working-directory: src
[intermittent] errors with: An error was encountered when fetching 'PUT https://nuget.pkg.github.com/daltskin/'. The request will now be retried. An error occurred while sending the request.
Now, I'm just using curl to push the package and it seems more reliable :)
Replace [PACKAGE]
with your package name
Replace [USERNAME]
with your username
Github workflow extract:
- name: Package
run: dotnet pack --configuration Release --no-build -p:PackageVersion=${{ env.GitVersion_SemVer}}
- name: Publish to github (using curl)
run: curl -vX PUT -u "[USERNAME]:${{ secrets.GITHUB_TOKEN }}" -F package=@[PACKAGE].${{ env.GitVersion_SemVer}}.nupkg https://nuget.pkg.github.com/[USERNAME]/
working-directory: src/bin/Release
I have two repos where I'm using the exact same build.yml
file and one fails while the other does not. The only difference is that one project has a .
in the name (Schema.NET
) while the other (FastestNuGet
) does not. There doesn't seem to be any issues tracking this.
Run dotnet nuget push .\windows-latest\*.nupkg --source GitHub --skip-duplicate
warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/RehanSaeed'. To save an API Key for a source use the 'setApiKey' command.
Pushing Schema.NET.7.1.1-preview.0.33.nupkg to 'https://nuget.pkg.github.com/RehanSaeed'...
PUT https://nuget.pkg.github.com/RehanSaeed/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/RehanSaeed/'. The request will now be retried.
Error while copying content to a stream.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
An existing connection was forcibly closed by the remote host.
PUT https://nuget.pkg.github.com/RehanSaeed/
An error was encountered when fetching 'PUT https://nuget.pkg.github.com/RehanSaeed/'. The request will now be retried.
Error while copying content to a stream.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
An existing connection was forcibly closed by the remote host.
PUT https://nuget.pkg.github.com/RehanSaeed/
error: Error while copying content to a stream.
error: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
error: An existing connection was forcibly closed by the remote host.
name: Build
on:
push:
pull_request:
release:
types:
- published
env:
# Set the DOTNET_SKIP_FIRST_TIME_EXPERIENCE environment variable to stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Set the build number in MinVer
MINVERBUILDMETADATA: build.${{github.run_number}}
jobs:
build:
name: Build-${{matrix.os}}
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
lfs: true
fetch-depth: 0
- name: 'Git Fetch Tags'
run: git fetch --tags
shell: pwsh
- name: 'Install .NET Core SDK'
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
- name: 'Dotnet Tool Restore'
run: dotnet tool restore
shell: pwsh
- name: 'Dotnet Cake Build'
run: dotnet cake --target=Build
shell: pwsh
- name: 'Dotnet Cake Test'
run: dotnet cake --target=Test
shell: pwsh
- name: 'Dotnet Cake Pack'
run: dotnet cake --target=Pack
shell: pwsh
- name: 'Publish Artefacts'
uses: actions/[email protected]
with:
name: ${{matrix.os}}
path: './Artefacts'
push-github-packages:
name: 'Push GitHub Packages'
needs: build
if: github.ref == 'refs/heads/master' || github.event_name == 'release'
runs-on: windows-latest
steps:
- name: 'Download Artefact'
uses: actions/download-artifact@v1
with:
name: 'windows-latest'
- name: 'Dotnet NuGet Add Source'
run: dotnet nuget add source https://nuget.pkg.github.com/RehanSaeed/index.json --name GitHub --username RehanSaeed --password ${{secrets.GITHUB_TOKEN}}
shell: pwsh
- name: 'Dotnet NuGet Push'
run: dotnet nuget push .\windows-latest\*.nupkg --source GitHub --skip-duplicate
shell: pwsh
I got it working with dotnet nuget push
here
.. but didnt work when using a repo under a GitHub organization, so I switched to curl
I'm using my nuget action under an organization and this is what's been working for us after many trial and errors.
- name: Publish backend nuget
run: curl -vX PUT -u "user:${{ secrets.package_secret }}" -F package=@Publish/backend.${{env.VERSION}}.nupkg https://nuget.pkg.github.com/myorg/
shell: bash
working-directory: ${{env.backend-directory}}
- name: Publish frontend nuget
run: curl -vX PUT -u "user:${{ secrets.package_secret }}" -F package=@Publish/backend.${{env.VERSION}}.nupkg https://nuget.pkg.github.com/myorg/
shell: bash
working-directory: ${{env.frontend-directory}}
I know this issue is closed, but I continue to see issues with the methods mentioned above. One time it works and then another time it doesn't. I am also working under and organization. This is SO Frustrating!
Hey All, I can understand this can be frustrating. For the team to have visibility and help here, I have created a new issue:
Reliability issues while publishing packages to GPR, using GitHub Actions)
#10045
Please provide your experience/issues and upvotes on this new issue. Hope this helps.
I reached out to GitHub Enterprise Support and here's what they shared with me:
Sorry for the trouble here -- we're aware of an issue that seems to affect some .nupkg files, but not others and our engineering team is working to isolate the issue causing this behaviour when pushing nuget packages to the GitHub Package Registry.
Please try the following alternative methods to push your package and let us know if that works for you:
curl -vX PUT -u "<username>:<TOKEN>" -F [email protected] https://nuget.pkg.github.com/<OWNER>/
Another alternative method is to push using the gpr tool:
dotnet tool install gpr -g gpr push PATH-TO-PKG-FILE.nupkg -k <TOKEN>
Here is how I used the GPR Tool in my GitHub Action and it worked the first time!
$file = Get-ChildItem -Path <where I output my nupkg file to> -Recurse -Filter *.nupkg | Select -First 1
gpr push $file.FullName -k ${{secrets.GITHUB_TOKEN}}
@Airn5475 gpr might not be an option for some users like me.
Something not everybody knows is that nuget.config files are evaluated in cascade from the root directory to the current directory. So nuget.config files in between the root and the current directory can add, remove or override existing properties. I use this particular behaviour to split the login keys and the actual nuget server in two separated nuget.config files, so I can add the nuget.config with the servers to the repository, and leave the nuget.config with the login keys out of it.
nuget cli app and visual studio handles this feature perfectly, whereas gpr only reads the properties of the first nuget.config it finds.
In fact, I suspect this way of handling nuget.configs is one of the reasons because it works for some users, and not for others.
@vpenades I hear you, this isn't for everyone, but I saw others in the comments above having trouble with dotnet push and so I thought it best to share my solution. Better to perhaps help some then for sure help none, right?
I am aware of the nuget.config cascade and have wrestled with it a couple times. That was not my issue this time since my files were all in order and a repo that HAD been publishing nuget packages fine, stopped working.
I can't speak to others, but gpr fixed my issue today!
More recently I've noticed a general improvement in the frequency of success messages vs. failure messages. I've also found that in the few instances that it doesn't work, going away for a coffee and coming back 10 minutes later to retry is usually sufficient to achieve a successful push. Not an ideal solution, but at least you get a coffee out of it!
Anyway, I've included both my NuGet.config
file and a deploy-package.ps1
script that I've written to ease this process. Just to note that the deploy-package script was primarily written for .NET Core/.NET Standard 2.1 (but seems to work fine with .NET Framework scripts too). The deploy-package and NuGet.config files must reside in your root folder (at same level as .sln file) and make an implicit assumption that the .csproj file is in a subdirectory (i.e. src folder etc.), so your project structure should look as follows:
You could revamp the deploy-package script for other folder arrangements, but this was ideal for my team's workflow.
Anyway, here are the files (replace repo name as required):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/**REPOSITORY-NAME**/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="%GITHUB_USERNAME%" />
<add key="ClearTextPassword" value="%GITHUB_TOKEN%" />
</github>
</packageSourceCredentials>
</configuration>
# Powershell Script identifies the latest built NuGet Package and uploads to GitHub Packages.
# Functions to define coloured messages for SUCCESS and ERROR statements.
function Write-Success{Write-Host "SUCCESS:" -ForegroundColor Green -NoNewLine}
function Write-Error{Write-Host "ERROR:" -ForegroundColor Red -NoNewLine}
# Store the initial working directory to return the user back to this folder during clean-up.
$startingDir = Get-Location
# Gets the location of the calling script.
# This file should be inside the top level of the respective dotnet project in the same level as the .sln file.
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
# Sets the working directory to the location of the project to build.
Set-Location "$ScriptDir/src"
# Builds Project to ensure .nupkg file is present.
# Note: this assumes <generatePackageOnBuild> tag in .csproj file is set to true.
Write-Host "Building Project to Generate .nupkg File..."
dotnet build --configuration Release
Write-Host "$(Write-Success) Build Complete."
Write-Host ""
# Identifying the most recent .nupkg file.
# Finds all children in bin/Release/netstandard2.1, which contains .nupkg files.
Write-Host "Finding Most Recent .nupkg File..."
$latestPackage = Get-ChildItem -path "./bin/Release/netstandard2.1" |
Sort-Object -Property LastWriteTime |
Select-Object -last 1
Write-Host "$(Write-Success) Most Recent Package Found."
Write-Host ""
# Extracting baseName from file.
$latestPackageBaseName = $latestPackage.baseName
Write-Host "$(Write-Success) baseName Retrieved: $latestPackageBaseName"
Write-Host ""
# Publishing Package to GitHub (assuming Token Configuration already complete).
Write-Host "Attempting to Deploy to GitHub..."
try {
dotnet nuget push "./bin/Release/netstandard2.1/$latestPackageBaseName.nupkg" --skip-duplicate -s "github" -k $env:NUGET_KEY
Write-Host ""
}
# Regardless of success of package push,
# reset variables and working directory location.
finally {
# Clean Up.
Write-Host "Cleaning up variables..."
Set-Location $startingDir
$latestPackage = ""
$latestPackageBaseName = ""
Write-Host "Powershell Script clean up complete."
}
Just a note for those who've never had to set environment variables, it's very straightforward. Simply follow the steps below:
code $profile.CurrentUserAllHosts
$Env:NUGET_KEY="..."
,$Env:GITHUB_USERNAME="..."
,$Env:GITHUB_TOKEN="..."
./deploy-package.ps1
script provided above.Just a final comment that Visual Studio can interfere with NuGet.config file! If working in Visual Studio, you can avoid needing the NuGet.config file altogether by running the following command in PowerShell (just a one-time thing!) and you set a system-wide source setting that will work across VS, PowerShell Core, Windows PowerShell etc:
dotnet nuget add source "https://nuget.pkg.github.com/**REPOSITORY-NAME**/index.json" --name "github" --username $Env:GITHUB_USERNAME --password $Env:GITHUB_TOKEN --store-password-in-clear-text
The deploy-package script will still work as expected.
This source setting is saved here on Windows: {Home}\{user}\AppData\Roaming\NuGet
This issue is intermittent, but the info above should increase your odds of success until it's fixed! If at first you don't succeed, get a coffee and try later ;)
Cheers.
I was able to make it work using the following command:
nuget push ProjectName/bin/Release/ProjectName.x.y.z.nupkg -source "github"
Previously, using dotnet nuget push ProjectName/bin/Release/ProjectName.x.y.z.nupkg --source "github"
was leading to warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/ORGANIZATION_NAME'. To save an API Key for a source use the 'setApiKey' command.
for me.
My nuget.config
file is the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="%GITHUB_USERNAME%" />
<add key="ClearTextPassword" value="%GITHUB_TOKEN%" />
</github>
</packageSourceCredentials>
</configuration>
Hi @jwillmer,
You should find the following works fine now:
- name: Publish Nuget to GitHub registry
run: dotnet nuget push ./MyNugetPackage.3.4.24.nupk -k ${GITHUB_TOKEN} -s https://nuget.pkg.github.com/USERNAME/index.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Support for the dotnet nuget push --api-key
option has now been added to GitHub Packages. For some reason this works consistently, but using basic auth (password in nuget.config
file) fails randomly!
@jcansdale I referenced your solution on stackoverflow: How to push nuget package in GitHub actions
@jwillmer,
Thanks for the heads up!
BTW, your example workflow can now look like this (no need for source-url
in setup-dotnet
):
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
- name: Build solution and generate NuGet package
run: |
cd <project>
dotnet pack -c Release -o out
- name: Push generated package to GitHub registry
run: dotnet nuget push ./<project>/out/*.nupkg --source https://nuget.pkg.github.com/<owner> --api-key ${{github.token}} --skip-duplicate --no-symbols true
Most helpful comment
So I've tried everything.. I've been in all the posts and all the issue threads and there is just no way to get this to work without applying some good old fashioned brute force 馃敤馃敤馃敤
The following is the only thing that works for me, without having to re-run the job.
It might urk some but at this point I don't care.