Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print and upload metadata + PyPI readme #11

Merged
merged 6 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
48 changes: 40 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,74 @@ 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 }}

- name: Upload built artifacts.
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.*