Skip to content

Upload Python Package to PyPI #4

Upload Python Package to PyPI

Upload Python Package to PyPI #4

Workflow file for this run

name: Upload Python Package to PyPI
on:
release:
types: [published]
jobs:
build:
name: Build and deploy
environment: test
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Set environment variables
id: set_env_variables
run: |
echo "PYTHONPATH=." >> "$GITHUB_ENV"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest
pytest test/ --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml
- name: Extract tag name
id: tag
run: echo "TAG_NAME=$(echo $GITHUB_REF | cut -d / -f 3)" >> "$GITHUB_OUTPUT"
- name: Update version in pyproject.toml
run: >-
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.PKG_VERSION }}/g" pyproject.toml
- name: Build package
run: python -m build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ vars.PYPI_URL }}
password: ${{ secrets.PYPI_API_TOKEN }}