3v324v23 commited on
Commit
41efb32
·
1 Parent(s): 69eaa4c

Add the mathly deploy script

Browse files
Files changed (1) hide show
  1. scripts/deploy_mathly.sh +27 -0
scripts/deploy_mathly.sh ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Deploys the current commit to the mathly Space (the math app) under its own name.
3
+ # A Space takes its name and emoji from the front matter of README.md, which ihki and mathly share; this pushes a
4
+ # copy of HEAD whose front matter says mathly, so the local README and the Arabic Space (origin) stay as they are.
5
+ # Usage: scripts/deploy_mathly.sh (commit first; the remote `mathly` is https://huggingface.co/spaces/wzender/mathly)
6
+ set -euo pipefail
7
+ cd "$(git rev-parse --show-toplevel)"
8
+ if [ -n "$(git status --porcelain)" ]; then
9
+ echo "There are uncommitted changes. Commit them first: only committed work is deployed." >&2
10
+ exit 1
11
+ fi
12
+ tmp=$(mktemp -d)
13
+ trap 'git worktree remove --force "$tmp" >/dev/null 2>&1 || true; rm -rf "$tmp"' EXIT
14
+ git worktree add --detach "$tmp" HEAD >/dev/null
15
+ python3 - "$tmp/README.md" <<'PY'
16
+ import re, sys
17
+ path = sys.argv[1]
18
+ text = open(path, encoding="utf-8").read()
19
+ head, sep, rest = text.partition("\n---\n") # the front matter: between the first two --- lines
20
+ own = {"title": "mathly", "emoji": "➗", "colorFrom": "blue", "colorTo": "gray"}
21
+ for key, value in own.items():
22
+ head = re.sub(rf"^{key}:.*$", f"{key}: {value}", head, flags=re.M)
23
+ open(path, "w", encoding="utf-8").write(head + sep + rest)
24
+ PY
25
+ git -C "$tmp" commit -qam "mathly: the Space's own name"
26
+ git -C "$tmp" push --force mathly HEAD:main
27
+ echo "Pushed $(git rev-parse --short HEAD) to mathly. The build: https://huggingface.co/spaces/wzender/mathly?logs=build"