Files
librespot-spotizerr-dev/.github/workflows/publish-to-pypi.yml
cool.gitter.not.me.again.duh 2a99432b49 was it because of the "'s?
2025-05-31 16:55:04 -06:00

66 lines
2.1 KiB
YAML

name: Publish Python Package to PyPI
on:
release:
types: [published]
jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/librespot-spotizerr # Optional: Link to your PyPI project
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from tag
id: get_version
run: |
echo "Original GITHUB_REF_NAME: ${GITHUB_REF_NAME}"
# Extract actual tag from ref (e.g., refs/tags/v1.2.3 -> v1.2.3 or 1.2.3)
TAG_FROM_REF="${GITHUB_REF_NAME##*/}"
echo "Extracted tag from ref: $TAG_FROM_REF"
# Strip 'v' prefix if present (e.g., v1.2.3 -> 1.2.3)
FINAL_VERSION="${TAG_FROM_REF#v}"
echo "Final version for build: $FINAL_VERSION"
echo "VERSION=$FINAL_VERSION" >> $GITHUB_OUTPUT
- name: Update version in setup.py
run: |
VERSION_TAG=${{ steps.get_version.outputs.VERSION }}
sed -i "s/version="[^"]*"/version="${VERSION_TAG}""/" setup.py
echo "Updated setup.py to version $VERSION_TAG for build:"
cat setup.py
- name: Update version in librespot/__init__.py
run: |
VERSION_TAG=${{ steps.get_version.outputs.VERSION }}
sed -i "s/version_name = \".*\"/version_name = \"${VERSION_TAG}\"/" librespot/__init__.py
echo "Updated librespot/__init__.py to version $VERSION_TAG for build:"
cat librespot/__init__.py
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# No need for user/password with trusted publishing
# If not using trusted publishing, you would uncomment and use:
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}