Skip to content

PDFCLOUD-5592 Publish to PYPI #240

PDFCLOUD-5592 Publish to PYPI

PDFCLOUD-5592 Publish to PYPI #240

name: Test and Publish
on:
pull_request:
push:
branches:
- main
- develop
- feature-*
release:
types:
- published
jobs:
docs-check:
name: Docs Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: 0.9.18
python-version: "3.11"
enable-cache: true
cache-suffix: test-and-publish
cache-dependency-glob: uv.lock
- name: Synchronize project dependencies
run: uv sync --group dev
- name: Build docs with MkDocs
run: uv run mkdocs build --strict
tests:
name: Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
environment: ci-live
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
permissions:
id-token: write
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: 0.9.18
python-version: ${{ matrix.python-version }}
enable-cache: true
cache-suffix: test-and-publish
cache-dependency-glob: uv.lock
- name: Run tests with nox
run: uvx nox --python ${{ matrix.python-version }} --session tests -- --no-parallel
env:
PDFREST_API_KEY: ${{ secrets.PDFREST_API_KEY }}
- name: Fetch base branch for diff-cover
if: github.event_name == 'pull_request'
run: |
if git rev-parse --is-shallow-repository | grep -q true; then
git fetch --no-tags --prune origin ${{ github.base_ref }} --unshallow
else
git fetch --no-tags --prune origin ${{ github.base_ref }}
fi
- name: Run diff-cover (new code must be >= 90%)
if: github.event_name == 'pull_request'
run: >
uv run diff-cover coverage/py${{ matrix.python-version }}/coverage.xml
--compare-branch origin/${{ github.base_ref }}
--fail-under 90
--format markdown:coverage/py${{ matrix.python-version }}/diff-cover.md
- name: Check client class function coverage
run: >
uv run python scripts/check_class_function_coverage.py
coverage/py${{ matrix.python-version }}/coverage.json
--class PdfRestClient
--class AsyncPdfRestClient
--class _FilesClient
--class _AsyncFilesClient
--fail-under 90
--markdown-report coverage/py${{ matrix.python-version }}/class-function-coverage.md
- name: Upload coverage reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
path: coverage/py${{ matrix.python-version }}
examples:
name: Examples (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
environment: ci-live
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
permissions:
id-token: write
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: 0.9.18
python-version: ${{ matrix.python-version }}
enable-cache: true
cache-suffix: test-and-publish
cache-dependency-glob: uv.lock
- name: Run examples with nox
run: uvx nox --python ${{ matrix.python-version }} --session examples
env:
PDFREST_API_KEY: ${{ secrets.PDFREST_API_KEY }}
publish:
name: Publish to PyPI
needs:
- docs-check
- tests
- examples
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
environment: production
permissions:
id-token: write
contents: read
env:
UV_PROJECT_ENVIRONMENT: .venv-release
UV_TRUSTED_PUBLISHING: always
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: 0.9.18
enable-cache: true
cache-suffix: pre-commit
cache-dependency-glob: uv.lock
- name: Restore venv cache
uses: actions/cache@v4
with:
path: |
${{ env.UV_PROJECT_ENVIRONMENT }}
key: ${{ runner.os }}-uv-release-${{ hashFiles('pyproject.toml') }}
- name: Synchronize project dependencies
run: uv sync --group dev
- name: Build distribution artifacts
run: uv build --python 3.11
- name: Publish package to PyPI (Trusted Publishing)
run: uv publish