2
0
Files
gitcaddy-server/scripts/sync-vault.sh
logikonline 997ead8b20
Some checks failed
Build and Release / Create Release (push) Successful in 0s
Build and Release / Unit Tests (push) Successful in 3m25s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 4m11s
Build and Release / Lint (push) Successful in 5m18s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Failing after 1s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Failing after 1s
Build and Release / Build Binary (linux/arm64) (push) Failing after 4s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 2m59s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Failing after 8h5m33s
build: Add vault sync script for template/locale synchronization
- Add scripts/sync-vault.sh to sync templates and locales from vault
- Update build.yml to run sync after checkout on all platforms
- Vault repo is source of truth, server receives at build time

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 17:11:15 -05:00

97 lines
2.8 KiB
Bash

#!/bin/bash
# sync-vault.sh - Syncs templates and locales from gitcaddy-vault to gitcaddy-server
# Usage: ./scripts/sync-vault.sh [vault-repo-path]
#
# If vault-repo-path is not provided, it will clone from git.marketally.com
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SERVER_DIR="$(dirname "$SCRIPT_DIR")"
VAULT_PATH="${1:-}"
# If no vault path provided, clone to temp directory
if [ -z "$VAULT_PATH" ]; then
VAULT_PATH=$(mktemp -d)
CLEANUP_VAULT=true
echo "Cloning gitcaddy-vault to $VAULT_PATH..."
git clone --depth 1 https://git.marketally.com/gitcaddy/gitcaddy-vault.git "$VAULT_PATH"
else
CLEANUP_VAULT=false
echo "Using vault from $VAULT_PATH"
fi
# Verify vault directory exists
if [ ! -d "$VAULT_PATH/templates" ]; then
echo "Error: $VAULT_PATH/templates not found"
exit 1
fi
echo "Syncing templates..."
# Sync vault templates
mkdir -p "$SERVER_DIR/templates/repo/vault"
cp -r "$VAULT_PATH/templates/repo/vault/"* "$SERVER_DIR/templates/repo/vault/"
echo " - Copied templates/repo/vault/"
echo "Syncing locales..."
# Merge locale files using Python
python3 << 'PYTHON_SCRIPT'
import json
import os
import sys
server_dir = os.environ.get('SERVER_DIR', '.')
vault_path = os.environ.get('VAULT_PATH', '.')
server_locale_dir = os.path.join(server_dir, 'options', 'locale')
vault_locale_dir = os.path.join(vault_path, 'locale')
if not os.path.isdir(vault_locale_dir):
print(f"Warning: {vault_locale_dir} not found, skipping locale sync")
sys.exit(0)
# Get all vault locale files
for filename in os.listdir(vault_locale_dir):
if not filename.startswith('locale_') or not filename.endswith('.json'):
continue
vault_file = os.path.join(vault_locale_dir, filename)
server_file = os.path.join(server_locale_dir, filename)
if not os.path.exists(server_file):
print(f" - Skipping {filename} (not in server)")
continue
# Load both files
with open(vault_file, 'r', encoding='utf-8') as f:
vault_data = json.load(f)
with open(server_file, 'r', encoding='utf-8') as f:
server_data = json.load(f)
# Merge vault keys into server (vault takes precedence for vault.* keys)
updated = False
for key, value in vault_data.items():
if key.startswith('vault.'):
if key not in server_data or server_data[key] != value:
server_data[key] = value
updated = True
if updated:
with open(server_file, 'w', encoding='utf-8') as f:
json.dump(server_data, f, ensure_ascii=False, indent=2)
print(f" - Updated {filename}")
else:
print(f" - {filename} (no changes)")
print("Locale sync complete")
PYTHON_SCRIPT
# Cleanup temp directory if we cloned
if [ "$CLEANUP_VAULT" = true ]; then
echo "Cleaning up temp directory..."
rm -rf "$VAULT_PATH"
fi
echo "Vault sync complete!"