Test CI and automated code coverage reports using GitHub Actions.

black, cicd, codecov, continuous-integration, coverage, documentation, github-actions, mypy, pylint, python, test-automation, unittest
pip install github-actions-cicd-example==0.0.1


License: MIT Tests codecov Code Style: Black Checked with mypy Latest Documentation

Example repo: using GitHub Actions for CI/CD for a Python project

This is a minimal repo demonstrating the use of GitHub Actions for Continuous Integration (CI) & Continous Deployment (CD) for a Python project.

The GitHub Actions are:

  1. Tests: Automatically unit test code using unittest from Python's standard library.
  2. Code coverage: Generate code coverage reports using The reports are automatically uploaded to codecov. The @codecov-commenter bot adds a comment to PR on code coverage status.
  3. Lint and format code: Lint using pylint. Check code formatting using black. Check type hints using mypy.
  4. Check docs build: Check Sphinx docs build successfully.
  5. Deploy docs to GitHub pages: Automatically deploy docs to a GitHub Pages repo upon merges to main branch.
  6. Upload release to PyPI: Publish the latest version of the package on PyPI when a new GitHub Release is created.

Each of these actions is stored in a YAML file in the .github/workflows directory.

File system structure


Push Token for Deploying Docs

Action #5 requires setting up a Personal Access Token with full repo access via the Developer Settings page. Store this token as an Actions secret under the name PUSH_TOKEN in the main repo (i.e. the repo where the docs source code is held). See more here.

Useful resources on the topic

  • mCoding's YouTube video on using GitHub actions for automated testing (see associated code repo).
  • Alex Damiani's YouTube videos on automated testing [1], [2] & [3] and associated code repos: [1] [2], & [3].
  • librosa is a real-world example of pyproject.toml, setup.cfg & working together.
  • Pharmpy uses Actions for building docs then deploying them to a separate GitHub Pages repo.
  • Vinod Kurup's blog post on automating PyPI releases with GitHub Actions.