UK based website and application support - contact form.

Blog.

Use Git to release code just like NPM

Cover Image for Use Git to release code just like NPM

Why use GutHub Packages?

GitHub Packages makes it easy to store and share dependencies right in your GitHub repo, so everything’s in one place. It’s especially useful for private projects, letting you control who can access what with your existing GitHub permissions.

Setup process

GitHub Action

To setup releses in your github repository, you need to create a github action. This action will be triggered when you create a new release. The action will publish the package to your github's package registry.

Action is really simple and you can find it in the github documentation. Note that registry-url field uses https://npm.pkg.github.com/ instead of npm.

Your action should be saved in npm-publish-github-packages.yml file.

name: <PACKAGE_NAME>

on:
  release:
    types: [created]

jobs:
  publish-gpr:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v3
        with:
          node-version: 18
          registry-url: https://npm.pkg.github.com/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

Modify package.json

One important note is to remember to include your guthub's username in "name" of your package. This is because github will use this name to create a package in your github's package registry.

When you publish a new release, github will trigger the github actions and publish the package to your github's package registry.

You will be able to use this package in your other projects.

{
  "name": "@<GITHUB_USER>/<PACKAGE_NAME>",
  "version": "1.0.27",
  ...
}

How to use it?

To install github's package in other projects use npm install as usual but again remember to include your github's username in the package name.

If your repository is private you'll also be prompted to enter your github's authorization token.

export GITHUB_PAT_TOKEN="ghp_****"

GitHub Releases Package Install Error

Conclusion

GitHub Packages simplifies package management by keeping everything close to your codebase and integrates smoothly with GitHub’s existing workflows. For private repositories, it’s a straightforward way to share and secure dependencies, all while supporting a variety of formats for flexible development needs.

← Back to homepage

Looking for website and application support in the Midlands? I specialize in providing comprehensive website maintenance and support services.
Whether you need hosting solutions, web application development, security updates, or assistance with in-house or remote teams, I can help.

My expertise covers React, Next.js, JavaScript, TypeScript, Web Components, Lit, Stencil.js, Node.js, RESTful APIs, Docker, Kubernetes, and Amazon Web Services.

Get in touch!