| name: Deploiement vers Hugging Face Spaces | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| PROJET05_DATABASE_URL: postgresql+psycopg://postgres:postgres@localhost:5432/projet05 | |
| PROJET05_TEST_DATABASE_URL: postgresql+psycopg://postgres:postgres@localhost:5432/projet05_test | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd "pg_isready -U postgres" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| pip install -e . | |
| - name: Install PostgreSQL client | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y postgresql-client | |
| - name: Prepare databases | |
| env: | |
| PGPASSWORD: postgres | |
| run: | | |
| psql -h localhost -U postgres -c "DROP DATABASE IF EXISTS projet05;" | |
| psql -h localhost -U postgres -c "DROP DATABASE IF EXISTS projet05_test;" | |
| psql -h localhost -U postgres -c "CREATE DATABASE projet05;" | |
| psql -h localhost -U postgres -c "CREATE DATABASE projet05_test;" | |
| - name: Run tests | |
| run: pytest | |
| - name: Préparer les données et le modèle | |
| run: python main.py | |
| - name: Deploy to Hugging Face Space | |
| 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/projet_05 hf_space | |
| rsync -av --exclude '.git' --exclude 'docs' ./ 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/projet_05 main | |