This repository demonstrates how to build a Continuous Integration (CI) pipeline step by step using GitHub Actions.
ci_exercise/
├── src/
│ ├── __init__.py
│ ├── calculator.py # Simple math operations
│ └── string_utils.py # String manipulation utilities
├── tests/
│ ├── __init__.py
│ ├── test_calculator.py
│ └── test_string_utils.py
├── .github/
│ └── workflows/ # GitHub Actions workflows
├── requirements.txt # Production dependencies
├── requirements-dev.txt # Development dependencies
├── pyproject.toml # Tool configurations
└── README.md
Each branch builds upon the previous one, adding new CI capabilities:
| Branch | Description | What You'll Learn |
|---|---|---|
main |
Basic project skeleton | Project structure, no CI yet |
01-tests |
Run unit tests | Setting up pytest in GitHub Actions |
02-code-format |
Code formatting check | Using Black for code formatting |
03-linting |
Static analysis | Using Flake8 for linting |
04-security |
Security scanning | Using Bandit and Safety for security |
05-build |
Build artifacts | Creating and uploading build artifacts |
06-complete |
Full CI pipeline | Complete pipeline with all stages |
- Start with the
mainbranch to understand the project structure - Check out each branch sequentially to see how the CI pipeline evolves
- Examine the
.github/workflows/ci.ymlfile in each branch - Try modifying the code and see how the CI reacts
git checkout main # Start here
git checkout 01-tests # Add testing
git checkout 02-code-format # Add formatting
git checkout 03-linting # Add linting
git checkout 04-security # Add security checks
git checkout 05-build # Add build step
git checkout 06-complete # See complete pipeline# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements-dev.txtpytest
pytest --cov=src # With coverageblack --check src tests # Check formatting
black src tests # Fix formatting
flake8 src tests # Run linter
mypy src # Type checking
bandit -r src # Security scan- Runs unit tests with pytest
- Ensures code functionality works as expected
- Generates test reports
- Checks code follows consistent style using Black
- Ensures readability and maintainability
- Static code analysis with Flake8
- Catches potential bugs and style issues
- Bandit: Finds common security issues in Python code
- Safety: Checks dependencies for known vulnerabilities
- Creates distributable packages
- Uploads artifacts for later use
- Combines all stages
- Runs stages in parallel where possible
- Uses job dependencies for proper ordering