omniparse 0.2.1

A Rust toolkit for detecting and extracting metadata, text, and content from various file formats
Documentation
name: Python Bindings

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]
  release:
    types: [ published ]

jobs:
  test:
    name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      
      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
      
      - name: Install maturin
        run: pip install maturin pytest pytest-cov
      
      - name: Build Python extension
        run: maturin develop --release
      
      - name: Run tests
        run: pytest python/tests/ -v --cov=omniparse --cov-report=xml
      
      - name: Upload coverage to Codecov
        if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          flags: python
          name: python-${{ matrix.python-version }}

  build-wheels:
    name: Build wheels on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          command: build
          args: --release --out dist --interpreter 3.8 3.9 3.10 3.11 3.12
          manylinux: auto
      
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-${{ matrix.os }}
          path: dist

  build-sdist:
    name: Build source distribution
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      
      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist
      
      - name: Upload sdist
        uses: actions/upload-artifact@v4
        with:
          name: sdist
          path: dist

  test-wheels:
    name: Test wheel on ${{ matrix.os }}
    needs: [build-wheels]
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Download wheels
        uses: actions/download-artifact@v4
        with:
          name: wheels-${{ matrix.os }}
          path: dist
      
      - name: Install wheel
        shell: bash
        run: |
          pip install pytest
          pip install omniparse --no-index --find-links dist --force-reinstall
      
      - name: Run basic tests
        run: pytest python/tests/test_basic.py -v

  publish:
    name: Publish to PyPI
    needs: [test, build-wheels, build-sdist, test-wheels]
    runs-on: ubuntu-latest
    if: github.event_name == 'release' && github.event.action == 'published'
    environment:
      name: pypi
      url: https://pypi.org/p/omniparse
    permissions:
      id-token: write
    
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist-artifacts
      
      - name: Prepare distribution files
        run: |
          mkdir -p dist
          find dist-artifacts -name '*.whl' -exec cp {} dist/ \;
          find dist-artifacts -name '*.tar.gz' -exec cp {} dist/ \;
          ls -lh dist/
      
      - name: Publish to PyPI
        uses: PyO3/maturin-action@v1
        with:
          command: upload
          args: --skip-existing dist/*
        env:
          MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}