diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ada7c15..b48facb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ on: env: FORCE_COLOR: "1" # Make tools pretty. + SETUPTOOLS_SCM_PRETEND_VERSION: "1.0" # avoid warnings about shallow checkout jobs: check-structlog: diff --git a/CHANGELOG.md b/CHANGELOG.md index ca5db21..c575157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/hynek/build-and-inspect-python-package/compare/v1.2...main) +### Added + +- Package metadata is now printed and uploaded as an artifact. + [#11](https://github.com/hynek/build-and-inspect-python-package/pull/11) +- The PyPI README, that is a project's PyPI landing page, is now uploaded as an artifact. + [#11](https://github.com/hynek/build-and-inspect-python-package/pull/11) + + ## [1.2](https://github.com/hynek/build-and-inspect-python-package/compare/v1.1...v1.2) ### Added diff --git a/README.md b/README.md index bc616b8..487e6a8 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,12 @@ This action provides the following functionality for GitHub Actions users that are maintaining Python packages and want to ensure in CI that the packages they will build are in good shape and remain so: 1. Builds your package using PyPA's [*build*](https://pypi.org/project/build/) (this works with any [PEP 517](https://peps.python.org/pep-0517/)-compatible build backend, including *Hatch*, *Flit*, *Setuptools*, *PDM*, or *Poetry*), -1. uploads the *wheel* and the source distribution (*SDist*) as GitHub Actins artifacts (**not** PyPI) so you can download and inspect them from the Summary view of a Actions run, +1. uploads the *wheel* and the source distribution (*SDist*) as GitHub Actions artifacts (**not** PyPI) so you can download and inspect them from the Summary view of a Actions run, 1. lints the wheel using [*check-wheel-contents*](https://pypi.org/project/check-wheel-contents/), 1. lints the PyPI README of both *wheel* and *SDist* using [*twine*](https://pypi.org/project/twine/), -1. prints the tree of both *SDist* and *wheel* in the CI output, so you don't have to download the packages to just check the contents. +1. prints the tree of both *SDist* and *wheel* in the CI output, so you don't have to download the packages to just check the contents, +1. prints and uploads the *SDist*'s `PKG-INFO` file (that is also the `METADATA` file in each wheel) as a GitHub Actions artifact, +1. upload the packages PyPI README, just as it would appear on the project's PyPI landing page as a GitHub Actions artifact (to level up your PyPI README game, check out [*hatch-fancy-pypi-readme*](https://github.com/hynek/hatch-fancy-pypi-readme)). 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. diff --git a/action.yml b/action.yml index 3fdf23e..62d4ad0 100644 --- a/action.yml +++ b/action.yml @@ -31,17 +31,17 @@ runs: shell: bash # Build SDist, then build wheel out of it. - - run: /tmp/baipp/bin/python -m build --outdir /tmp/baipp-out + - run: /tmp/baipp/bin/python -m build --outdir /tmp/baipp/dist shell: bash working-directory: ${{ inputs.path }} - name: Set output id: setter shell: bash - run: echo "::set-output name=dist::/tmp/baipp-out" + run: echo "::set-output name=dist::/tmp/baipp/dist" # Give user overview over what we've built. - - run: ls -l /tmp/baipp-out + - run: ls -l /tmp/baipp/dist shell: bash working-directory: ${{ inputs.path }} @@ -49,24 +49,56 @@ runs: uses: actions/upload-artifact@v3 with: name: Packages - path: /tmp/baipp-out/* + path: /tmp/baipp/dist/* - - run: /tmp/baipp/bin/check-wheel-contents /tmp/baipp-out/*.whl + - run: /tmp/baipp/bin/check-wheel-contents /tmp/baipp/dist/*.whl shell: bash working-directory: ${{ inputs.path }} - name: Check PyPI README shell: bash working-directory: ${{ inputs.path }} - run: /tmp/baipp/bin/python -m twine check --strict /tmp/baipp-out/* + run: /tmp/baipp/bin/python -m twine check --strict /tmp/baipp/dist/* - - name: Show wheel & SDist contents hierarchically. + - name: Show wheel & SDist contents hierarchically, including metadata. shell: bash working-directory: ${{ inputs.path }} run: | - cd /tmp/baipp-out + cd /tmp/baipp/dist mkdir -p out/wheels /tmp/baipp/bin/python -m wheel unpack --dest out/wheels *.whl mkdir -p out/sdist tar xf *.tar.gz -C out/sdist tree -a out + echo ----- Metadata Follows ----- + cat out/sdist/*/PKG-INFO + echo ----- End of Metadata ----- + + - name: Upload metadata + uses: actions/upload-artifact@v3 + with: + name: Package Metadata + path: /tmp/baipp/dist/out/sdist/*/PKG-INFO + + - name: Extract PyPI README + shell: bash + working-directory: /tmp/baipp/dist/out/sdist/ + run: | + cat */PKG-INFO | python -c ' + import email.parser + import sys + + em = email.parser.Parser().parsestr(sys.stdin.read()) + suffix = { + "text/markdown": "md", + "text/x-rst": "rst", + }[em["Description-Content-Type"]] + with open(f"PyPI-README.{suffix}", "w") as f: + f.write(em.get_payload()) + ' + + - name: Upload PyPI README + uses: actions/upload-artifact@v3 + with: + name: PyPI README + path: /tmp/baipp/dist/out/sdist/PyPI-README.*