How to download a JAR from Github Package Registry for a specific Release version

6k Views Asked by At

Goal

I want to have two repositories:

  • Repository A: Publishes a JAR to Github Registry

  • Repository B: Downloads the JAR from A and publishes a Docker Image containing the JAR.


I.e. I'm searching for an API which looks like:

wget https://github.com/repoOwner/repoName/packages/1.2.3/my.jar

Question

Is there a Github Action or API which allows me to download an artifact from a Github Package Registry for a specific version?

Problem

I know there is a Github API for the artifacts but I don't see how I can request the artifact URL for a specific version.

2

There are 2 best solutions below

5
On BEST ANSWER

To Download the JAR from the Github Package Registry use this URL:

https://maven.pkg.github.com/OWNER/REPO/PACKAGE/VERSION/ARTIFACT.jar
  • Authenticate with your personal developer token and account name
    • For public repositories the token does not need special permissions
    • For private repositories the token only needs package:read permission
  • Replace OWNER with the Github account name of the repository owner
  • Replace REPO with the repository name
  • Replace PACKAGE with the group id you published
  • Replace VERSION with the artifact version you published
  • Replace ARTIFACT with the artifact id you published

E.g. for this Package, were only a pom file is published:

https://maven.pkg.github.com/abrensch/brouter/org/btools/brouter/1.6.1/brouter-1.6.1.pom
0
On

@hb0 answer is great and helped me a lot.

I will just add my experience, maybe it can help someone else.

I was trying to download the jar file with this command:

curl -O --header "Authorization: Bearer $MYSECRETTOKEN" https://maven.pkg.github.com/myorg/myrepo/com/org/mypackage/1.0.0/mypackage-1.0.0.jar

But it was returning:

Moved Permanently

Then I had to change the command to:

curl -O -L https://_:[email protected]/myorg/myrepo/com/org/mypackage/1.0.0/mypackage-1.0.0.jar

where $MYSECRETTOKEN is an environment var with github token as you probably guessed.