1

I am using GitHub packages to publish my private NPM packages. I need to download the published package of specific version for carrying out automation work. How can I download the package as a zip bundle using GitHub REST API or equivalent? Additionally, since it is a private package, it needs to be authenticated.

I know that equivalent functionality exists but it works for GitHub releases and assets. I could not find anything yet for GitHub packages!

Harshal Patil
  • 17,838
  • 14
  • 60
  • 126
  • When you say a zip bundle, are you specifically trying to retrieve the package contents as a compressed zipped folder with a `.zip` file extension? Because I was under the impression the only accessible assets from an npm package published via GitHub packages, private or otherwise, would be a `.tgz`. – killshot13 Oct 24 '21 at 14:46
  • `zip` or `.tgz` - anything is fine as long as I can download it. – Harshal Patil Oct 24 '21 at 14:53

1 Answers1

0

After a few days of intermittent research regarding this question, here is what I have found. There seem to be two methods of retrieving and/or consuming privately published NPM packages from the GitHub Package Registry. And neither of them is an exact match to your desired method, so, here goes...

OPTION 1.

You can consume the npm package directly within your application provided you have a locally configured .nprmc file on your machine in your user directory (check first @~/.npmrc), AND you have created a GitHub personal access token with the following scopes.

  • repo: full (this is how you will be authenticated.)
  • workflow
  • write: packages
  • adminOrg: read
  • user: email

NOTE: You may not require all of these, but these are the permissions I used and had no issues. Once you generate the token, create or add it to your .npmrc file like so, replacing TOKEN with the actual token value.

//npm.pkg.github.com/:_authToken=TOKEN

Be sure you additionally add the following snippet into the project or container itself within another .npmrc file in the root directory of the codebase.

@YOUR_GITHUB_USERNAME:registry=https://npm.pkg.github.com

OPTION 2:

You can connect your package to a private GitHub repository, which will allow you to access the tar.gz artifact for each version of your package and directly download it to your local machine from the web.

github.com > Your profile > Packages > Connect repository > Select and link.

An npm package that has been published to the GitHub Package Registry AND linked to a GitHub repository will allow the owner to download the package artifacts as a .tar file.


REFERENCE: How to publish packages to the GitHub Package Registry

killshot13
  • 186
  • 1
  • 4
  • 14