GitHub Actions CI for Python with Matrix Testing
Set up a complete GitHub Actions CI pipeline for Python projects with matrix testing across multiple Python versions, linting, type checking, and coverage.
Prerequisites
- -A Python project in a GitHub repository
- -pytest and ruff installed as dev dependencies
Steps
Create the CI workflow directory
Create the directory structure that GitHub Actions requires for workflow files.
Create the CI workflow file
Create a CI workflow that tests against Python 3.11, 3.12, and 3.13. It runs linting, formatting checks, type checking, and tests with coverage.
The matrix strategy runs all Python versions in parallel, so the total CI time equals the slowest single version, not the sum.
Validate the workflow syntax locally
Verify that the workflow file is valid YAML before committing. Syntax errors in workflow files are only caught after pushing to GitHub.
This checks YAML syntax only, not GitHub Actions schema. For full validation, use 'actionlint' if installed.
Commit and push the workflow
Commit the workflow file and push to GitHub. The CI pipeline will trigger automatically on the next push or pull request to main.
Check the workflow run status
Use the GitHub CLI to check the status of recent workflow runs. This shows whether your CI pipeline passed or failed.
Use 'gh run view <run-id> --log-failed' to see the logs for a failed run without opening a browser.
Full Script
FAQ
Discussion
Loading comments...