Abhinav Gavireddi commited on
Commit
481c367
·
1 Parent(s): b3e9681

fix: fixed issue with pushing codes to HF

Browse files
Files changed (1) hide show
  1. .github/workflows/ci.yaml +30 -17
.github/workflows/ci.yaml CHANGED
@@ -25,30 +25,43 @@ jobs:
25
  # if [ -f tests/test.py ]; then python -m unittest discover -s tests; fi
26
 
27
  deploy-to-hf:
28
- needs: build-and-test
29
  runs-on: ubuntu-latest
30
- if: github.ref == 'refs/heads/main'
31
  environment: prod
32
  steps:
33
- - name: Checkout repo
34
  uses: actions/checkout@v3
35
  with:
36
- fetch-depth: 0
 
 
 
 
 
 
 
 
37
 
38
- - name: Set up Docker Buildx
39
- uses: docker/setup-buildx-action@v3
 
 
 
 
 
 
 
40
 
41
- - name: Log in to Hugging Face Docker
42
- run: echo "${{ secrets.HF_TOKEN }}" | docker login --username ${{ secrets.HF_USERNAME }} --password-stdin registry.huggingface.co
43
 
44
- - name: Build Docker image
45
- run: docker build -t registry.huggingface.co/${{ secrets.HF_USERNAME }}/${{ secrets.HF_SPACE_NAME }}:latest .
46
 
47
- - name: Push Docker image to Hugging Face
48
- run: docker push registry.huggingface.co/${{ secrets.HF_USERNAME }}/${{ secrets.HF_SPACE_NAME }}:latest
49
 
50
- # Optionally, trigger a Space restart via the API (not strictly required)
51
- - name: Restart Hugging Face Space
52
- run: |
53
- pip install huggingface_hub
54
- python -c "from huggingface_hub import HfApi; HfApi(token='${{ secrets.HF_TOKEN }}').restart_space('${{ secrets.HF_USERNAME }}', '${{ secrets.HF_SPACE_NAME }}')"
 
25
  # if [ -f tests/test.py ]; then python -m unittest discover -s tests; fi
26
 
27
  deploy-to-hf:
 
28
  runs-on: ubuntu-latest
 
29
  environment: prod
30
  steps:
31
+ - name: Checkout code
32
  uses: actions/checkout@v3
33
  with:
34
+ fetch-depth: 0 # Full git history if needed for versioning or changelog
35
+
36
+ - name: Set up Python
37
+ uses: actions/setup-python@v4
38
+ with:
39
+ python-version: '3.10' # Use whatever version you prefer
40
+
41
+ - name: Install Hugging Face Hub client
42
+ run: pip install huggingface_hub
43
 
44
+ - name: Push to Hugging Face Space
45
+ env:
46
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
47
+ HF_USERNAME: ${{ secrets.HF_USERNAME }}
48
+ HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
49
+ run: |
50
+ echo "Pushing latest code to Hugging Face Space"
51
+ git config --global user.email "[email protected]"
52
+ git config --global user.name "Abhinav_Gavireddi"
53
 
54
+ # Set up Hugging Face CLI
55
+ huggingface-cli login --token "$HF_TOKEN"
56
 
57
+ # Add Hugging Face as remote
58
+ git remote add hf https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}
59
 
60
+ # Push code to the Space repo
61
+ git push hf main
62
 
63
+ # Optional: Restart Space via API (defensive move)
64
+ python -c "
65
+ from huggingface_hub import HfApi;
66
+ api = HfApi(token='$HF_TOKEN');
67
+ api.restart_space(repo_id='${HF_USERNAME}/${HF_SPACE_NAME}')