name: Test and Publish
on:
push:
branches: [ main ]
paths-ignore:
- '**.md'
- 'docs/**'
pull_request:
branches: [ main ]
release:
types: [published]
permissions:
contents: write
packages: write
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.11']
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Tesseract (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y tesseract-ocr
- name: Install Tesseract (macOS)
if: matrix.os == 'macos-latest'
run: brew install tesseract
- name: Install Tesseract (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
choco install tesseract
$tesseractPath = "C:\Program Files\Tesseract-OCR"
# Add to system PATH
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$tesseractPath", [System.EnvironmentVariableTarget]::Machine)
# Add to current session PATH
$env:Path = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
# Add to GITHUB_PATH for subsequent steps
echo "$tesseractPath" >> $env:GITHUB_PATH
# Verify installation
& "C:\Program Files\Tesseract-OCR\tesseract.exe" --version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
pip install -e .
- name: Run tests
run: |
pytest --cov=mcp_ocr tests/
- name: Upload coverage reports
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-latest'
publish:
needs: test
runs-on: ubuntu-latest
environment: release
if: github.event_name == 'release' && github.event.action == 'published' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Verify tag matches version
run: |
VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
TAG=${GITHUB_REF#refs/tags/v}
if [ "$VERSION" != "$TAG" ]; then
echo "Version in pyproject.toml ($VERSION) does not match tag ($TAG)"
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build and verify
run: |
python -m build
twine check dist/*
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install build twine
python -m build
twine upload dist/*
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
body_path: CHANGELOG.md
generate_release_notes: true