File size: 1,969 Bytes
7c8c999
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
set -euo pipefail

# Merge origin/main into huggingface-space-deployment while preserving
# HF-specific overrides (Dockerfile port/CMD, README frontmatter, app.py).

BRANCH="huggingface-space-deployment"
HF_FILES=(Dockerfile README.md app.py)

echo "==> Fetching origin..."
git fetch origin

echo "==> Switching to $BRANCH..."
git checkout "$BRANCH"

# Stash HF-specific files before merge so they survive any conflicts.
echo "==> Stashing HF-specific files..."
for f in "${HF_FILES[@]}"; do
  [ -f "$f" ] && cp "$f" "/tmp/_hfsd_${f//\//_}"
done

echo "==> Merging origin/main..."
if ! git merge origin/main --no-edit; then
  echo ""
  echo "*** Merge produced conflicts. Resolving HF-specific files..."
  for f in "${HF_FILES[@]}"; do
    if git diff --name-only --diff-filter=U | grep -qx "$f"; then
      cp "/tmp/_hfsd_${f//\//_}" "$f"
      git add "$f"
      echo "    Resolved: $f (kept HF version)"
    fi
  done
  git commit --no-edit
fi

# Ensure README has HF frontmatter.
if ! head -1 README.md | grep -q '^---'; then
  echo "==> Re-adding HF frontmatter to README.md..."
  TMP=$(mktemp)
  cat > "$TMP" <<'FRONTMATTER'
---
title: FALZH
sdk: docker
emoji: "\U0001F680"
colorFrom: blue
colorTo: blue
pinned: true
---

FRONTMATTER
  cat README.md >> "$TMP"
  mv "$TMP" README.md
  git add README.md
  git commit -m "Restore HF README frontmatter" --no-edit
fi

# Ensure Dockerfile has HF overrides (port 7860, python entrypoint).
if ! grep -q 'PORT=7860' Dockerfile; then
  echo "==> Restoring HF Dockerfile overrides..."
  sed -i 's/^ENV PYTHONUNBUFFERED=1$/ENV PYTHONUNBUFFERED=1 \\\n    PORT=7860/' Dockerfile
  sed -i 's/^EXPOSE .*/EXPOSE 7860/' Dockerfile
  sed -i 's|^CMD .*|CMD ["python", "app.py"]|' Dockerfile
  git add Dockerfile
  git commit -m "Restore HF Dockerfile overrides" --no-edit
fi

echo ""
echo "==> Done! $BRANCH is now up to date with origin/main + HF overrides."
echo "    Run 'git push origin $BRANCH' to deploy."