Reworked PublishOnPyPI.

This commit is contained in:
Patrick Lehmann
2025-09-01 22:58:19 +02:00
parent d5ad74fa89
commit e559fb8219
5 changed files with 145 additions and 54 deletions

View File

@@ -78,15 +78,15 @@ jobs:
# build (not isolated) # build (not isolated)
- name: 🔧 [build] Install dependencies for packaging and release - name: 🔧 [build - no-isolation] Install dependencies for packaging and release
if: inputs.requirements == 'no-isolation' if: inputs.requirements == 'no-isolation'
run: python -m pip install --disable-pip-version-check build run: python -m pip install --disable-pip-version-check build
- name: 🔨 [build] Build Python package (source distribution) - name: 🔨 [build - no-isolation] Build Python package (source distribution)
if: inputs.requirements == 'no-isolation' if: inputs.requirements == 'no-isolation'
run: python -m build --no-isolation --sdist run: python -m build --no-isolation --sdist
- name: 🔨 [build] Build Python package (binary distribution - wheel) - name: 🔨 [build - no-isolation] Build Python package (binary distribution - wheel)
if: inputs.requirements == 'no-isolation' if: inputs.requirements == 'no-isolation'
run: python -m build --no-isolation --wheel run: python -m build --no-isolation --wheel

View File

