Reusable steps and workflows for GitHub Actions, focused on Python packages.
GitHub Actions workflows, actions and documentation are mostly focused on JavaScript/TypeScript as the scripting language for writing reusable CI code. However, Python being equally popular and capable, usage of JS/TS might be bypassed, with some caveats. This repository gathers reusable CI tooling for testing, packaging and distributing Python projects and documentation.
See GitHub Actions and GitHub Reusable Workflows for more background information.
-
Artifacts:
pyTooling/upload-artifact: The upload-artifact action will preserve file attributes like permissions.pyTooling/download-artifact: The download-artifact action will preserve file attributes like permissions.
- Documentation:
MikTeX: A predefined MikTeX image based on Debian Bookworm + Python 3.13 with specific tools for documentation generation using e.g. Sphinx and related extensions.
This repository provides 10+ Reusable Workflows based on the CI pipelines of the repos in this GitHub organisation, EDA², VHDL, and others. By combining them, Python packages can be continuously tested and released along with Sphinx documentation sites, to GitHub Releases, GitHub Pages and PyPI. Optionally, coverage and static type check reports can be gathered and integrated into the online documentation.
As shown in the screenshots above, the expected order is:
-
Global:
Parameters: It generates output parameters with artifact names and job matrices to be used in later running jobs.
It's a workaround for the limitations to handle global variables in GitHub Actions workflows (see actions/runner#480).ExtractConfiguration: extracts configuration values from
pyproject.toml
and exposes configured paths and filenames as job output parameters. -
Predefined pipelines:
CompletePipeline: is a predefined pipeline for typical Python projects using all predefined job templates of pyTooling at once: (unit testing, code coverage, static typing, documentation report generation and publishing, packaging, releasing, ...) -
Code testing/analysis:
ApplicationTesting: like UnitTesting, but running tests using an installed Python package.UnitTesting: run unit test with
pytest
using multiple versions of Python, and optionally upload results as XML reports. Configuration options topytest
should be given via section[tool.pytest.ini_options]
in apyproject.toml
file.
Besides test results, also code coverage data (incl. branch coverage) can be collected usingpytest
/pytest-cov
/coverage.py
. Configuration options tocoverage.py
should be given via section[tool.coverage.*]
in apyproject.toml
file.
While multiple report formats can be created in the job, it's recommended to usePublishTestResults
and/orPublishCoverageResults
to merge results from matrix runs and then generate final reports as XML, JSON or HTML.
Finally, reports can be published to GitHub Pages or cloud services like Codecov and Codacy.StaticTypeCheck: collect static type check result with
mypy
, and optionally upload results as an HTML report.VerifyDocs: extract code examples from the README and test these code snippets.
-
Packaging and releasing:
Package: generate source and wheel packages, and upload them as an artifact.PublishOnPyPI: publish source and wheel packages to PyPI.
PublishTestResults: publish unit test results through GH action
dorny/test-reporter
.PublishCoverageResults: publish ucode coverage results.
NightlyRelease: publish GitHub Release.
Release: publish GitHub Release.
-
Documentation:
SphinxDocumentation: create HTML and LaTeX documentation using Sphinx.LaTeXDocumentation: compile LaTeX documentation to a PDF file using MikTeX.
PublishToGitHubPages: publish HTML documentation to GitHub Pages.
-
Cleanup:
IntermediateCleanUp: delete intermediate artifacts.ArtifactCleanUp: delete artifacts.
-
⚠ Deprecated ⚠:
CoverageCollection: UseUnitTesting
, because is can collect code coverage too. This avoids code duplication in job templates.BuildTheDocs: Use
SphinxDocumentation
,LaTeXDocumentation
andPublishToGitHubPages
. BuildTheDocs isn't maintained anymore.
ExamplePipeline.yml is an example Workflow which uses all of the Reusable Workflows. Python package/tool developers can copy it into their repos, in order to use al the reusable workflows straightaway. Minimal required modifications are the following:
- Set the
name
input of jobParameters
. - Specify the
commands
input of jobStaticTypeCheck
.
Find further usage cases in the following list of projects:
- Patrick Lehmann
- Unai Martinez-Corral (Maintainer)
- and more...
This Python package (source code) licensed under Apache License 2.0. The accompanying documentation is licensed under Creative Commons - Attribution 4.0 (CC-BY 4.0).
SPDX-License-Identifier: Apache-2.0