Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
package

GitHub Action

Build and Inspect a Python Package

v2.0.1

Build and Inspect a Python Package

package

Build and Inspect a Python Package

Builds the current package using standard PyPA tooling, keeps it as artifacts, then performs checks on it

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Build and Inspect a Python Package

uses: hynek/build-and-inspect-python-package@v2.0.1

Learn more about this action in hynek/build-and-inspect-python-package

Choose a version

Build and Inspect Python Packages

This action provides the following functionality for GitHub Actions users that are maintaining Python packages:

Builds your package using PyPA's build (this works with any PEP 517-compatible build backend, including Hatch, Flit, Setuptools, PDM, or Poetry). SOURCE_DATE_EPOCH is set to the timestamp of the last commit, giving you reproducible builds with meaningful file timestamps.

Uploads the built wheel and the source distribution (SDist) as GitHub Actions artifacts, so you can download and inspect them from the Summary view of a run, or upload them to PyPI automatically once the verification succeeds.

Lints the wheel contents using check-wheel-contents.

Lints the PyPI README using Twine and uploads it as an GitHub Actions artifact for further inspection. To level up your PyPI README game, check out hatch-fancy-pypi-readme!

Prints the tree of both SDist and wheel in the CI output, so you don't have to download the packages, if you just want to check the content list.

Prints and uploads the packaging metadata as a GitHub Actions artifact.


If you package an application as a Python package, this action is useful to double-check you're shipping everything you need, including all templates, translation files, et cetera.

Usage

jobs:
  check-package:
    name: Build & inspect our package.
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: hynek/build-and-inspect-python-package@v1

Caution

Internally, build-and-inspect-python-package uses actions/upload-artifact for storing the built artifacts that you can download with actions/download-artifact.

Unfortunately, v4 of both is incompatible with previous versions, so you have to make sure that your download-artifact version matches the version that build-and-inspect-python-package uses for uploading.

If you're using download-artifact@v3, you have to use build-and-inspect-python-package@v1. If you're using download-artifact@v4, you have to use build-and-inspect-python-package@v2.

Inputs

  • path: the location of the Python package to build (optional, default: .).

Outputs

  • dist: the location with the built packages.

    See for example how argon2-cffi-bindings uses this feature to check the built wheels don't break a dependency.

Artifacts

After a successful run, you'll find multiple artifacts in the run's Summary view:

  • Packages: The built packages. Perfect for automated PyPI upload workflows!
  • Package Metadata: the extracted packaging metadata (hint: it's formatted as an email).
  • PyPI README: the extracted PyPI README, exactly how it would be used by PyPI as your project's landing page. PEP 621 calls it readme, in classic setuptools it's long_description.

Our CI uses all inputs and outputs, if you want to see them in action.

License

The scripts and documentation in this project are released under the MIT License.