CI/CD Setup Guide 🚀¶
This guide helps you set up the complete CI/CD pipeline for the MCP Python Analyzer project.
📋 Prerequisites¶
Before enabling the full CI/CD pipeline, ensure you have:
- [x] GitHub repository with appropriate permissions
- [x] PyPI account for package publishing
- [x] TestPyPI account for testing (optional but recommended)
🔐 GitHub Repository Settings¶
Required Permissions¶
Go to Settings > Actions > General and ensure:
- ✅ Allow GitHub Actions to create and approve pull requests
- ✅ Allow GitHub Actions to approve pull requests
- ✅ Read and write permissions for GITHUB_TOKEN
Environments Setup¶
Create these environments in Settings > Environments:
1. PyPI Environment¶
- Name:
pypi - URL:
https://pypi.org/p/mcp-server-analyzer - Protection rules:
- ✅ Required reviewers (optional, for extra security)
- ✅ Wait timer: 0 minutes
- ✅ Restrict to protected branches only:
main
2. TestPyPI Environment¶
- Name:
testpypi - URL:
https://test.pypi.org/p/mcp-server-analyzer - Protection rules: None (for automatic testing)
🐍 PyPI Trusted Publishing Setup¶
1. PyPI Configuration¶
- Log in to PyPI
- Go to Account Settings > Publishing
- Add a new trusted publisher with these settings:
- PyPI Project Name:
mcp-server-analyzer - Owner:
anselmoo(your GitHub username) - Repository name:
mcp-server-analyzer - Workflow name:
ci-cd.yml - Environment name:
pypi
2. TestPyPI Configuration (Optional)¶
- Log in to TestPyPI
- Go to Account Settings > Publishing
- Add a new trusted publisher with these settings:
- PyPI Project Name:
mcp-server-analyzer - Owner:
anselmoo(your GitHub username) - Repository name:
mcp-server-analyzer - Workflow name:
ci-cd.yml - Environment name:
testpypi
🐳 Container Registry Setup¶
The pipeline automatically publishes to GitHub Container Registry (GHCR) using GITHUB_TOKEN. No additional setup required!
Images will be available at: ghcr.io/anselmoo/mcp-server-analyzer
🚀 Activating the Pipeline¶
Step 1: Enable Workflows¶
- Rename the current workflow file:
- Activate the full CI/CD pipeline:
Step 2: Test the Pipeline¶
- Push to main branch - triggers testing + TestPyPI + Docker build
- Create a version tag - triggers full release pipeline:
📊 Pipeline Workflow¶
On Push to Main Branch:¶
- ✅ Test & Quality: Pre-commit hooks, pytest, multi-Python testing
- ✅ Build Python Package: Create distribution packages
- ✅ Build Docker Image: Multi-arch build + container signing
- ✅ Publish to TestPyPI: Test package publishing
On Version Tag (v..*):¶
- ✅ All main branch steps +
- ✅ Publish to PyPI: Production package release
- ✅ GitHub Release: Create release with signed artifacts
- ✅ Rerun-safe Release Assets: If the release already exists, assets are updated in place
- ✅ Docker Latest Tag: Update latest container image
🔍 Monitoring & Debugging¶
GitHub Actions Dashboard¶
Monitor pipeline status at: https://github.com/anselmoo/mcp-server-analyzer/actions
Common Issues & Solutions¶
1. PyPI Trusted Publishing Failed¶
Solution: Verify trusted publisher configuration matches exactly:
- Repository name:
mcp-server-analyzer - Workflow name:
ci-cd.yml - Environment name:
pypi
2. Docker Build Failed¶
Solution: Check Dockerfile and ensure all files exist:
uv.lockfile presentpyproject.tomlconfigured correctly- Source code in
src/directory
3. Tests Failed¶
Solution: Ensure project structure:
- Source code in
src/mcp_python_analyzer/ - Tests in
tests/directory PYTHONPATH=srcenvironment variable set
Debug Commands¶
Test locally before pushing:
# Test pre-commit
uv tool run pre-commit run --all-files
# Test pytest
PYTHONPATH=src uv run pytest tests/ -v
# Test Docker build
docker build -t mcp-server-analyzer-test .
# Test package build
uv build
# Test package installation
pip install dist/*.whl
🔒 Security Best Practices¶
- ✅ Trusted Publishing: No API tokens stored in secrets
- ✅ Container Signing: All images signed with Cosign
- ✅ Artifact Signing: All releases signed with Sigstore
- ✅ Multi-arch Support: linux/amd64 and linux/arm64
- ✅ Minimal Permissions: Each job uses least-privilege access
📈 Release Process¶
Semantic Versioning¶
Use semantic versioning for releases:
- v1.0.0 - Major release
- v1.1.0 - Minor release (new features)
- v1.0.1 - Patch release (bug fixes)
Release Checklist¶
- ✅ Update version in
pyproject.toml - ✅ Update
CHANGELOG.md - ✅ Run tests locally:
uv run pytest - ✅ Create version tag:
git tag v1.0.0 - ✅ Push tag:
git push origin v1.0.0 - ✅ Monitor GitHub Actions
- ✅ Verify PyPI release
- ✅ Test Docker image
- ✅ Announce release
🎯 Next Steps¶
After setting up CI/CD:
- Configure branch protection for
mainbranch - Set up Codecov for coverage reporting
- Add dependabot for dependency updates
- Configure GitHub Security Advisories
- Set up project documentation with GitHub Pages
🚀 Your CI/CD pipeline is now ready for production!