-
Notifications
You must be signed in to change notification settings - Fork 2
Automated NPM publishing via GitHub Actions with semver #41
Description
Summary
Set up automated NPM publishing on every merge to main, using GitHub Actions and semantic versioning.
Problem
Currently there is no automated publish pipeline. Publishing is manual, error-prone, and version bumps are ad-hoc.
Requirements
- Every merge to
maintriggers an NPM publish of changed packages - Versions follow semver (major / minor / patch)
- Works with the existing Lerna monorepo (publishes only changed packages)
- GitHub Actions-based
Key Design Decision: How to Determine Semver Bump
This is the core question to resolve. Leading approaches:
Option A — Conventional Commits + automated detection
Use Conventional Commits to encode intent in commit messages:
fix:→ patchfeat:→ minorfeat!:/BREAKING CHANGE:→ major
Tools like Lerna (with --conventional-commits), changesets, or semantic-release can parse these and auto-bump versions.
Option B — Changesets
Use @changesets/cli — developers add a "changeset" file per PR describing the bump type. A GitHub Action consumes these on merge.
Option C — Manual version bump in PR
Developer explicitly bumps package.json version in the PR. CI just publishes whatever version is in the package.
Recommendation: Evaluate Options A and B. Conventional Commits + Lerna's built-in support is the lowest-friction path given we already use Lerna, but Changesets is the most popular choice in the JS ecosystem for monorepos.
Implementation Scope
- Research & decide on the versioning strategy (A, B, or C above)
- Enforce commit conventions (if Option A) — add commitlint + husky, or a CI check
- Create GitHub Actions workflow that:
- Triggers on push/merge to
main - Builds & tests all packages
- Determines version bumps
- Publishes changed packages to NPM
- Triggers on push/merge to
- Set up NPM token as a GitHub Actions secret (
NPM_TOKEN) - Handle monorepo — only publish packages that actually changed
- Tag releases in git (e.g.
@dcb-es/event-store@1.2.3)
Acceptance Criteria
- Merging to
mainautomatically publishes changed packages to NPM - Version bumps follow semver based on the chosen strategy
- Only changed packages are published (not the whole monorepo)
- Git tags created for each release
- Failed builds/tests block publishing
- Process documented in README or CONTRIBUTING.md