Spaces:
Sleeping
Sleeping
chaton59
commited on
Commit
·
4114067
1
Parent(s):
d56625a
feat: add initial CI/CD pipeline with GitHub Actions (tests + HF deploy)
Browse files- .github/workflows/ci-cd.yml +54 -0
.github/workflows/ci-cd.yml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: CI/CD Pipeline # Nom lisible dans tab Actions GitHub
|
| 2 |
+
|
| 3 |
+
on: # Triggers du plan : push/PR pour isolation envs
|
| 4 |
+
push:
|
| 5 |
+
branches: [dev, main]
|
| 6 |
+
pull_request:
|
| 7 |
+
branches: [main]
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
test: # Job CI : Qualité code/ML (étapes 1-5 plan, séquentiel)
|
| 11 |
+
runs-on: ubuntu-latest # Env gratuit/rapide (<10min cible)
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v4 # Étape 1 : Récup repo
|
| 14 |
+
- name: Set up Python
|
| 15 |
+
uses: actions/setup-python@v5
|
| 16 |
+
with:
|
| 17 |
+
python-version: '3.10' # Fixe pour reproductibilité (ML P3/P4)
|
| 18 |
+
- name: Cache pip # Accélère deps futures (perf reco)
|
| 19 |
+
uses: actions/cache@v4
|
| 20 |
+
with:
|
| 21 |
+
path: ~/.cache/pip
|
| 22 |
+
key: $$ {{ runner.os }}-pip- $${{ hashFiles('requirements.txt') }}
|
| 23 |
+
- name: Install dependencies
|
| 24 |
+
run: |
|
| 25 |
+
python -m pip install --upgrade pip
|
| 26 |
+
pip install -r requirements.txt # Tes deps (FastAPI, SQLAlchemy, etc.)
|
| 27 |
+
pip install pytest pytest-cov black flake8 # Outils lint/tests (plan)
|
| 28 |
+
- name: Lint code # Étape 4 : Standards (black pour format auto, flake8 erreurs)
|
| 29 |
+
run: black --check . && flake8 . # Fail si style KO
|
| 30 |
+
- name: Run tests # Étape 5 : Couverture >80% (cas critiques Pydantic/ML)
|
| 31 |
+
run: pytest --cov=src --cov-report=xml tests/ # Assume tests/ ; XML pour badges
|
| 32 |
+
- name: Upload coverage # Optionnel : Rapport GitHub (monitoring plan)
|
| 33 |
+
uses: codecov/codecov-action@v4
|
| 34 |
+
with:
|
| 35 |
+
file: ./coverage.xml
|
| 36 |
+
|
| 37 |
+
deploy: # Job CD : Déploiement (après test OK, conditionnel)
|
| 38 |
+
needs: test # Dépend CI (séquentiel plan)
|
| 39 |
+
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main' # Branches seulement
|
| 40 |
+
runs-on: ubuntu-latest
|
| 41 |
+
steps:
|
| 42 |
+
- uses: actions/checkout@v4
|
| 43 |
+
- name: Deploy to HF Spaces # Étape 7 : Push vers oc_p5 (dev/main)
|
| 44 |
+
uses: huggingface/huggingface-hub@v4 # Action HF pour auth/push facile (simule git push hf)
|
| 45 |
+
env:
|
| 46 |
+
HUGGINGFACE_TOKEN: ${{ secrets.HF_TOKEN }} # Secret (2.4)
|
| 47 |
+
with:
|
| 48 |
+
huggingface_repo: ASI-Engineer/oc_p5 # Ton Space dev (crée oc_p5-prod pour main si besoin)
|
| 49 |
+
repo_type: space # Type Space (pas model)
|
| 50 |
+
- name: Fallback git push to HF # Si hub fail (ton remote hf backup)
|
| 51 |
+
run: |
|
| 52 |
+
git remote add hf https://huggingface.co/spaces/ASI-Engineer/oc_p5 || true
|
| 53 |
+
git config --global url."https://${{ secrets.HF_TOKEN }}@huggingface.co".insteadOf "https://huggingface.co"
|
| 54 |
+
git push hf HEAD:${{ github.ref_name }} # Push branche courante
|