59 lines
1.7 KiB
Bash
59 lines
1.7 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
export PATH=/usr/bin:/usr/local/bin:/usr/sbin:/sbin:/bin:$PATH
|
|
|
|
GREEN="\033[0;32m"
|
|
YELLOW="\033[1;33m"
|
|
RED="\033[0;31m"
|
|
NC="\033[0m"
|
|
|
|
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"
|
|
|
|
# sync ブランチを使用
|
|
CURRENT_BRANCH=$(git -C "$REPO_ROOT" rev-parse --abbrev-ref HEAD)
|
|
if [ "$CURRENT_BRANCH" != "sync" ]; then
|
|
echo -e "${YELLOW}Switching to sync branch...${NC}"
|
|
git -C "$REPO_ROOT" fetch origin sync
|
|
git -C "$REPO_ROOT" checkout sync
|
|
fi
|
|
|
|
echo -e "${YELLOW}Pulling from origin/sync...${NC}"
|
|
git -C "$REPO_ROOT" pull --rebase origin sync || {
|
|
echo -e "${RED}Failed to pull from remote. Continuing...${NC}"
|
|
}
|
|
|
|
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 (sync branch)...${NC}"
|
|
git push origin sync || {
|
|
echo -e "${RED}Failed to push.${NC}"
|
|
exit 1
|
|
}
|
|
echo -e "${GREEN}Changes pushed to Gitea (sync branch)${NC}"
|
|
else
|
|
echo -e "${GREEN}No changes detected${NC}"
|
|
fi
|
|
|
|
echo -e "${GREEN}=== Sync Complete ===${NC}"
|