Auto-sync Fri Feb 13 08:51:24 UTC 2026
This commit is contained in:
@@ -1,94 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
exec > >(tee -a /tmp/debug_script.log) 2>&1
|
||||
export WM_BASE_URL="http://windmill_server:8000"
|
||||
export WM_WORKSPACE="admins"
|
||||
export PATH=$HOME/.npm-global/bin:$PATH
|
||||
|
||||
echo "=== Windmill Workflow Git Sync ==="
|
||||
echo "=== START SYNC ==="
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Configuration & Checks
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Ensure Windmill CLI variables are set
|
||||
if [[ -z "${WM_TOKEN}" ]]; then
|
||||
echo "Warning: WM_TOKEN is not set. attempting to continue assuming ~/.config/windmill/config.toml exists."
|
||||
echo "If this fails, please set WM_TOKEN and WM_BASE_URL variables in the Windmill workspace settings or workflow input."
|
||||
fi
|
||||
|
||||
# Configure Git for the container
|
||||
# This is necessary because the script runs inside a Docker container
|
||||
# where the global git config might not be set.
|
||||
echo "Configuring Git..."
|
||||
git config --global --add safe.directory /workspace
|
||||
if [ -z "$(git config --global user.email)" ]; then
|
||||
git config --global user.email "windmill-bot@example.com"
|
||||
git config --global user.name "Windmill Bot"
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Execution
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Move to workspace directory (mapped to /home/akira/develop/windmill)
|
||||
# We need to be in the workflows directory where wmill.yaml is likely located
|
||||
# to ensure configuration (like includeSchedules) is respected.
|
||||
if [ -d "/workspace/workflows" ]; then
|
||||
cd /workspace/workflows
|
||||
elif [ -d "/workspace" ]; then
|
||||
cd /workspace
|
||||
else
|
||||
echo "Error: /workspace directory not found. Is the volume mounted correctly?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set PATH to ensure wmill is available
|
||||
export PATH=~/.npm-global/bin:$PATH
|
||||
|
||||
# Check if wmill is available
|
||||
if ! command -v wmill &> /dev/null; then
|
||||
echo "wmill command not found. Attempting to install windmill-client..."
|
||||
# Try installing using pip if npm is not available, or npm
|
||||
if command -v npm &> /dev/null; then
|
||||
npm install -g windmill-cli
|
||||
else
|
||||
echo "Error: npm not found. Cannot install wmill client."
|
||||
exit 1
|
||||
fi
|
||||
npm install -g windmill-cli
|
||||
fi
|
||||
|
||||
# Pull latest from Windmill
|
||||
echo "Pulling from Windmill..."
|
||||
# wmill sync pull will use the workspace defined in wmill.yaml or env vars.
|
||||
# We add --yes to avoid prompts.
|
||||
if wmill sync pull --skip-variables --skip-secrets --skip-resources --yes --verbose; then
|
||||
echo "Successfully pulled from Windmill."
|
||||
else
|
||||
echo "Error: wmill sync pull failed. Check your WM_TOKEN and connection."
|
||||
exit 1
|
||||
fi
|
||||
wmill sync pull --token "$WM_TOKEN" --base-url "$WM_BASE_URL" --workspace "$WM_WORKSPACE" --skip-variables --skip-secrets --skip-resources --yes --verbose || exit 1
|
||||
|
||||
git config --global --add safe.directory /workspace
|
||||
git config --global user.email "bot@example.com"
|
||||
git config --global user.name "Bot"
|
||||
|
||||
# Check for changes
|
||||
# Force add everything first to capture untracked files
|
||||
git add .
|
||||
git commit -m "Auto-sync $(date)" || echo "No changes"
|
||||
|
||||
if [[ -n $(git status --porcelain) ]]; then
|
||||
echo "Changes detected, committing to Git..."
|
||||
|
||||
# Commit
|
||||
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# Use explicit config to ensure commit works even if global config fails
|
||||
if git -c user.email="windmill-bot@example.com" -c user.name="Windmill Bot" commit -m "Auto-sync: ${TIMESTAMP}
|
||||
|
||||
Synced workflows from Windmill workspace"; then
|
||||
echo "✓ Changes committed to Git"
|
||||
echo "Successfully synced and committed changes at ${TIMESTAMP}"
|
||||
else
|
||||
echo "Error: Git commit failed."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "✓ No changes detected"
|
||||
echo "No changes to commit"
|
||||
fi
|
||||
|
||||
echo "=== Sync Complete ==="
|
||||
echo "=== END SYNC ==="
|
||||
|
||||
Reference in New Issue
Block a user