Auto-sync: 2026-02-25 07:14:42
This commit is contained in:
@@ -1,69 +1,48 @@
|
||||
#!/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' # No Color
|
||||
GREEN="[0;32m"
|
||||
YELLOW="[1;33m"
|
||||
RED="[0;31m"
|
||||
NC="[0m"
|
||||
|
||||
echo -e "${GREEN}=== Windmill Workflow Git Sync ===${NC}"
|
||||
|
||||
# リポジトリルート(コンテナ内: docker-compose.ymlの .:/workspace マウント)
|
||||
REPO_ROOT="/workspace"
|
||||
# wmill.yamlがあるディレクトリ(Windmill CLIはここで実行する)
|
||||
WMILL_DIR="${REPO_ROOT}/workflows"
|
||||
|
||||
# Windmill CLIのセットアップ
|
||||
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
|
||||
|
||||
# 環境変数チェック
|
||||
if [ -z "$WM_TOKEN" ]; then
|
||||
echo -e "${RED}Error: WM_TOKEN is not set.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
# WM_BASE_URLはWindmill内で自動設定される場合があるが、念のため
|
||||
: "${WM_BASE_URL:=http://windmill_server:8000}"
|
||||
# Workspaceは環境変数または引数で
|
||||
: "${WM_WORKSPACE:=admins}"
|
||||
|
||||
# Git設定(コンテナ内での一時設定)
|
||||
git config --global --add safe.directory "$REPO_ROOT"
|
||||
git config --global user.email "bot@keinafarm.net"
|
||||
git config --global user.name "Windmill Bot"
|
||||
|
||||
# 1. Windmill(DB) -> Local Disk(wmill.yamlがあるディレクトリで実行)
|
||||
echo -e "${YELLOW}Pulling from Windmill...${NC}"
|
||||
cd "$WMILL_DIR"
|
||||
wmill sync pull --token "$WM_TOKEN" --base-url "$WM_BASE_URL" --workspace "$WM_WORKSPACE" --skip-variables --skip-secrets --skip-resources --yes || exit 1
|
||||
wmill sync pull --config-dir /workspace/wmill_config --skip-variables --skip-secrets --skip-resources --yes || exit 1
|
||||
|
||||
# 2. Local Disk -> Git Remote(Gitリポジトリルートに戻ってgit操作)
|
||||
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')
|
||||
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
git commit -m "Auto-sync: ${TIMESTAMP}"
|
||||
|
||||
echo -e "${YELLOW}Pushing to Gitea...${NC}"
|
||||
# リモートURLにトークンが含まれていない場合、プッシュに失敗する可能性がある
|
||||
# ここでは既存のoriginを使用
|
||||
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. Need credentials in git remote url or credential helper.${NC}"
|
||||
echo -e "${YELLOW}Hint: git remote set-url origin https://<token>@gitea.keinafarm.net/...${NC}"
|
||||
echo -e "${RED}Failed to push.${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo -e "${GREEN}✓ Changes pushed to Gitea${NC}"
|
||||
echo -e "${GREEN}Changes pushed to Gitea${NC}"
|
||||
else
|
||||
echo -e "${GREEN}✓ No changes detected${NC}"
|
||||
echo -e "${GREEN}No changes detected${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}=== Sync Complete ===${NC}"
|
||||
|
||||
Reference in New Issue
Block a user