Skip to content

Publish to PyPI

Publish to PyPI #25

name: Publish to PyPI
on:
workflow_run:
workflows: ["Release"]
types: [completed]
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Get latest tag
id: tag
run: |
TAG=$(git describe --tags --abbrev=0)
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Using tag: $TAG"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install build tools
run: pip install build tomli tomli_w
- name: Inject version from tag
run: |
python3 - <<'EOF'
import tomli, tomli_w, os
version = os.environ["VERSION"].lstrip("v")
with open("pyproject.toml", "rb") as f:
data = tomli.load(f)
data["project"]["version"] = version
with open("pyproject.toml", "wb") as f:
tomli_w.dump(data, f)
print(f"Set version to {version}")
EOF
env:
VERSION: ${{ steps.tag.outputs.tag }}
- name: Build package
run: python3 -m build
- uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
publish:
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/deezer-python-gql
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1