ParallelLLC/algorithmic_trading
2732
1name: Sync Hugging Face Space2 3# Publishes app.py + the algotrader package to a Hugging Face Space.4#5# Setup (one time):6# 1. Create the Space at https://huggingface.co/new-space with SDK "Gradio".7# 2. Add repository secret HF_TOKEN — a write token from8# https://huggingface.co/settings/tokens9# 3. Add repository variable HF_SPACE_ID, e.g. "your-username/backtest-reality-check".10#11# Without those set the job is skipped, so forks and PRs are unaffected.12 13on:14 push:15 branches: [main]16 paths:17 - 'app.py'18 - 'algotrader/**'19 - 'SPACE_README.md'20 - 'requirements-space.txt'21 - 'tests/test_v2_*.py'22 - '.github/workflows/sync-hf-space.yml'23 workflow_dispatch:24 25jobs:26 sync:27 runs-on: ubuntu-latest28 if: vars.HF_SPACE_ID != ''29 steps:30 - uses: actions/checkout@v431 32 - uses: actions/setup-python@v533 with:34 python-version: '3.11'35 36 - name: Verify the Space actually runs before publishing it37 run: |38 pip install --quiet -r requirements-space.txt pytest39 python -m pytest tests/test_v2_engine.py tests/test_v2_validation.py \40 tests/test_v2_strategies.py tests/test_v2_portfolio.py -q41 ALGOTRADER_OFFLINE=1 python -c "import app; app.build_app(); print('Space builds OK')"42 43 - name: Push to the Space44 env:45 HF_TOKEN: ${{ secrets.HF_TOKEN }}46 run: |47 if [ -z "$HF_TOKEN" ]; then48 echo "HF_TOKEN secret is not set; skipping publish." >&249 exit 050 fi51 chmod +x scripts/deploy_hf_space.sh52 ./scripts/deploy_hf_space.sh "${{ vars.HF_SPACE_ID }}"53 