GitHub Actions
Auto-deploy from GitHub Actions
decf87a
name: ci-cd
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
test-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: pytest --cov=app --cov=monitoring --cov-report=term-missing -q
- name: Build Docker image
run: docker build -t ocr-projet06:ci .
- name: Deploy to Hugging Face Space
if: github.ref == 'refs/heads/main'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git clone https://huggingface.co/spaces/stephmnt/credit-scoring-mlops hf_space
rsync -av \
--exclude '.git' \
--exclude '.venv' \
--exclude '.pytest_cache' \
--exclude '__pycache__' \
--exclude 'mlruns' \
--exclude '*.ipynb' \
--exclude 'logs' \
--exclude 'reports' \
--exclude 'screen-mlflow.png' \
--exclude 'artifacts/preprocessor.joblib' \
--exclude 'data/*.csv' \
--exclude 'data/*.parquet' \
--exclude 'notebooks/mlflow.db' \
./ hf_space/
cd hf_space
git add .
git commit -m "Auto-deploy from GitHub Actions" || echo "No changes to commit"
git push https://stephmnt:${HF_TOKEN}@huggingface.co/spaces/stephmnt/credit-scoring-mlops main