Publishing Packages to GitHub Packages with GitHub Actions
This guide explains how to use GitHub Packages as a unified package registry and demonstrates step‑by‑step how to configure npm, create a workflow file, and automatically publish a Node.js package to GitHub Packages via GitHub Actions whenever a new release is created.
GitHub Packages is a platform for hosting and managing packages, including container images, that integrates with source code, permissions, and billing on GitHub.
It supports registries for common package managers such as npm, RubyGems, Maven, Gradle, Docker, and NuGet, with a dedicated container registry optimized for Docker and OCI images.
The article lists language‑specific package formats and clients (e.g., JavaScript → package.json via npm, Ruby → Gemfile via gem, Java → pom.xml via mvn, etc.).
To publish a Node.js package to GitHub Packages, follow these steps:
Create a repository and clone it locally.
Add a test index.js file.
Initialize the npm package with npm init , using a scoped name like @YOUR-USERNAME/YOUR-REPOSITORY .
Run npm install to generate package-lock.json , commit and push the changes.
Create a workflow file .github/workflows/release-package.yml that triggers on a release event, builds the package, and publishes it using the npm publish command with the appropriate authentication token.
Add a .npmrc file in the repository root containing @YOUR-USERNAME:registry=https://npm.pkg.github.com and set the publishConfig field in package.json to point to the same registry.
Commit the workflow and configuration files and push them; the workflow will run automatically on each new release, publishing the package to GitHub Packages if tests pass.
Images in the original article illustrate the process and promote the DevOps Cloud Academy.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.