This comprehensive guide covers the CI/CD pipeline for the Dataproc MCP Server, including automated testing, quality gates, release management, troubleshooting, and best practices.
ALWAYS run this before any git operations:
npm run pre-pushThis command runs ALL CI checks locally:
- Build compilation
- ESLint validation
- Prettier formatting check
- TypeScript type checking
- Unit tests
- Security audit
- Package validation
- Documentation link testing
Benefits:
- β Prevents CI failures by catching issues locally
- β Builds developer confidence
- β Maintains quality gates
- β Saves time and resources
When using semantic-release with automated versioning, CI/CD runs will often create new commits and tags on the main branch. This means your local branch can quickly become "behind" the remote, even if you just pushed. This is normal and expected with automated release workflows.
git push origin main
# β Error: Updates were rejected (fetch first)
git pull --rebase
# β
Success: Pulls semantic-release commits/tags
git push origin main
# β
Success: Now pushes your changes-
Always Pull Before Push (Recommended):
# Before making changes git pull --rebase # Make your changes, commit git add . git commit -m "feat: your changes" # Pull again before push (in case CI ran while you worked) git pull --rebase git push origin main
-
Configure Git Auto-rebase:
git config pull.rebase true git config rebase.autoStash true # Now git pull will automatically rebase git pull # equivalent to git pull --rebase
-
Automation Tip: Add this alias to your
.gitconfig:git config alias.sync "!git pull --rebase && git push"Then use:
git syncinstead of separate pull/push commands. -
Force Push (Not Recommended):
# Only use if you're sure no one else is working on main git push --force-with-lease origin main
- Always run
npm run pre-pushbefore any git operations. - Pull before starting work on a new feature.
- Pull before pushing to catch any CI updates.
- Use
--rebaseto maintain clean history. - Monitor CI/CD runs to understand when semantic-release creates commits.
- Developer commits with conventional commit message.
- CI/CD runs tests, builds, and semantic-release.
- Semantic-release creates new version commit + tag.
- NPM package published automatically.
- Developer needs to pull these automated commits.
Expected Version Bumps:
- Patch: v1.0.0 β v1.0.1 (fixes)
- Minor: v1.0.1 β v1.1.0 (features)
- Major: v1.1.0 β v2.0.0 (breaking changes)
This pattern is by design and indicates a healthy CI/CD pipeline! π
The CI/CD pipeline provides:
- π Pre-flight Checks - Intelligent change detection and dependency sync
- π‘οΈ Quality Gates - Code quality, security scanning, and coverage checks
- π§ͺ Automated Testing - Unit, integration, and end-to-end tests across Node.js versions
- π Documentation - Auto-generated docs and validation
- π¦ Build Artifacts - Production-ready distributions
- π Release Automation - Semantic versioning and automated publishing
- π Security Scanning - Dependency vulnerabilities and code analysis
graph TD
A[π Push/PR Trigger] --> B[π Pre-flight Checks]
B --> C{π Changes Detected?}
C -->|Yes| D[π Quality Gates Matrix]
C -->|No| Z[βοΈ Skip Pipeline]
D --> D1[π¦ Node.js 18]
D --> D2[π¦ Node.js 20]
D --> D3[π¦ Node.js 22]
D1 --> E1[π¨ Build & Lint]
D2 --> E2[π¨ Build & Lint]
D3 --> E3[π¨ Build & Lint]
E1 --> F[π Security Scan]
E2 --> F
E3 --> F
F --> G[π§ͺ Integration Tests]
G --> H[π Documentation]
F --> I[π¦ Build Artifacts]
G --> I
H --> I
I --> J[π Pipeline Summary]
J -->|Main Branch| K[π Release Pipeline]
K --> L[π Release Validation]
L --> M[π¦ Semantic Release]
M --> N[π€ NPM Publish]
N --> O[π GitHub Release]
O --> P[β
Post-Release Validation]
style A fill:#e1f5fe
style K fill:#c8e6c9
style N fill:#4caf50
style P fill:#2e7d32
- Purpose: Intelligent change detection and optimization
- Actions:
- Checkout repository with full history
- Detect file changes (
.ts,.js,.json,package.json, workflows) - Determine if tests/security scans are needed
- Set conditional flags for downstream jobs
- Purpose: Multi-version testing and code quality validation
- Matrix Strategy: Node.js 18, 20, 22
- Actions:
- π¦ Install dependencies with caching
- π¨ TypeScript compilation (
npm run build) - π§Ή ESLint validation (
npm run lint:check) - π
Prettier formatting check (
npm run format:check) - π TypeScript type checking (
npm run type-check)
- Purpose: Vulnerability detection and security validation
- Actions:
- π‘οΈ NPM audit with audit-ci integration
- π Dependency vulnerability scanning
- π Security report generation
β οΈ Fail on high/critical vulnerabilities
- Purpose: Comprehensive testing with coverage reporting
- Actions:
- π§ͺ Unit tests (
npm test) - π Coverage generation (
npm run test:coverage) - π€ Codecov upload with detailed reporting
- β
Coverage threshold validation (
npm run test:coverage:check)
- π§ͺ Unit tests (
- Purpose: Documentation generation and validation
- Actions:
- π Documentation generation (
npm run docs:generate) - π Link validation (
npm run docs:test-links) - π Example validation (
npm run validate:examples) - π€ Artifact upload for GitHub Pages
- π Documentation generation (
- Purpose: Production build and asset preparation
- Actions:
- π¨ Clean build (
npm run build:clean) - π¦ Standalone build (
npm run build:standalone) - ποΈ Template generation (
npm run build:templates) - π€ Artifact upload for releases
- π¨ Clean build (
- Purpose: Comprehensive status reporting
- Actions:
- π Generate status table with all job results
- π Create GitHub step summary
- π― Report success/failure status
The release pipeline now automatically triggers when PRs are merged to main branch with enhanced commit analysis.
- Purpose: Pre-release checks with improved commit detection
- β¨ NEW FEATURES:
- π Enhanced conventional commit analysis - Detects commits in PR merges
- π Squashed merge support - Handles GitHub's squash and merge commits
- π₯ Breaking change detection - Analyzes commit bodies for BREAKING CHANGE
- π Intelligent commit range analysis - Improved commit history parsing
- Actions:
- π Multi-pattern commit validation (feat, fix, perf, revert, BREAKING)
- π Release readiness check with enhanced logic
- π― Automatic release type determination (patch/minor/major)
- π Detailed commit logging for debugging
- Purpose: Automated versioning with improved commit parsing
- β¨ NEW FEATURES:
- π― Improved version calculation based on enhanced commit analysis
- π Better changelog generation with conventional commit categorization
- π PR merge commit handling for accurate version bumping
- Actions:
- π·οΈ Smart version calculation based on conventional commits
- π Comprehensive changelog generation with emoji categorization
- π― Git tag creation with proper versioning
- π¦ Production package preparation
- Purpose: Seamless public package distribution on PR merge
- β¨ NEW FEATURES:
- π Automatic publishing triggered by PR merges
- π Enhanced publication verification with retry logic
- π Improved error handling and notifications
- Actions:
- π€ Publish to npm registry (
@dipseth/dataproc-mcp-server) - π Publication verification with availability checks
- π Download statistics tracking and monitoring
- π€ Publish to npm registry (
- Purpose: Comprehensive GitHub release creation with assets
- β¨ NEW FEATURES:
- π Improved release notes with conventional commit categorization
- π Enhanced asset management with build artifacts
- π Better cross-referencing between NPM and GitHub releases
- Actions:
- π Create GitHub release with detailed notes
- π Attach comprehensive build artifacts
- π Generate categorized release notes with emojis
- Purpose: Comprehensive release verification and monitoring
- β¨ NEW FEATURES:
- π§ͺ Installation testing with multiple scenarios
- π Enhanced metrics collection and reporting
- π Improved notification system with detailed summaries
- Actions:
- π NPM package availability check with retry logic
- π¦ Comprehensive installation testing in clean environments
- π Release metrics collection and success tracking
- π Success notifications with package links and installation commands
- Location:
tests/unit/ - Coverage: TypeScript source files
- Types:
- Resource handlers testing
- Default parameters validation
- Profile configuration testing
- Validation schema testing
- Location:
tests/manual/ - Coverage: End-to-end workflows
- Types:
- Authentication methods testing
- MCP resource testing
- Job output handling
- Cluster management flows
- Minimum: 90% lines, functions, branches, statements
- Reporting: Codecov integration
- Enforcement: Pipeline fails if coverage drops below threshold
Golden Command (Recommended):
npm run pre-pushIndividual Commands:
# Build and compile
npm run build
# Code quality
npm run lint:check
npm run format:check
npm run type-check
# Testing
npm run test:unit:fast
npm test
# Security
npm run security:check
# Package validation
npm run validate-package
# Documentation
npm run docs:test-linksFor intelligent change detection:
npm run pre-flightBefore creating releases:
npm run ci-cd:validate- Problem: Corrupted Unicode character causing JSON parsing errors
- Solution: Fixed corrupted emoji in CI workflow
- Prevention: Use proper UTF-8 encoding in all workflow files
- Problem:
npm cifailing due to package.json/package-lock.json mismatch - Solution:
- Added dependency sync check job
- Implemented fallback to
npm installwhennpm cifails - Updated package-lock.json with
npm install --package-lock-only
- Prevention: Always run
npm installafter dependency changes
- Problem: TypeScript 5.8.3 vs ESLint TypeScript support (5.4.0 max)
- Solution: Updated dependencies and added compatibility warnings
- Note: ESLint warnings are non-blocking but should be addressed
- Problem:
tsconfig.jsonincluded explicit types that weren't available in fresh CI installs - Root Cause: CI environment differences - local had cached types, CI had fresh install
- Solution: Removed explicit
typesarray entirely, letting TypeScript use default behavior - Why Local Missed It: Local
node_moduleshad cached type definitions that CI didn't have - Prevention: Test with fresh installs:
rm -rf node_modules package-lock.json && npm install && npm run build - Status: β RESOLVED - CI now matches local environment exactly
Critical for preventing CI failures that local testing misses:
# Clean install (matches CI behavior exactly)
rm -rf node_modules package-lock.json
npm install
# Or use npm ci (requires existing lock file)
npm ci
# Test in clean environment
npm run pre-pushWhy Environment Differences Occur:
- Local
node_modulesmay have cached/different versions - CI always starts with fresh installs
- TypeScript type definitions can vary between installs
- Development vs production dependency differences
# 1. Check dependency sync
npm install --package-lock-only
# 2. Clear cache and reinstall (matches CI environment)
rm -rf node_modules package-lock.json
npm install
# 3. Run golden command locally
npm run pre-push
# 4. Check specific issues
npm run build
npm run lint:check
npm run type-check# Run specific test suites
npm run test:unit
npm run test:unit:fast
npm run test:integration
# Debug with verbose output
npm test -- --verbose
# Check coverage
npm run test:coverage
npm run test:coverage:check# Run security audit
npm run security:check
npm audit
# Fix vulnerabilities
npm audit fix
# Check specific audit level
npm audit --audit-level moderate# Regenerate documentation
npm run docs:generate
npm run docs:api
# Update documentation with current version
npm run docs:update
# Test links
npm run docs:test-links
# Validate examples
npm run validate:examples# Validate package
npm run validate-package
# Test package creation
npm pack --dry-run
# Check package contents
npm pack
tar -tzf *.tgzThe release workflow now automatically updates all documentation when a new version is published:
- β README.md - Version badges and installation commands
- β
Documentation files - All
.mdfiles with package references - β
Configuration files -
docs/_config.ymland package metadata - β
Package info - Creates
docs/package-info.jsonwith release details - β NPM metadata - Homepage, repository URLs, and keywords
graph LR
A[π Semantic Release] --> B[π Update Documentation]
B --> C[πΎ Commit Changes]
C --> D[β
Post-Release Validation]
You can also update documentation locally:
# Update all documentation with current version
npm run docs:update
# What it updates:
# - README.md version badges and installation commands
# - All documentation files with package references
# - Configuration files and metadata
# - Package information JSON file- Smart version detection - Reads current version from package.json
- Comprehensive updates - Updates all references across the project
- Safe operations - Only updates when changes are detected
- Detailed logging - Shows exactly what was updated
- Git integration - Commits changes with
[skip ci]to prevent loops
The CI/CD pipeline now automatically publishes new versions when PRs are merged to main branch. Here's how it works:
# Create feature branch
git checkout -b feat/new-feature
# Always run golden command before committing
npm run pre-push
# Use conventional commits
git commit -m "feat: add cluster auto-scaling support"
# Push and create PR
git push origin feat/new-featureWhen a PR is merged to main, the enhanced release workflow:
- β Detects conventional commits in the merge
- β Analyzes commit types (feat, fix, perf, BREAKING CHANGE)
- β Determines version bump automatically
- β Publishes to NPM if changes warrant a release
- β Creates GitHub release with changelog
- β Validates publication success
The workflow now intelligently detects:
- Conventional commits in PR titles and descriptions
- Squashed merge commits with conventional format
- Breaking changes in commit bodies
- Multiple commit types in a single PR
# Feature additions (minor version bump)
git commit -m "feat: add cluster auto-scaling support"
# Bug fixes (patch version bump)
git commit -m "fix: resolve memory leak in job monitoring"
# Breaking changes (major version bump)
git commit -m "feat!: redesign authentication API"
# Performance improvements (patch version bump)
git commit -m "perf: optimize query response time"
# Documentation (no version bump)
git commit -m "docs: add troubleshooting guide"
# Chores/CI (no version bump)
git commit -m "ci: enhance release workflow detection"The npm run pre-push command now includes release validation:
npm run pre-push
# Now includes: build, lint, format, type-check, tests, security,
# package validation, docs, AND release:dry validationgraph TD
A[π PR Merged to Main] --> B[π Enhanced Commit Analysis]
B --> C{π Conventional Commits Found?}
C -->|Yes| D[π Determine Version Bump]
C -->|No| E[βΉοΈ Skip Release]
D --> F[π¨ Build & Test]
F --> G[π¦ Semantic Release]
G --> H[π€ NPM Publish]
H --> I[π GitHub Release]
I --> J[β
Post-Release Validation]
J --> K[π’ Success Notification]
# Create release branch
git checkout -b release/v1.2.3
# Update version
npm version 1.2.3 --no-git-tag-version
# Validate before commit
npm run pre-push
# Commit and push
git commit -am "chore(release): 1.2.3"
git push origin release/v1.2.3
# Create PR to main- Package Name:
@dataproc/mcp-server - Current Version:
2.0.0 - Registry: https://registry.npmjs.org/ (Public)
- Access: Public
- License: MIT
- Automated versioning based on conventional commits
- Changelog generation with emoji categorization
- GitHub releases with compiled assets
- NPM publishing with proper dist-tags
- Git tagging with version tags
NPM_TOKEN secret to publish packages.
-
Create NPM Access Token:
npm login
- Go to npmjs.com β Account Settings β Access Tokens
- Generate "Automation" token
- Copy the token
-
Add GitHub Secret:
- Repository β Settings β Secrets and variables β Actions
- New repository secret:
NPM_TOKEN - Paste your npm token
- Save
-
Verify Setup:
- Push a commit with conventional format to main branch
- Watch the release workflow execute
- Verify package appears on npm registry
- Weekly dependency scans - Automated vulnerability detection
- Code security analysis - SAST scanning integration
- Secret scanning - Prevents credential leaks
- Supply chain security - Package integrity verification
- β Use conventional commit format
- β Keep commits atomic and focused
- β Write descriptive commit messages
- β Reference issues when applicable
- β
Always run
npm run pre-pushbefore committing
- β
Create feature branches from
main - β Keep PRs small and focused
- β Include tests for new features
- β Update documentation as needed
- β Ensure all CI checks pass
- β
Run
npm run pre-pushlocally first
- β Maintain β₯90% test coverage
- β Write tests before implementing features (TDD)
- β Use descriptive test names
- β Mock external dependencies
- β Test both success and error scenarios
- β Never commit secrets or credentials
- β Use environment variables for configuration
- β Keep dependencies updated
- β Review security scan results
- β Follow principle of least privilege
Required secrets in GitHub repository settings:
# NPM Publishing
NPM_TOKEN=your_npm_token
# Code Coverage (optional)
CODECOV_TOKEN=your_codecov_token
# GitHub Token (automatically provided)
GITHUB_TOKEN=automatically_providedConfigure for main branch:
Required status checks:
- π Pre-flight Checks
- π Dependency Sync Check
- π Quality Gates (Node 18)
- π Quality Gates (Node 20)
- π Quality Gates (Node 22)
- π Security Scanning
- π Integration Validation
Require branches to be up to date: β
Require pull request reviews: β
(1 reviewer)
Dismiss stale reviews: β
Restrict pushes to matching branches: β
- GitHub Actions dashboard
- Repository status badges
- Email notifications (configurable)
- Slack/Discord integration (optional)
- Build Success Rate - Pipeline reliability
- Build Duration - Performance optimization
- Test Coverage - Quality maintenance
- Security Vulnerabilities - Risk assessment
- Package Size - Bundle optimization
- Run
npm run pre-push- Catch issues locally - Check GitHub Actions logs - Detailed error analysis
- Review this guide - Common solutions and troubleshooting
- Search existing issues - Community solutions
- Open new issue - Include logs and error details
- Contact maintainers - For urgent production issues
When reporting issues, include:
# System information
node --version
npm --version
git --version
# Project status
npm run pre-push
npm run pre-flight
npm run ci-cd:validate
# Dependency status
npm ls
npm audit
# Build logs
npm run build 2>&1 | tee build.log# Golden command (run before every push)
npm run pre-push
# Pre-flight check (intelligent change detection)
npm run pre-flight
# Release readiness validation
npm run ci-cd:validate
# Individual quality checks
npm run build
npm run lint:check
npm run format:check
npm run type-check
npm run test:unit:fast
npm run security:check
npm run validate-package
npm run docs:test-links.github/workflows/ci.yml- Main CI/CD pipeline.github/workflows/release.yml- Release automation (if exists).github/workflows/docs.yml- Documentation pipeline (if exists)
package.json- Scripts and dependencies.eslintrc.json- Code quality rules.prettierrc- Code formatting rulestsconfig.json- TypeScript configuration.audit-ci.json- Security audit configuration
This comprehensive CI/CD pipeline ensures code quality, security, and reliable releases while maintaining developer productivity through the golden command workflow.