This document provides a complete overview of the GitHub Actions setup for automated npm publishing.
- Trigger: When a GitHub release is published
- Purpose: Automated npm publishing
- Features:
- Tests on multiple Node.js versions (16, 18, 20)
- Version consistency check between git tag and package.json
- Automated npm publish after successful tests
- Trigger: Pull requests and pushes to main/master
- Purpose: Continuous integration
- Features:
- Multi-version Node.js testing
- Linting and formatting checks
- Code coverage reporting
- Enhanced description and metadata
- Proper repository configuration
- Comprehensive keywords for discoverability
- File inclusion/exclusion for npm package
- Node.js version requirements
- Excludes development files from npm package
- Keeps only essential files for end users
- Reduces package size
- Comprehensive library documentation
- Usage examples and API overview
- Development and publishing instructions
- Detailed publishing workflow guide
- Setup instructions for maintainers
- Troubleshooting guide
- Version history tracking
- Follows Keep a Changelog format
- Ready for automated updates
-
Create NPM Account
# Visit https://www.npmjs.com/ and create account -
Generate NPM Token
# Go to https://www.npmjs.com/settings/tokens # Create "Automation" token
-
Add GitHub Secret
# Repository Settings → Secrets → Actions # Add secret: NPM_TOKEN = your_npm_token
-
Update Version
npm version patch # or minor/major git push -
Create GitHub Release
- Go to GitHub repository
- Releases → Create new release
- Tag:
v1.0.1(matching package.json) - Publish release
-
Automatic Publishing
- GitHub Action runs automatically
- Tests pass → Package published to npm
- Monitor in Actions tab
-
Multi-Version Testing
- Runs tests on Node.js 16, 18, 20
- Ensures compatibility across versions
-
Version Validation
- Checks git tag matches package.json version
- Prevents version mismatches
-
Build & Publish
- Builds TypeScript to JavaScript
- Publishes to npm registry
-
Code Quality
- ESLint for code quality
- Prettier for formatting
- TypeScript compilation
-
Testing
- Unit tests with AVA
- Coverage reporting
- Multi-Node.js version support
ream.js/
├── .github/workflows/ # GitHub Actions
├── build/ # Compiled output (published)
├── src/ # Source code (not published)
├── package.json # Package configuration
├── .npmignore # NPM exclusions
├── README.md # Main documentation
├── CHANGELOG.md # Version history
└── PUBLISHING.md # Publishing guide
- Use "Automation" tokens for CI/CD
- Store as GitHub repository secret
- Never commit tokens to code
- Follow semantic versioning
- Update CHANGELOG.md for each release
- Test thoroughly before releasing
- All tests must pass before publishing
- Code quality checks enforced
- Multi-Node.js version compatibility
- GitHub repository → Actions tab
- View logs for failed runs
- Monitor npm package page
- Version Mismatch: Ensure git tag matches package.json
- Test Failures: Fix tests before creating release
- NPM Token: Verify secret is set correctly
- Package Name: Ensure unique name on npm
✅ Automated Publishing: No manual npm publish commands ✅ Quality Assurance: Tests run before every publish ✅ Version Safety: Prevents version mismatches ✅ Multi-Platform: Tests on multiple Node.js versions ✅ Documentation: Comprehensive guides for maintainers ✅ Security: Secure token management via GitHub secrets
The setup is now complete and ready for automated npm publishing! 🚀