Open utterances-bot opened 1 year ago
Thanks for this useful tip. I expect you will find that the GraphQL no longer works once they move the maven packages under the newer package infrastructure that both npm and Nuget are under. It brings other benefits, but it broke a script I was using to download nuget packages. I switched the script to use the REST API but then found the same as you, I couldn't use that to download the package anymore.
Your post inspired me to look into other ways and I found that the URL for downloading NuGet packages is:
Ahh, fantastic, thank you for providing this @mungojam! 🎉
I'll have to update the post, but here are additional examples of downloading packages in packages v2.
Note Even if you are referencing public packages, you still need to provide a (classic) PAT
curl -H "Authorization: token ghp_xyz" -L -O \
https://maven.pkg.github.com/joshjohanning-org/download/com/sherlock/herokupoc/1.0.0-202202122241/herokupoc-1.0.0-202202122241.jar
curl -H "Authorization: token ghp_xyz" -L -O \
https://nuget.pkg.github.com/joshjohanning-org/download/Wolfringo.Hosting/1.1.1/Wolfringo.Hosting.1.1.1.nupkg
npm must work a bit differently; the download URL is different
# get package versions
version="0.0.3"
token="ghp_xyz"
org="joshjohanning-org"
package_name="npm-package-example"
# get url
url=$(curl -H "Authorization: token $token" -Ls https://npm.pkg.github.com/@$org/$package_name | jq --arg version $version -r '.versions[$version].dist.tarball')
# download
curl -H "Authorization: token $token" -L -o $package_name-$version.tgz $url
curl -H "Authorization: token ghp_xyz" -L -O \
https://rubygems.pkg.github.com/$org/gems/packages-migration-demo-0.2.0.gem
I'll have to update the post, but here are additional examples of downloading packages in packages v2.
I finally got around to updating the post!
And added Rubygems as well 😄
Very helpful. Thanks Josh.
Programmatically Download a Package Binary from GitHub Packages | josh-ops
Programmatically download a package binary (such as NuGet, Maven) from GitHub Packages
https://josh-ops.com/posts/github-download-from-github-packages/