name: CI/CD — Neural Machine Translation on: push: branches: [main] pull_request: branches: [main] workflow_dispatch: env: PYTHON_VERSION: "3.12" # JOB 1 — Lint & Unit Tests (no model download) jobs: test: name: Lint & Unit Tests runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - name: Cache pip uses: actions/cache@v4 with: path: ~/.cache/pip key: pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt', 'pyproject.toml') }} restore-keys: | pip-${{ env.PYTHON_VERSION }}- - name: Install dependencies run: | python -m pip install --upgrade pip pip install -e . --quiet pip install -r requirements.txt --quiet - name: Lint with Ruff (non-blocking) run: | pip install ruff --quiet ruff check . --output-format=github || true - name: Run unit tests (no model required) run: | pytest tests/ \ -m "not integration" \ --tb=short \ -v \ --no-header env: TRANSFORMERS_OFFLINE: "1" HF_DATASETS_OFFLINE: "1" # JOB 2 — Deploy to Hugging Face Spaces (main branch only) deploy: name: Deploy to Hugging Face Space runs-on: ubuntu-latest needs: test if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - name: 📦 Cache pip uses: actions/cache@v4 with: path: ~/.cache/pip key: pip-deploy-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt') }} restore-keys: | pip-deploy-${{ env.PYTHON_VERSION }}- - name: 🛡️ Validate secrets are set run: | if [ -z "${{ secrets.HF_TOKEN }}" ]; then echo "HF_TOKEN secret is not set. Aborting." exit 1 fi if [ -z "${{ secrets.HF_SPACE_ID }}" ]; then echo "HF_SPACE_ID secret is not set. Aborting." exit 1 fi - name: Install huggingface-hub CLI run: pip install huggingface-hub --quiet - name: Push repository to Hugging Face Space run: | git config user.email "ci@github-actions" git config user.name "GitHub Actions" git remote add hf "https://user:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/${{ secrets.HF_SPACE_ID }}" git push hf main --force - name: Deployment success notification run: | echo "🎉 Deployed → https://huggingface.co/spaces/${{ secrets.HF_SPACE_ID }}"