Spaces:
Runtime error
Runtime error
Add GitHub Actions workflows
Browse files- sync-to-huggingface.yml: Auto-deploy to HF Spaces on push
- lint-and-test.yml: Code quality checks
- health-check.yml: Monitor deployed space hourly
.github/workflows/health-check.yml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Health Check Workflow
|
| 2 |
+
# Monitors the deployed Hugging Face Space
|
| 3 |
+
name: Health Check
|
| 4 |
+
|
| 5 |
+
on:
|
| 6 |
+
schedule:
|
| 7 |
+
# Run every hour
|
| 8 |
+
- cron: '0 * * * *'
|
| 9 |
+
workflow_dispatch:
|
| 10 |
+
|
| 11 |
+
jobs:
|
| 12 |
+
health:
|
| 13 |
+
runs-on: ubuntu-latest
|
| 14 |
+
steps:
|
| 15 |
+
- name: Check HF Space Health
|
| 16 |
+
run: |
|
| 17 |
+
response=$(curl -s -o /dev/null -w "%{http_code}" https://mmrech-medsam2-server.hf.space/api/health || echo "000")
|
| 18 |
+
if [ "$response" = "200" ]; then
|
| 19 |
+
echo "✅ Space is healthy"
|
| 20 |
+
exit 0
|
| 21 |
+
else
|
| 22 |
+
echo "❌ Space health check failed (HTTP $response)"
|
| 23 |
+
exit 1
|
| 24 |
+
fi
|
| 25 |
+
|
| 26 |
+
- name: Notify on failure
|
| 27 |
+
if: failure()
|
| 28 |
+
uses: actions/github-script@v7
|
| 29 |
+
with:
|
| 30 |
+
script: |
|
| 31 |
+
github.rest.issues.create({
|
| 32 |
+
owner: context.repo.owner,
|
| 33 |
+
repo: context.repo.repo,
|
| 34 |
+
title: '🚨 NeuroSeg Server Health Check Failed',
|
| 35 |
+
body: `Health check failed at ${new Date().toISOString()}\n\nPlease check the Hugging Face Space: https://mmrech-medsam2-server.hf.space`,
|
| 36 |
+
labels: ['bug', 'infrastructure']
|
| 37 |
+
})
|
.github/workflows/lint-and-test.yml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Lint and Test Workflow
|
| 2 |
+
name: Lint and Test
|
| 3 |
+
|
| 4 |
+
on:
|
| 5 |
+
push:
|
| 6 |
+
branches: [main, develop]
|
| 7 |
+
pull_request:
|
| 8 |
+
branches: [main]
|
| 9 |
+
|
| 10 |
+
jobs:
|
| 11 |
+
lint:
|
| 12 |
+
runs-on: ubuntu-latest
|
| 13 |
+
steps:
|
| 14 |
+
- name: Checkout
|
| 15 |
+
uses: actions/checkout@v4
|
| 16 |
+
|
| 17 |
+
- name: Setup Python
|
| 18 |
+
uses: actions/setup-python@v5
|
| 19 |
+
with:
|
| 20 |
+
python-version: '3.10'
|
| 21 |
+
|
| 22 |
+
- name: Install dependencies
|
| 23 |
+
run: |
|
| 24 |
+
python -m pip install --upgrade pip
|
| 25 |
+
pip install flake8 black isort
|
| 26 |
+
|
| 27 |
+
- name: Lint with flake8
|
| 28 |
+
run: |
|
| 29 |
+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics || true
|
| 30 |
+
|
| 31 |
+
- name: Check formatting with black
|
| 32 |
+
run: |
|
| 33 |
+
black --check . || true
|
| 34 |
+
|
| 35 |
+
- name: Check imports with isort
|
| 36 |
+
run: |
|
| 37 |
+
isort --check-only . || true
|
| 38 |
+
|
| 39 |
+
test-syntax:
|
| 40 |
+
runs-on: ubuntu-latest
|
| 41 |
+
steps:
|
| 42 |
+
- name: Checkout
|
| 43 |
+
uses: actions/checkout@v4
|
| 44 |
+
|
| 45 |
+
- name: Setup Python
|
| 46 |
+
uses: actions/setup-python@v5
|
| 47 |
+
with:
|
| 48 |
+
python-version: '3.10'
|
| 49 |
+
|
| 50 |
+
- name: Test Python syntax
|
| 51 |
+
run: |
|
| 52 |
+
python -m py_compile app.py
|
| 53 |
+
echo "✅ Python syntax OK"
|
.github/workflows/sync-to-huggingface.yml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Sync NeuroSeg Server to Hugging Face Spaces
|
| 2 |
+
# This workflow automatically deploys the server to Hugging Face Spaces when pushing to main
|
| 3 |
+
name: Sync to Hugging Face Spaces
|
| 4 |
+
|
| 5 |
+
on:
|
| 6 |
+
push:
|
| 7 |
+
branches: [main]
|
| 8 |
+
workflow_dispatch:
|
| 9 |
+
|
| 10 |
+
jobs:
|
| 11 |
+
sync:
|
| 12 |
+
runs-on: ubuntu-latest
|
| 13 |
+
steps:
|
| 14 |
+
- name: Checkout
|
| 15 |
+
uses: actions/checkout@v4
|
| 16 |
+
with:
|
| 17 |
+
fetch-depth: 0
|
| 18 |
+
lfs: true
|
| 19 |
+
|
| 20 |
+
- name: Setup Git
|
| 21 |
+
run: |
|
| 22 |
+
git config user.name "GitHub Actions"
|
| 23 |
+
git config user.email "actions@github.com"
|
| 24 |
+
|
| 25 |
+
- name: Push to Hugging Face
|
| 26 |
+
env:
|
| 27 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 28 |
+
run: |
|
| 29 |
+
git remote add hf https://user:${HF_TOKEN}@huggingface.co/spaces/mmrech/medsam2-server
|
| 30 |
+
git push hf main --force
|