Skip to content

feat: automate npm publish to npmjs on version bump via GitHub Actions #3

Description

@qa-ashutosh

Summary

Right now publishing to npm is a manual step. Any version bump should automatically trigger a release and publish to npmjs, no manual npm publish needed.

Proposed flow

  1. Dev bumps version locally: npm version patch | minor | major
  2. That creates a git tag (e.g. v1.1.0) and a commit
  3. git push --follow-tags pushes both
  4. GitHub Actions detects the new tag, runs CI, and publishes to npm

Implementation

Add a new workflow file .github/workflows/release.yml:

name: Release

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '20.x'
          registry-url: 'https://registry.npmjs.org'

      - run: npm ci
      - run: npm run build
      - run: npm test

      - run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Secret to add

In GitHub repo Settings → Secrets → Actions, add:

  • NPM_TOKEN — generate from npmjs.com under Access Tokens (choose Automation type)

Usage after setup

npm version patch   # bumps 1.0.0 → 1.0.1, creates tag v1.0.1
git push --follow-tags
# GitHub Actions takes it from here

Acceptance criteria

  • .github/workflows/release.yml added
  • NPM_TOKEN secret documented in CONTRIBUTING.md
  • Publish only runs after build and tests pass (no broken releases)
  • Works for patch, minor, and major bumps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions