#!/bin/bash # deploy.sh - Deploy to HuggingFace Spaces with meaningful commit messages # # Usage: # ./deploy.sh "Your commit message" # ./deploy.sh (prompts for message if not provided) set -e # Exit on error # Color output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check if we're in a git repo if ! git rev-parse --git-dir > /dev/null 2>&1; then echo -e "${RED}Error: Not in a git repository${NC}" exit 1 fi # Check for uncommitted changes if ! git diff-index --quiet HEAD --; then echo -e "${YELLOW}You have uncommitted changes:${NC}" git status --short echo "" read -p "Stage and commit all changes? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}Aborted${NC}" exit 1 fi git add -A fi # Get commit message if [ -z "$1" ]; then echo -e "${YELLOW}Enter commit message:${NC}" read -r COMMIT_MSG if [ -z "$COMMIT_MSG" ]; then echo -e "${RED}Error: Commit message cannot be empty${NC}" exit 1 fi else COMMIT_MSG="$1" fi # Validate commit message isn't generic if [[ "$COMMIT_MSG" =~ ^(Upload|update|Update|fix|Fix)$ ]]; then echo -e "${YELLOW}Warning: Commit message is too generic: '$COMMIT_MSG'${NC}" read -p "Continue anyway? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}Aborted${NC}" exit 1 fi fi # Create commit if there are staged changes if ! git diff-index --quiet --cached HEAD --; then echo -e "${GREEN}Creating commit...${NC}" git commit -m "$COMMIT_MSG" else echo -e "${YELLOW}No staged changes to commit${NC}" fi # Show what will be pushed echo -e "\n${YELLOW}Commits to be pushed:${NC}" git log origin/main..HEAD --oneline --decorate # Confirm push echo "" read -p "Push to HuggingFace Spaces? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}Aborted${NC}" exit 1 fi # Push to HuggingFace echo -e "${GREEN}Pushing to HuggingFace Spaces...${NC}" git push origin main echo -e "${GREEN}✓ Deployment complete!${NC}" echo -e "View at: ${GREEN}https://huggingface.co/spaces/Luigi/tiny-scribe${NC}" # Verify commit message was preserved echo -e "\n${YELLOW}Verifying commit on remote...${NC}" git fetch origin -q REMOTE_MSG=$(git log origin/main -1 --pretty=format:"%s") echo -e "Latest remote commit: ${GREEN}$REMOTE_MSG${NC}" if [[ "$REMOTE_MSG" == *"huggingface_hub"* ]]; then echo -e "${RED}⚠ WARNING: Remote commit has generic message!${NC}" echo -e "${YELLOW}This means you may have edited files via HF web UI.${NC}" echo -e "${YELLOW}Always use 'git push' instead of the web interface!${NC}" fi