IDKHowToCodeFr commited on
Commit
f523f57
·
1 Parent(s): 2322c22

ci: add space restart workflow on push and 30-hour keep-alive ping

Browse files
.github/workflows/deploy.yml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deploy and Restart HF Space
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-and-restart:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout Code
14
+ uses: actions/checkout@v4
15
+ with:
16
+ fetch-depth: 0
17
+ lfs: true
18
+
19
+ - name: Sync to Hugging Face Space & Restart
20
+ env:
21
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
22
+ HF_SPACE: ${{ secrets.HF_SPACE }}
23
+ run: |
24
+ if [ -z "$HF_TOKEN" ]; then
25
+ echo "HF_TOKEN secret not set. Skipping Hugging Face sync."
26
+ exit 0
27
+ fi
28
+
29
+ SPACE_REPO="${HF_SPACE:-rachit-mangawa/hf-backend}"
30
+ echo "Syncing code to Hugging Face Space: $SPACE_REPO..."
31
+ git push "https://rachit-mangawa:${HF_TOKEN}@huggingface.co/spaces/${SPACE_REPO}" main:main --force
32
+
33
+ echo "Triggering Space restart..."
34
+ curl -f -s -X POST "https://huggingface.co/api/spaces/${SPACE_REPO}/restart" \
35
+ -H "Authorization: Bearer ${HF_TOKEN}" || echo "Space restart API request sent."
.github/workflows/keep_alive.yml CHANGED
@@ -2,7 +2,7 @@ name: Space Keep Alive
2
 
3
  on:
4
  schedule:
5
- - cron: "*/30 * * * *"
6
  workflow_dispatch:
7
 
8
  jobs:
@@ -11,9 +11,16 @@ jobs:
11
  steps:
12
  - name: Ping Health Endpoint
13
  run: |
 
 
 
 
 
 
14
  TARGET_URL="${{ secrets.HF_SPACE_URL }}"
15
  if [ -z "$TARGET_URL" ]; then
16
  TARGET_URL="https://rachit-mangawa-hf-backend.hf.space/health"
17
  fi
18
- echo "Pinging ${TARGET_URL}..."
 
19
  curl --fail --show-error --silent --max-time 30 "$TARGET_URL" || exit 1
 
2
 
3
  on:
4
  schedule:
5
+ - cron: "0 */6 * * *"
6
  workflow_dispatch:
7
 
8
  jobs:
 
11
  steps:
12
  - name: Ping Health Endpoint
13
  run: |
14
+ HOUR=$(python3 -c "import time; print(int(time.time() // 3600))")
15
+ if [ "${{ github.event_name }}" != "workflow_dispatch" ] && [ $((HOUR % 30)) -ge 6 ]; then
16
+ echo "Skipping ping: not at 30-hour mark (Hour: $HOUR, Remainder: $((HOUR % 30)))."
17
+ exit 0
18
+ fi
19
+
20
  TARGET_URL="${{ secrets.HF_SPACE_URL }}"
21
  if [ -z "$TARGET_URL" ]; then
22
  TARGET_URL="https://rachit-mangawa-hf-backend.hf.space/health"
23
  fi
24
+
25
+ echo "Sending one keep-alive ping to ${TARGET_URL}..."
26
  curl --fail --show-error --silent --max-time 30 "$TARGET_URL" || exit 1