name: CI/CD to Hugging Face Space with uv on: push: branches: - main # Or your default branch, e.g., 'master', 'dev' jobs: deploy: runs-on: ubuntu-latest steps: - name: Check for HF_TOKEN availability id: check_hf_token env: HF_TOKEN_CHECK: ${{ secrets.HF_TOKEN }} # Pass the secret to an env var for shell check run: | if [ -z "$HF_TOKEN_CHECK" ]; then echo "::notice::HF_TOKEN secret is not set. Hugging Face Space push will be skipped." echo "push_enabled=false" >> $GITHUB_OUTPUT else echo "::notice::HF_TOKEN secret is set. Proceeding with Hugging Face Space push." echo "push_enabled=true" >> $GITHUB_OUTPUT fi - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 lfs: true - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.10" # Recommended: specify a precise version like '3.10', '3.11', or '3.12' - name: Install uv # Installs the uv tool on the GitHub Actions runner uses: astral-sh/setup-uv@v1 - name: Check for pyproject.toml existence id: check_pyproject run: | if [ -f requirements.txt ]; then echo "::notice::requirements.txt already exists. Skipping uv generation." echo "generate_reqs=false" >> $GITHUB_OUTPUT elif [ -f pyproject.toml ]; then echo "::notice::pyproject.toml found and no requirements.txt. Proceeding with uv pip compile." echo "generate_reqs=true" >> $GITHUB_OUTPUT else echo "::notice::Neither requirements.txt nor pyproject.toml found. Skipping uv pip compile." echo "generate_reqs=false" >> $GITHUB_OUTPUT fi - name: Generate requirements.txt using uv id: generate_reqs # This step will only run if pyproject.toml was found in the previous step if: ${{ steps.check_pyproject.outputs.generate_reqs == 'true' }} run: | # Use uv pip compile to generate a locked requirements.txt from pyproject.toml # This ensures reproducibility. uv export --no-hashes --format requirements-txt > requirements.txt # uv pip compile pyproject.toml -o requirements.txt # Check if requirements.txt was created if [ -f requirements.txt ]; then echo "requirements.txt generated successfully:" cat requirements.txt else echo "Error: requirements.txt was not generated despite pyproject.toml existing." exit 1 fi - name: Commit requirements.txt if changed if: ${{ steps.check_pyproject.outputs.generate_reqs == 'true' }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add requirements.txt git commit -m "chore: update requirements.txt [auto-generated by CI]" echo "requirements.txt committed." - name: Push to HuggingFace Space if: ${{ steps.check_hf_token.outputs.push_enabled == 'true' }} env: HF_TOKEN: ${{ secrets.HF_TOKEN }} FORCE_PUSH: ${{ secrets.FORCE_PUSH }} run: | if [ -z "$FORCE_PUSH" ]; then echo "::notice::FORCE_PUSH secret is not set." git push https://GF-John:$HF_TOKEN@huggingface.co/spaces/GF-John/video-caption main else echo "::notice::FORCE_PUSH secret is set. Doing Force Push toHugging Face Space." git push -f https://GF-John:$HF_TOKEN@huggingface.co/spaces/GF-John/video-caption main fi