| name: CI/CD Pipeline |
|
|
| on: |
| push: |
| branches: [ main, develop ] |
| pull_request: |
| branches: [ main ] |
|
|
| jobs: |
| test: |
| runs-on: ubuntu-latest |
| |
| steps: |
| - uses: actions/checkout@v3 |
| |
| - name: Set up Python |
| uses: actions/setup-python@v4 |
| with: |
| python-version: '3.10' |
| |
| - name: Install system dependencies |
| run: | |
| sudo apt-get update |
| sudo apt-get install -y tesseract-ocr poppler-utils |
| |
| - name: Install Python dependencies |
| run: | |
| python -m pip install --upgrade pip |
| pip install -r requirements.txt |
| pip install pytest pytest-cov httpx |
| |
| - name: Run tests |
| run: | |
| pytest tests/ -v --cov=app --cov-report=xml |
| |
| - name: Upload coverage |
| uses: codecov/codecov-action@v3 |
| with: |
| file: ./coverage.xml |
| fail_ci_if_error: false |
|
|
| docker-build: |
| runs-on: ubuntu-latest |
| needs: test |
| |
| steps: |
| - uses: actions/checkout@v3 |
| |
| - name: Set up Docker Buildx |
| uses: docker/setup-buildx-action@v2 |
| |
| - name: Build Docker image |
| run: | |
| docker build -t pdf-redaction-api:test . |
| |
| - name: Test Docker image |
| run: | |
| docker run -d -p 7860:7860 --name test-api pdf-redaction-api:test |
| sleep 10 |
| curl -f http://localhost:7860/health || exit 1 |
| docker stop test-api |
| |
| deploy-huggingface: |
| runs-on: ubuntu-latest |
| needs: [test, docker-build] |
| if: github.ref == 'refs/heads/main' |
| |
| steps: |
| - uses: actions/checkout@v3 |
| |
| - name: Deploy to HuggingFace Spaces |
| env: |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} |
| run: | |
| git config --global user.email "github-actions@github.com" |
| git config --global user.name "GitHub Actions" |
| |
| |
| git remote add hf https://user:$HF_TOKEN@huggingface.co/spaces/${{ secrets.HF_SPACE }} || true |
| |
| |
| git push hf main:main |
|
|