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

Programmatically Download a Package Binary from GitHub Packages | josh-ops #22

Open
utterances-bot opened this issue Dec 17, 2022 · 9 comments

Comments

@utterances-bot
Copy link

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/

Copy link

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:

https://nuget.pkg.github.com/{org-or-user}/download/{package.name}/{package.version}/{package.name}.{package.version}.nupkg

@joshjohanning
Copy link
Owner

Ahh, fantastic, thank you for providing this @mungojam! 🎉

@joshjohanning
Copy link
Owner

joshjohanning commented May 8, 2023

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

Maven

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

NuGet

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

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

RubyGems

curl -H "Authorization: token ghp_xyz" -L -O \
  https://rubygems.pkg.github.com/$org/gems/packages-migration-demo-0.2.0.gem

@github-actions github-actions bot added the stale label Aug 19, 2023
Repository owner deleted a comment from github-actions bot Aug 19, 2023
Repository owner deleted a comment from mungojam Dec 11, 2023
@joshjohanning
Copy link
Owner

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 😄

Copy link

Very helpful. Thanks Josh.

Copy link

Saved my day. Thank you

Copy link

I had my github packed pushed to remote and now I am trying to use it in my application and added it under dependencies in my build.gradle file but however after giving the github username and pswd details when doing build it says that the username is null. Is there a way to resolve this.

Copy link

something like this
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("username")
password = project.findProperty("gpr.token") ?: System.getenv("token")
}

@joshjohanning
Copy link
Owner

I had my github packed pushed to remote and now I am trying to use it in my application and added it under dependencies in my build.gradle file but however after giving the github username and pswd details when doing build it says that the username is null. Is there a way to resolve this.

something like this
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("username")
password = project.findProperty("gpr.token") ?: System.getenv("token")
}

I'm certainly not a gradle expert! But Did you end up figuring this out @niharikaganji29?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants