fixing drag #33
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Hugging Face Spaces | |
| on: | |
| push: | |
| branches: [ main, docker_beauty ] # TODO: remove docker_beauty before merging | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| env: | |
| HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN }} | |
| HF_SPACE_REPO: ${{ secrets.HUGGINGFACE_SPACE_REPO }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| lfs: true | |
| - name: Validate secrets | |
| run: | | |
| if [ -z "$HF_TOKEN" ]; then | |
| echo "ERROR: HUGGINGFACE_TOKEN secret is not set." >&2 | |
| exit 1 | |
| fi | |
| if [ -z "$HF_SPACE_REPO" ]; then | |
| echo "ERROR: HUGGINGFACE_SPACE_REPO secret is not set." >&2 | |
| exit 1 | |
| fi | |
| - name: Configure git | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| git config --global credential.helper store | |
| # HF accepts any username when authenticating via token | |
| printf 'https://user:%s@huggingface.co\n' "$HF_TOKEN" > ~/.git-credentials | |
| git lfs install | |
| - name: Clone existing HF Space | |
| run: | | |
| git clone "https://huggingface.co/spaces/$HF_SPACE_REPO" space_repo | |
| cd space_repo | |
| git lfs install | |
| - name: Sync files into Space | |
| run: | | |
| cd space_repo | |
| # Ensure LFS tracks model file types | |
| cat > .gitattributes <<'EOF' | |
| *.pt filter=lfs diff=lfs merge=lfs -text | |
| *.pth filter=lfs diff=lfs merge=lfs -text | |
| *.bin filter=lfs diff=lfs merge=lfs -text | |
| *.h5 filter=lfs diff=lfs merge=lfs -text | |
| *.onnx filter=lfs diff=lfs merge=lfs -text | |
| EOF | |
| # Sync application files | |
| cp ../app.py . | |
| cp ../requirements.txt . | |
| cp ../Dockerfile . | |
| cp ../yolo_utils.py . | |
| cp ../README.md . | |
| cp -r ../templates . | |
| cp -r ../static . | |
| # Sync model weight files | |
| find .. -maxdepth 1 -type f \( -name "*.pt" -o -name "*.onnx" \) -exec cp {} . \; | |
| echo "Files to be committed:" | |
| ls -lh | |
| - name: Commit and push | |
| run: | | |
| cd space_repo | |
| echo "--- Remote URL ---" | |
| git remote -v | |
| echo "--- Current HEAD ---" | |
| git log --oneline -3 | |
| git add . | |
| if git diff --cached --quiet; then | |
| echo "No changes to deploy." | |
| else | |
| git commit -m "deploy: sync from GitHub ${{ github.sha }}" | |
| git push -v origin main | |
| fi | |
| - name: Summary | |
| run: | | |
| echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Space**: [spaces/$HF_SPACE_REPO](https://huggingface.co/spaces/$HF_SPACE_REPO)" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Model files deployed:" >> $GITHUB_STEP_SUMMARY | |
| cd space_repo | |
| for file in *.pt *.onnx; do | |
| [ -f "$file" ] && echo "- \`$file\` ($(ls -lh "$file" | awk '{print $5}'))" >> $GITHUB_STEP_SUMMARY | |
| done | |
| for file in *.pt *.onnx; do | |
| [ -f "$file" ] && echo "- \`$file\` ($(ls -lh "$file" | awk '{print $5}'))" >> $GITHUB_STEP_SUMMARY | |
| done |