Pushing Tags to NPM
This guide explains how to publish your package versions to npmjs.com by pushing git tags.
Quick Startโ
1. Create and Push a Git Tagโ
# Create a version tag (e.g., v2.1.16)
git tag v2.1.16
# Push the tag to GitHub
git push origin v2.1.16
2. Automatic Publishingโ
When you push a tag matching the pattern v* (e.g., v2.1.16), the GitHub Actions workflow automatically:
- โ Runs all tests and linting
- โ Builds the project
- โ Verifies package structure
- โ Publishes to npmjs.com
- โ
Sets appropriate npm dist-tags (
latestfor stable,betafor prereleases) - โ Creates/updates GitHub release
How It Worksโ
Workflow Triggerโ
The .github/workflows/publish.yml workflow is triggered when:
- Tag push: Any tag matching
v*pattern is pushed to GitHub - Manual dispatch: You can manually trigger via GitHub Actions UI
- Workflow call: Called from other workflows
Version Detectionโ
The workflow automatically:
- Extracts version from the git tag (removes
vprefix) - Updates
package.jsonversion if needed - Publishes with the correct npm dist-tag
NPM Dist-Tagsโ
- Stable versions (e.g.,
v2.1.16): Published withlatesttag - Prerelease versions (e.g.,
v2.1.16-beta.1): Published withbetatag
Examplesโ
Publishing a Patch Versionโ
# Current version: 2.1.15
git tag v2.1.16
git push origin v2.1.16
Publishing a Minor Versionโ
# Current version: 2.1.15
git tag v2.2.0
git push origin v2.2.0
Publishing a Major Versionโ
# Current version: 2.1.15
git tag v3.0.0
git push origin v3.0.0
Publishing a Prereleaseโ
# Beta release
git tag v2.1.16-beta.1
git push origin v2.1.16-beta.1
Verificationโ
After pushing a tag, you can verify publication:
Check GitHub Actionsโ
- Go to your repository's Actions tab
- Find the "Publish to NPM" workflow run
- Verify all steps completed successfully
Check NPM Registryโ
# View package versions
npm view mcp-adr-analysis-server versions
# View dist-tags
npm view mcp-adr-analysis-server dist-tags
# Check specific version
npm view mcp-adr-analysis-server@2.1.16
Check Package Pageโ
Visit: https://www.npmjs.com/package/mcp-adr-analysis-server
Troubleshootingโ
Tag Not Publishingโ
- Check tag format: Must start with
v(e.g.,v2.1.16) - Verify workflow trigger: Check Actions tab for workflow run
- Check NPM_TOKEN: Ensure
NPM_TOKENsecret is set in GitHub - Review workflow logs: Check for errors in the workflow run
Version Already Existsโ
If a version already exists on npm, the publish will fail. Options:
- Use a different version: Increment to next version
- Unpublish (if recently published):
npm unpublish mcp-adr-analysis-server@2.1.16- Note: Unpublishing is only allowed within 72 hours
Missing NPM Tokenโ
If you see authentication errors:
- Generate an npm access token:
- Go to https://www.npmjs.com/settings/tokens
- Create "Automation" token
- Add to GitHub Secrets:
- Repository โ Settings โ Secrets and variables โ Actions
- Add secret named
NPM_TOKEN
Manual Publishing (Alternative)โ
If you need to publish manually without using git tags:
# Update version in package.json
npm version patch # or minor, major
# Build and publish
npm run build
npm publish
Best Practicesโ
- Semantic Versioning: Follow semver (major.minor.patch)
- Tag Before Push: Create tag locally, review, then push
- Test Locally: Run
npm run test:packagebefore tagging - Changelog: Update CHANGELOG.md before creating release
- Release Notes: Use GitHub Releases for detailed notes