fontsource_downloader 0.3.1

A library to download (and cache) fonts with Fontsource REST API
Documentation
name: Python

on:
  push:
    branches: [main]
    paths:
      - '**.{rs,pyi,py}'
      - '!tests/*.rs'
      - Cargo.lock
      - uv.lock
      - pyproject.toml
      - .github/workflows/python.yml
    tags:
      - "v*"
  pull_request:
    branches: [main]
    paths:
      - '**.{rs,pyi,py}'
      - '!tests/*.rs'
      - Cargo.lock
      - uv.lock
      - pyproject.toml
      - .github/workflows/python.yml

permissions: {}

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tag/v') && github.ref != 'refs/head/main' }}

jobs:
  linux:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: ubuntu-latest
            target: x86_64
          - runner: ubuntu-latest
            target: x86
          - runner: ubuntu-latest
            target: aarch64
          - runner: ubuntu-latest
            target: armv7
          - runner: ubuntu-latest
            target: s390x
          - runner: ubuntu-latest
            target: ppc64le
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: actions/setup-python@v6
        with:
          python-version: '3.x'
      - name: Build wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: ${{ matrix.platform.target }}
          # Use the zig toolchain for all targets except ppc64le.
          # Note, this is meant to avoid build errors in aws-lc-sys crate, which compiles C code.
          args: >-
            --release --out dist --find-interpreter
            ${{ matrix.platform.target != 'ppc64le' && '--zig' || ''}}
          # avoid cache-poisoning potential for actually distributed builds
          sccache: ${{ startsWith(github.ref, 'refs/tags') && 'false' || 'true' }}
          manylinux: auto
          # here we either install the ppc64le compiler/toolchain or install zig on all others
          before-script-linux: |
            case "${{ matrix.platform.target }}" in
              ppc64le)
                apt-get update
                apt-get install -y \
                  pkg-config \
                  gcc-powerpc64le-linux-gnu \
                  g++-powerpc64le-linux-gnu \
                  binutils-powerpc64le-linux-gnu \
                  libc6-dev-ppc64el-cross
                ;;
              *)
                # spell-checker: disable-next-line
                pip install ziglang
                ;;
            esac
      - name: Upload wheels
        uses: actions/upload-artifact@v7
        with:
          name: wheels-linux-${{ matrix.platform.target }}
          path: dist/*

  windows:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      matrix:
        platform:
          - runner: windows-latest
            target: x64
          - runner: windows-latest
            target: x86
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: actions/setup-python@v6
        with:
          python-version: '3.x'
          architecture: ${{ matrix.platform.target }}
      - name: Build wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: ${{ matrix.platform.target }}
          args: --release --out dist --find-interpreter
          sccache: ${{ startsWith(github.ref, 'refs/tags') && 'false' || 'true' }} # zizmor: ignore[cache-poisoning]
      - name: Upload wheels
        uses: actions/upload-artifact@v7
        with:
          name: wheels-windows-${{ matrix.platform.target }}
          path: dist/*

  macos:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - runner: macos-15-intel
            target: x86_64
          - runner: macos-15
            target: aarch64
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: actions/setup-python@v6
        with:
          python-version: '3.x'
      - name: Build wheels
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          target: ${{ matrix.platform.target }}
          args: --release --out dist --find-interpreter
          sccache: ${{ startsWith(github.ref, 'refs/tags') && 'false' || 'true' }} # zizmor: ignore[cache-poisoning]
      - name: Upload wheels
        uses: actions/upload-artifact@v7
        with:
          name: wheels-macos-${{ matrix.platform.target }}
          path: dist/*

  sdist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
      - uses: actions/setup-python@v6
        with:
          python-version: 3.x
      - name: Build sdist
        uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
        with:
          command: sdist
          args: --out dist
      - name: Upload sdist
        uses: actions/upload-artifact@v7
        with:
          name: wheels-sdist
          path: dist/*

  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout this Repo
        uses: actions/checkout@v6
        with:
          persist-credentials: false
      - name: Install the latest version of uv
        uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
        id: setup-uv
        with:
          enable-cache: true # zizmor: ignore[cache-poisoning]
      - name: Cache deps
        uses: actions/cache@v5 # zizmor: ignore[cache-poisoning]
        with:
          path: ~/.cargo
          key: python-test-${{ hashFiles('Cargo.lock', 'uv.lock') }}
      - name: Setup Rust
        run: rustup update --no-self-update
      - name: Install Workflow Dependencies
        run: uv sync --group test
      - name: Run pytest
        run: uv run pytest -vv -s --color yes

  release:
    runs-on: ubuntu-latest
    needs: [linux, windows, macos, sdist, test]
    permissions:
      id-token: write
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v8
        with:
          pattern: wheels-*
          path: dist
          merge-multiple: true

      - uses: actions/setup-python@v6
        if: ${{ !startsWith(github.ref, 'refs/tags/') }}
        with:
          python-version: '3.x'
      - name: twine Check
        if: ${{ !startsWith(github.ref, 'refs/tags/') }}
        run: pipx run twine check dist/*

      # now uses trusted publishing
      - name: Publish package PyPI
        if: startsWith(github.ref, 'refs/tags/')
        uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
        with:
          skip-existing: true

  docs:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout this Repo
        uses: actions/checkout@v6
        with:
          persist-credentials: false
      - name: Install the latest version of uv
        uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
        id: setup-uv
        with:
          enable-cache: true # zizmor: ignore[cache-poisoning]
      - name: Install deps
        run: uv sync --group docs
      - name: Build docs
        run: uv run sphinx-build docs docs/_build/html -E -W
      - name: Upload docs
        uses: actions/upload-pages-artifact@v5
        with:
          path: docs/_build/html

  deploy-docs:
    if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    needs: docs
    permissions:
      pages: write      # to deploy to Pages
      id-token: write   # to verify the deployment originates from an appropriate source
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        uses: actions/deploy-pages@v5
        id: deployment