SteGONZALEZ's picture
modificarion CD
419cbae
Raw
History Blame Contribute Delete
2.46 kB
name: CD
on:
push:
branches: ["main"]
jobs:
test:
name: tests_CD
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: "2.0.0"
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies (with dev)
run: poetry install --no-interaction --with dev
- name: Run tests (SQLite file)
env:
API_KEY: "ci-test-key"
DATABASE_URL: "sqlite+pysqlite:////tmp/test.db"
run: poetry run pytest -q
build-and-push:
name: build_and_push_GHCR
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compute image name (lowercase)
id: vars
run: echo "image_name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ steps.vars.outputs.image_name }}:latest
${{ steps.vars.outputs.image_name }}:${{ github.sha }}
deploy-huggingface:
name: deploy_to_huggingface
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Push to Hugging Face Space (force)
env:
HF_TOKEN: "${{ secrets.HF_TOKEN }}"
run: |
set -euo pipefail
git config --global user.email "ci@github.com"
git config --global user.name "github-actions"
# évite l'erreur si le remote existe déjà
git remote remove hf 2>/dev/null || true
git remote add hf https://huggingface.co/spaces/SteGONZALEZ/technova-api
# push authentifié vers HF (avec token) + force comme tu fais d'habitude
git push --force https://SteGONZALEZ:${HF_TOKEN}@huggingface.co/spaces/SteGONZALEZ/technova-api main