#!/bin/bash set -e export PATH=/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/bin:$PATH GREEN="" YELLOW="" RED="" NC="" echo -e "${GREEN}=== Windmill Workflow Git Sync ===${NC}" REPO_ROOT="/workspace" WMILL_DIR="${REPO_ROOT}/workflows" if ! command -v wmill &> /dev/null; then echo -e "${YELLOW}Installing windmill-cli...${NC}" npm install -g windmill-cli export PATH=$(npm prefix -g)/bin:$PATH fi git config --global --add safe.directory "$REPO_ROOT" git config --global user.email "bot@keinafarm.net" git config --global user.name "Windmill Bot" echo -e "${YELLOW}Pulling from Windmill...${NC}" cd "$WMILL_DIR" wmill sync pull --config-dir /workspace/wmill_config --skip-variables --skip-secrets --skip-resources --yes || exit 1 cd "$REPO_ROOT" if [[ -n $(git status --porcelain) ]]; then echo -e "${YELLOW}Changes detected, committing to Git...${NC}" git add -A TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S") git commit -m "Auto-sync: ${TIMESTAMP}" echo -e "${YELLOW}Pushing to Gitea...${NC}" git pull --rebase origin main || { echo -e "${RED}Failed to pull from remote. Trying push anyway...${NC}" } git push origin main || { echo -e "${RED}Failed to push.${NC}" exit 1 } echo -e "${GREEN}Changes pushed to Gitea${NC}" else echo -e "${GREEN}No changes detected${NC}" fi echo -e "${GREEN}=== Sync Complete ===${NC}"