This PR implements a comprehensive CI/CD pipeline using GitHub Actions to automate testing, building, deployment, and security auditing for the Healthy-Stellar contracts repository. This addresses a critical gap in the development workflow where all testing and deployment was previously manual.
Triggers: Every push and pull request to main
Jobs:
- Runs
cargo fmt --all --check - Enforces consistent Rust code formatting
- Required for merge
- Runs
cargo clippy -- -D warnings - Zero warnings policy enforced
- Checks all targets and features across workspace
- Required for merge
- Runs
cargo test --workspace - Executes all 754+ tests across all contracts
- Validates correctness and prevents regressions
- Required for merge
- Builds for
wasm32-unknown-unknowntarget - Verifies all contracts compile to valid WASM
- Optimizes binaries using
soroban contract optimize - Uploads artifacts for 7 days
- Required for merge
- Meta-job that depends on all other jobs
- Used for branch protection rules
- Single check to require in branch protection
Performance Optimizations:
- Parallel job execution
- Cargo registry caching
- Cargo git index caching
- Build target caching
- Significantly reduces CI run time (typically 5-10 minutes)
Triggers:
- Automatic: Every push to
main - Manual:
workflow_dispatchwith optional contract selection
Features:
- Automatically detects which contracts changed
- Only deploys modified contracts
- Saves time and resources
- Manual override available for specific deployments
- Builds optimized WASM binaries
- Optimizes using
soroban contract optimize - Deploys to Stellar testnet using
soroban-cli - Generates deployment summary with contract IDs
- Posts summary as PR comment (if applicable)
- Saves deployment info as artifacts (90 days)
- Markdown table with deployment results
- Success/failure status for each contract
- Deployed contract IDs for reference
- Visible in GitHub Step Summary
- Posted as PR comment for visibility
Security:
- Uses
STELLAR_SECRET_KEYfrom GitHub Secrets - Never exposes private keys in logs
- Secure credential management
Triggers:
- Scheduled: Every Monday at 9:00 AM UTC
- Manual:
workflow_dispatch - Automatic: When
Cargo.tomlorCargo.lockchanges
Jobs:
- Runs
cargo auditfor known vulnerabilities - Scans all workspace dependencies
- Generates JSON report with details
- Automatically creates GitHub issues for vulnerabilities
- Updates existing issues instead of creating duplicates
- Labels:
security,dependencies,high-priority
- Reviews dependency changes in pull requests
- Fails on moderate or higher severity issues
- Blocks problematic licenses (GPL-3.0, AGPL-3.0)
- Uses GitHub's dependency review API
- Runs
cargo denyfor comprehensive checks:- Advisories: Known security vulnerabilities
- Licenses: License compliance verification
- Bans: Banned dependency detection
- Sources: Dependency source verification
- Generates Software Bill of Materials (SBOM)
- Uploads SBOM as artifact (90 days)
Automated Issue Management:
- Creates detailed GitHub issues when vulnerabilities found
- Includes vulnerability details and remediation steps
- Prevents duplicate issues
- Enables quick response to security threats
- Configuration for
cargo-deny - Defines allowed/denied licenses
- Configures security advisory checks
- Sets up dependency source verification
- Enforces supply chain security policies
- Comprehensive workflow documentation
- Detailed explanation of each job
- Caching strategy documentation
- Troubleshooting guides
- Local testing instructions
- Monitoring and maintenance guidelines
- Step-by-step setup guide
- Secret configuration instructions
- Branch protection rule setup
- Verification procedures
- Advanced configuration options
- Best practices and checklists
-
CI passes on every PR before merge is allowed
- All checks (format, clippy, test, build) must pass
- CI Success job provides single check for branch protection
- Parallel execution for faster feedback
-
Branch protection rules require CI to pass
- Documented setup process in CICD_SETUP.md
- Required checks clearly identified
- Instructions for configuring branch protection
-
Deployment workflow uses GitHub Secrets for testnet keys
STELLAR_SECRET_KEYstored securely in GitHub Secrets- Never exposed in logs or outputs
- Setup instructions provided
-
Immediate Feedback
- CI runs on every PR
- Catches issues before merge
- Reduces debugging time
-
Consistent Code Quality
- Automated formatting checks
- Linting with zero warnings
- Comprehensive test coverage
-
Confidence in Changes
- All tests run automatically
- WASM build verification
- No manual testing required
-
Automated Deployments
- No manual deployment steps
- Consistent deployment process
- Deployment history tracked
-
Security Monitoring
- Weekly vulnerability scans
- Automatic issue creation
- Supply chain security
-
Audit Trail
- All deployments documented
- Contract IDs tracked
- Deployment summaries preserved
-
Correctness Assurance
- All 754+ tests run on every change
- Zero warnings policy
- WASM build verification
-
Security First
- Weekly security audits
- Dependency vulnerability tracking
- License compliance
-
Traceability
- Complete deployment history
- Artifact retention
- Audit-ready documentation
-
Configure Secret:
# Generate testnet account soroban keys generate deployer --network testnet # Get secret key soroban keys show deployer # Add to GitHub: Settings → Secrets → STELLAR_SECRET_KEY
-
Enable GitHub Actions:
- Settings → Actions → General
- Allow all actions
- Enable read/write permissions
-
Configure Branch Protection:
- Settings → Branches → Add rule for
main - Require status checks:
CI Success - Require PR reviews: 1 approval
- Settings → Branches → Add rule for
-
Test the Pipeline:
- Create a test PR
- Verify all checks pass
- Merge to trigger deployment
See CICD_SETUP.md for comprehensive setup instructions including:
- Secret configuration
- Branch protection setup
- Notification configuration
- Troubleshooting guides
- Best practices
Before pushing, run these commands locally:
# Format check
cargo fmt --all --check
# Clippy
cargo clippy --all-targets --all-features --workspace -- -D warnings
# Tests
cargo test --workspace
# WASM build
cargo build --release --target wasm32-unknown-unknown --workspaceThe workflows have been tested with:
- ✅ Format check passes
- ✅ Clippy with zero warnings
- ✅ All tests pass
- ✅ WASM builds successfully
- ✅ Deployment workflow syntax validated
- ✅ Security audit workflow syntax validated
Estimated run times (with caching):
- Format Check: ~30 seconds
- Clippy Lint: ~3-5 minutes
- Test Suite: ~5-8 minutes
- Build WASM: ~5-7 minutes
- Total CI Time: ~8-12 minutes (parallel execution)
- Deployment: ~2-5 minutes per contract
- Security Audit: ~3-5 minutes
All workflows implement aggressive caching:
- Cargo registry:
~/.cargo/registry - Cargo git index:
~/.cargo/git - Build artifacts:
target/
Cache keys based on Cargo.lock hash ensure:
- Cache invalidation when dependencies change
- Fast CI runs when dependencies unchanged
- Efficient use of GitHub Actions minutes
- Private keys stored in GitHub Secrets
- Never logged or exposed
- Separate accounts for testnet/mainnet recommended
- Weekly automated scans
- Automatic issue creation
- Clear remediation steps
- Audit trail maintained
- Dependency source verification
- License compliance checking
- Known vulnerability detection
- SBOM generation for transparency
- Review security audit results
- Check for created security issues
- Update vulnerable dependencies
- Review deployment history
- Verify contract IDs documented
- Clean up old artifacts
- Comprehensive security review
- Update workflow versions
- Optimize caching strategies
None. This is a new feature that adds CI/CD capabilities without modifying existing code or workflows.
.github/workflows/ci.yml- CI pipeline.github/workflows/deploy-testnet.yml- Deployment automation.github/workflows/security-audit.yml- Security scanning.github/workflows/README.md- Workflow documentationCICD_SETUP.md- Setup guidedeny.toml- cargo-deny configuration
Potential improvements:
- Mainnet deployment workflow
- Performance benchmarking
- Code coverage reporting
- Automated changelog generation
- Release automation
- Multi-environment deployments
- Slack/Discord notifications
- Custom deployment strategies
Common issues and solutions documented in:
.github/workflows/README.md- Workflow-specific issuesCICD_SETUP.md- Setup and configuration issues
- CI workflow created and tested
- Deployment workflow created
- Security audit workflow created
- Documentation complete
- Setup guide provided
- Troubleshooting guides included
- Caching implemented
- Secrets documented
- Branch protection instructions provided
- Best practices documented
Closes #394
This PR establishes a production-ready CI/CD pipeline that ensures code quality, automates deployments, and maintains security for the Healthy-Stellar healthcare contracts.