Spaces:
Sleeping
Sleeping
| name: CI - Tests & Lint | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Necessario per permettere il push completo | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install flake8 pytest black | |
| - name: Set HuggingFace token | |
| run: echo "${{ secrets.HFREPO }}" > ~/.hf_token | |
| - name: Cache Hugging Face and datasets | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/huggingface | |
| ~/.cache/datasets | |
| key: ${{ runner.os }}-hf-${{ hashFiles('requirements.txt') }} | |
| - name: Prepare processed data | |
| run: | | |
| mkdir -p data/processed | |
| python src/data_preparation.py tweet_eval | |
| python src/data_preparation.py youtube | |
| env: | |
| HF_TOKEN: ${{ secrets.HFREPO }} | |
| - name: Format code with Black | |
| run: | | |
| black --line-length 100 src tests | |
| - name: Lint with flake8 | |
| run: | | |
| flake8 src tests --max-line-length=100 --exclude=__init__.py | |
| continue-on-error: true | |
| - name: Run tests | |
| run: | | |
| export PYTHONPATH=$PYTHONPATH:$(pwd) | |
| pytest --maxfail=1 --disable-warnings -q | |
| env: | |
| HF_TOKEN: ${{ secrets.HFREPO }} | |
| - name: Configure Git identity for CI | |
| run: | | |
| git config --global user.email "ci-bot@users.noreply.github.com" | |
| git config --global user.name "GitHub Actions" | |
| - name: Push app update to Hugging Face Space | |
| run: | | |
| echo "Checking for changes before pushing..." | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "Changes detected — committing and pushing to Hugging Face " | |
| git add . | |
| git commit -m "Auto-deploy new version [skip ci]" || echo "No commit needed" | |
| git pull https://user:${HF_TOKEN}@huggingface.co/spaces/Lordemarco/sentiment-fastapi main --rebase || true | |
| git push https://user:${HF_TOKEN}@huggingface.co/spaces/Lordemarco/sentiment-fastapi main --force | |
| else | |
| echo "No changes to push " | |
| fi | |
| env: | |
| HF_TOKEN: ${{ secrets.HFREPO }} | |