Spaces:
Running on T4

File size: 976 Bytes
ff80158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Deploy the current commit to a Hugging Face Space repo.
#
#   scripts/deploy_hf_space.sh <git-remote>     e.g. hf (production), hf-staging
#
# The GitHub history contains a large blob the Space repo rejects, so the
# Space gets a commit with the same tree on top of the Space's own history.
# Its "Source-Commit:" trailer records the GitHub commit, which the app reports
# as mosaic_commit in every result's provenance (src/mosaic/build_info.py).
set -euo pipefail

remote="${1:?usage: $0 <git-remote>}"
if ! git diff --quiet HEAD -- || [ -n "$(git status --porcelain --untracked-files=no)" ]; then
    echo "Commit or stash local changes first." >&2
    exit 1
fi

src=$(git rev-parse HEAD)
git fetch -q "$remote"
deploy=$(git commit-tree "HEAD^{tree}" -p "$remote/main" \
    -m "deploy: ${src:0:7} $(git log -1 --format=%s HEAD)" \
    -m "Source-Commit: $src")
git push "$remote" "$deploy:main"
echo "Deployed ${src:0:7} to $remote as ${deploy:0:7}"