|
name: CI & Deploy |
|
|
|
on: |
|
push: |
|
branches: [ main ] |
|
pull_request: |
|
branches: [ main ] |
|
|
|
jobs: |
|
build-and-test: |
|
runs-on: ubuntu-latest |
|
steps: |
|
- name: Checkout repo |
|
uses: actions/checkout@v3 |
|
- name: Set up Python |
|
uses: actions/setup-python@v4 |
|
with: |
|
python-version: '3.10' |
|
- name: Install dependencies |
|
run: | |
|
python -m pip install --upgrade pip |
|
pip install uv |
|
uv pip install --system -r requirements.txt |
|
|
|
|
|
|
|
|
|
deploy-to-hf: |
|
runs-on: ubuntu-latest |
|
needs: build-and-test |
|
environment: prod |
|
steps: |
|
- name: Checkout code |
|
uses: actions/checkout@v3 |
|
with: |
|
fetch-depth: 0 |
|
|
|
- name: Set up Python |
|
uses: actions/setup-python@v4 |
|
with: |
|
python-version: '3.10' |
|
|
|
- name: Install Hugging Face Hub client |
|
run: pip install huggingface_hub |
|
|
|
- name: Configure Git credential helper |
|
run: | |
|
# Use the "store" helper so huggingface-cli can write credentials here |
|
git config --global credential.helper store |
|
|
|
- name: Push to Hugging Face Space |
|
env: |
|
HF_TOKEN: ${{ secrets.HF_TOKEN }} |
|
HF_USERNAME: ${{ secrets.HF_USERNAME }} |
|
HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }} |
|
run: | |
|
echo "π Pushing code to HF Space..." |
|
|
|
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com" |
|
git config --global user.name "github-actions[bot]" |
|
|
|
|
|
huggingface-cli login --token "$HF_TOKEN" --add-to-git-credential |
|
|
|
|
|
git remote add hf https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}.git |
|
|
|
git fetch hf main |
|
git push hf main --force |
|
|
|
|
|
python -c "from huggingface_hub import HfApi; api = HfApi(token='$HF_TOKEN'); api.restart_space(repo_id='${HF_USERNAME}/${HF_SPACE_NAME}')" |
|
|