Overview
The CI workflow automatically runs on every push tomain and on all pull requests targeting main. It performs comprehensive Python code quality checks including linting, type checking, testing, and security scanning.
Trigger Conditions
The workflow runs on:Workflow Configuration
Runner Environment
The workflow runs onubuntu-latest, which provides:
- Latest Ubuntu LTS version
- Pre-installed development tools
- Docker support
- GitHub Actions runner environment
Workflow Steps
Checkout code
Uses This step fetches the complete repository history and checks out the commit that triggered the workflow.
actions/checkout@v4 to clone the repository into the runnerSetup Python
Configures Python 3.12 using
actions/setup-python@v5Python 3.12 is specified to ensure consistent behavior across all CI runs. This version includes the latest performance improvements and security updates.
Install dependencies
Upgrades pip and wheel, then installs the project with development dependenciesThe workflow:
- Upgrades
pipandwheelto latest versions - Checks for
pyproject.tomlpresence - Installs the project in editable mode with dev extras
- Uses
|| trueto continue even if installation fails
Code Quality Tools
The CI workflow runs multiple tools to ensure code quality:Ruff - Fast Python linter
Ruff - Fast Python linter
Command:
ruff check .Ruff is an extremely fast Python linter written in Rust. It checks for:- Code style issues
- Common programming errors
- Complexity issues
- Import sorting
Ruff replaces multiple tools (flake8, isort, pydocstyle) with a single fast linter.
Black - Code formatter
Black - Code formatter
Command: If Black finds formatting issues, the CI will fail. Run
black --check .Black verifies that code follows consistent formatting standards. The --check flag ensures it only reports issues without modifying files.black . locally to auto-format your code.MyPy - Static type checker
MyPy - Static type checker
Command: Ensures type hints are correct and catches potential type errors.
mypy src/MyPy performs static type analysis on the src/ directory to catch type-related bugs before runtime.Pytest - Test runner
Pytest - Test runner
Command: Executes all tests found in the project and reports results.
pytestRuns the project’s test suite using pytest with coverage reporting enabled (via pytest-cov).Bandit - Security linter
Bandit - Security linter
Command:
bandit -r src/Bandit scans Python code for common security issues:- Hard-coded passwords
- SQL injection vulnerabilities
- Use of insecure functions
- Shell injection risks
Safety - Dependency vulnerability scanner
Safety - Dependency vulnerability scanner
Command: The
safety check -r <(pip freeze) --full-reportSafety checks installed dependencies against a database of known security vulnerabilities.--full-report flag provides detailed information about any vulnerable packages found.Failure Handling
The workflow is designed to be informative rather than strictly blocking:- Each tool runs independently
- Tool failures don’t stop subsequent checks
- All results are visible in the workflow logs
- Review logs to identify and fix issues
Customization
Changing Python Version
To use a different Python version, modify the setup step:Adding Additional Checks
Add new tools to the linting step:Making Checks Blocking
To make the workflow fail on tool errors, remove|| true from commands:
Running on Additional Branches
Expand trigger conditions to include more branches:Local Development
Run the same checks locally before pushing:Running these checks locally helps catch issues before pushing, reducing CI iteration time.
Troubleshooting
pyproject.toml not found
pyproject.toml not found
If your project doesn’t have a To enable checks, add a
pyproject.toml file, the workflow skips all Python checks and logs:pyproject.toml file to your project root.Installation failures
Installation failures
The workflow uses
|| true for installations, so failures don’t stop the workflow. Check logs for:- Missing system dependencies
- Incompatible package versions
- Network issues during download
pyproject.toml or requirements files.Tool not found errors
Tool not found errors
If a tool isn’t found, ensure it’s included in the installation step:All tools must be installed before they’re executed.
Best Practices
- Fix issues locally first - Run all checks before pushing to avoid CI failures
- Review all tool output - Even if checks pass, review warnings and suggestions
- Keep dependencies updated - Regularly update tools to get latest checks and fixes
- Use pre-commit hooks - Automate local checks with pre-commit framework
- Monitor security findings - Address Bandit and Safety findings promptly
Related Workflows
- Security Workflow - Trivy container scanning for Docker images