#!/bin/bash set -e echo "=== Windmill Workflow Git 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 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 (skipped for testing)." # else # echo "Error: wmill sync pull failed. Check your WM_TOKEN and connection." # exit 1 # fi # Check for changes # Force add everything first to capture untracked files git add . 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 ==="