@@ -69,18 +69,18 @@ jobs:
- name: ⚙ Install dependencies for packaging and release - name: ⚙ Install dependencies for packaging and release
run: python -m pip install --disable-pip-version-check ${{ inputs.requirements }} run: python -m pip install --disable-pip-version-check ${{ inputs.requirements }}
- name: Release Python source package to PyPI - name: Publish Python wheel package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.tar.gz
- name: ⤴ Release Python wheel package to PyPI
env: env:
TWINE_USERNAME: __token__ TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.whl run: twine upload dist/*.whl
- name: ⤴ Publish Python source package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.tar.gz
- name: 🗑️ Delete packaging Artifacts - name: 🗑️ Delete packaging Artifacts
uses: geekyeggo/delete-artifact@v5 uses: geekyeggo/delete-artifact@v5
with: with:

View File

@@ -162,7 +162,7 @@ requirements
Either a requirements file can be referenced using ``'-r path/to/requirements.txt'``, or a list of Either a requirements file can be referenced using ``'-r path/to/requirements.txt'``, or a list of
packages can be specified using a space separated list like ``'build wheel'``. packages can be specified using a space separated list like ``'build wheel'``.
:Behavior: If the value is an empty string, :pypi:`build` is used for packaging. |br| :Behavior: If the value is an empty string, :pypi:`build` is used for packaging. |br|
if the value is ``no-isolation``, :ypy:`build` is used in *no-isolation* mode for packaging. |br| if the value is ``no-isolation``, :pypi:`build` is used in *no-isolation* mode for packaging. |br|
otherwise, a list of requirements is assumed and :pypi:`setuptools` is used for packaging. otherwise, a list of requirements is assumed and :pypi:`setuptools` is used for packaging.
:Description: Python dependencies to be installed through *pip*. :Description: Python dependencies to be installed through *pip*.
@@ -175,7 +175,7 @@ artifact
:Type: string :Type: string
:Required: yes :Required: yes
:Possible Values: Any valid artifact name. :Possible Values: Any valid artifact name.
:Description: Name of the artifact containing the unittest report summary in XML format. :Description: Name of the artifact containing the packaged Python code.
.. _JOBTMPL/Package/Secrets: .. _JOBTMPL/Package/Secrets:

View File

@@ -3,29 +3,46 @@
PublishOnPyPI PublishOnPyPI
############# #############
Publish a source (``*.tar.gz``) package and/or wheel (``*.whl``) packages to `PyPI <https://pypi.org/>`__. Publish a wheel (``*.whl``) packages and/or source (``*.tar.gz``) package to `PyPI <https://pypi.org/>`__.
**Behavior:** .. topic:: Features
1. Download package artifact * Publish a Python package to `PyPI <https://pypi.org/>`__.
2. Publish source package(s) (``*.tar.gz``)
3. Publish wheel package(s) (``*.whl``)
4. Delete the artifact
**Preconditions:** .. topic:: Behavior:
A PyPI account was created and the package name is either not occupied or the user has access rights for that package. 1. Download package artifact
2. Publish source package(s) (``*.tar.gz``)
3. Publish wheel package(s) (``*.whl``)
4. Delete the artifact
**Requirements:** .. topic:: Preconditions:
Setup a secret (e.g. ``PYPI_TOKEN``) in GitHub to handover the PyPI token to the job. 1. A PyPI account was created and the package name is either not occupied or the user has access rights for that
package.
2. An access token was generated at PyPI, which can be used for uploading packages.
3. A secret (e.g. ``PYPI_TOKEN``) was setup in GitHub Actions to handover the PyPI token to the pipeline.
**Dependencies:** .. topic:: Job Execution
* :gh:`actions/download-artifact` .. image:: ../../_static/pyTooling-Actions-PublishOnPyPI.png
* :gh:`actions/setup-python` :width: 500px
* :gh:`geekyeggo/delete-artifact`
.. topic:: Dependencies
* :gh:`pyTooling/download-artifact`
* :gh:`actions/download-artifact`
* :gh:`actions/setup-python`
* :gh:`geekyeggo/delete-artifact`
* pip
* :pypi:`wheel`
* :pypi:`twine`
.. _JOBTMPL/PublishOnPyPI/Instantiation:
Instantiation Instantiation
************* *************
@@ -78,62 +95,136 @@ by that job. Finally, the list of requirements is overwritten to load a list of
secrets: secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
.. seealso::
Parameters :ref:`JOBTMPL/Package`
**********
.. _JOBTMPL/PublishOnPyPI/Parameters:
Parameter Summary
*****************
.. rubric:: Goto :ref:`input parameters <JOBTMPL/PublishOnPyPI/Inputs>`
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| Parameter Name | Required | Type | Default |
+=====================================================================+==========+==========+===================================================================+
| :ref:`JOBTMPL/PublishOnPyPI/Input/ubuntu_image_version` | no | string | ``'24.04'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/PublishOnPyPI/Input/python_version` | no | string | ``'3.13'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/PublishOnPyPI/Input/requirements` | no | string | ``'wheel twine'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/PublishOnPyPI/Input/artifact` | yes | string | — — — — |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
.. rubric:: Goto :ref:`secrets <JOBTMPL/PublishOnPyPI/Secrets>`
+-----------------------------------------------------------+----------+----------+--------------+
| Token Name | Required | Type | Default |
+===========================================================+==========+==========+==============+
| :ref:`JOBTMPL/PublishOnPyPI/Secret/PYPI_TOKEN` | no | string | — — — — |
+-----------------------------------------------------------+----------+----------+--------------+
.. rubric:: Goto :ref:`output parameters <JOBTMPL/PublishOnPyPI/Outputs>`
This job template has no output parameters.
.. _JOBTMPL/PublishOnPyPI/Inputs:
Input Parameters
****************
.. _JOBTMPL/PublishOnPyPI/Input/ubuntu_image_version:
ubuntu_image_version
====================
:Type: string
:Required: no
:Default Value: ``'24.04'``
:Possible Values: See `actions/runner-images - Available Images <https://github.com/actions/runner-images?tab=readme-ov-file#available-images>`__
for available Ubuntu image versions.
:Description: Version of the Ubuntu image used to run this job.
.. note::
Unfortunately, GitHub Actions has only a `limited set of functions <https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#functions>`__,
thus, the usual Ubuntu image name like ``'ubuntu-24.04'`` can't be split into image name and image
version.
.. _JOBTMPL/PublishOnPyPI/Input/python_version:
python_version python_version
============== ==============
+----------------+----------+----------+----------+ :Type: string
| Parameter Name | Required | Type | Default | :Required: no
+================+==========+==========+==========+ :Default Value: ``'3.13'``
| python_version | optional | string | ``3.11`` | :Possible Values: Any valid Python version conforming to the pattern ``<major>.<minor>`` or ``pypy-<major>.<minor>``. |br|
+----------------+----------+----------+----------+ See `actions/python-versions - available Python versions <https://github.com/actions/python-versions>`__
and `actions/setup-python - configurable Python versions <https://github.com/actions/setup-python>`__.
:Description: Python version used as default for other jobs requiring a single Python version. |br|
In case :ref:`JOBTMPL/Parameters/Input/python_version_list` is an empty string, this version is used
to populate the version list.
Python version used for uploading the package contents via `twine` to PyPI.
.. _JOBTMPL/PublishOnPyPI/Input/requirements:
requirements requirements
============ ============
+----------------+----------+----------+-----------------+ :Type: string
| Parameter Name | Required | Type | Default | :Required: no
+================+==========+==========+=================+ :Default Value: ``''``
| requirements | optional | string | ``wheel twine`` | :Possible Values: Any valid list of parameters for ``pip install``. |br|
+----------------+----------+----------+-----------------+ Either a requirements file can be referenced using ``'-r path/to/requirements.txt'``, or a list of
packages can be specified using a space separated list like ``'wheel twine'``.
:Description: Python dependencies to be installed through *pip*.
List of requirements to be installed for uploading the package contents to PyPI.
.. _JOBTMPL/PublishOnPyPI/Input/artifact:
artifact artifact
======== ========
+----------------+----------+----------+--------------+ :Type: string
| Parameter Name | Required | Type | Default | :Required: yes
+================+==========+==========+==============+ :Possible Values: Any valid artifact name.
| artifact | yes | string | — — — — | :Description: Name of the artifact containing the packaged Python package(s).
+----------------+----------+----------+--------------+
Name of the artifact containing the package(s).
.. _JOBTMPL/PublishOnPyPI/Secrets:
Secrets Secrets
******* *******
.. _JOBTMPL/PublishOnPyPI/Secret/PYPI_TOKEN:
PYPI_TOKEN PYPI_TOKEN
========== ==========
+----------------+----------+----------+--------------+ :Type: string
| Secret Name | Required | Type | Default | :Required: no
+================+==========+==========+==============+ :Default Value: — — — —
| PYPI_TOKEN | yes | string | — — — — | :Description: The token to publish and upload packages on `PyPI <https://pypi.org/>`__.
+----------------+----------+----------+--------------+
The token to access the package at PyPI for uploading new data.
Results .. _JOBTMPL/PublishOnPyPI/Outputs:
Outputs
******* *******
This job template has no output parameters. This job template has no output parameters.
.. _JOBTMPL/PublishOnPyPI/Optimizations:
Optimizations
*************
This template offers no optimizations (reduced job runtime).

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB