Skip to content

Build and publish to PyPI #2

Build and publish to PyPI

Build and publish to PyPI #2

Workflow file for this run

name: Build and publish to PyPI
on:
workflow_dispatch:
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install build dependencies
run: |
pip install --upgrade pip
pip install setuptools wheel twine build
- name: Extract version from setup.py
id: get_version
run: |
# Busca en setup.py la línea que tenga VERSION = "X.Y.Z"
# y extrae el valor X.Y.Z
VERSION=$(grep -Po '(?<=^VERSION = ")[^"]*' setup.py)
echo "package_version=$VERSION" >> $GITHUB_OUTPUT
# (Opcional) Paso para comprobar que el tag vX.Y.Z coincide con la versión del setup.py
- name: Check version consistency
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}" # quita el prefijo 'v'
if [ "$TAG_VERSION" != "${{ steps.get_version.outputs.package_version }}" ]; then
echo "Error: la versión del tag ($TAG_VERSION) no coincide con setup.py (${{ steps.get_version.outputs.package_version }})"
exit 1
fi
- name: Build distribution (sdist & wheel)
run: |
python -m build
- name: Publish to PyPI
run: |
twine check dist/*
twine upload --username __token__ --password ${{ secrets.PYPI_API_TOKEN }} dist/*