diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index ce5bba11ef..a6ebc26199 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -310,6 +310,42 @@ jobs: with: fetch-depth: 0 + - name: Sync vault templates and locales (Unix) + if: matrix.goos != 'windows' + run: | + chmod +x scripts/sync-vault.sh + ./scripts/sync-vault.sh + + - name: Sync vault templates and locales (Windows) + if: matrix.goos == 'windows' + shell: pwsh + run: | + # Clone vault repo + git clone --depth 1 https://git.marketally.com/gitcaddy/gitcaddy-vault.git $env:TEMP\gitcaddy-vault + + # Sync templates + Copy-Item -Path "$env:TEMP\gitcaddy-vault\templates\repo\vault\*" -Destination "templates\repo\vault\" -Force -Recurse + + # Sync locales using Python + python -c @" + import json, os + vault_dir = os.path.join(os.environ['TEMP'], 'gitcaddy-vault', 'locale') + server_dir = os.path.join('options', 'locale') + for f in os.listdir(vault_dir): + if not f.startswith('locale_') or not f.endswith('.json'): continue + vault_file = os.path.join(vault_dir, f) + server_file = os.path.join(server_dir, f) + if not os.path.exists(server_file): continue + with open(vault_file, 'r', encoding='utf-8') as vf: vault_data = json.load(vf) + with open(server_file, 'r', encoding='utf-8') as sf: server_data = json.load(sf) + for k, v in vault_data.items(): + if k.startswith('vault.'): server_data[k] = v + with open(server_file, 'w', encoding='utf-8') as sf: json.dump(server_data, sf, ensure_ascii=False, indent=2) + "@ + + # Cleanup + Remove-Item -Recurse -Force "$env:TEMP\gitcaddy-vault" + - name: Setup Go uses: actions/setup-go@v5 with: @@ -596,6 +632,11 @@ jobs: with: fetch-depth: 0 + - name: Sync vault templates and locales + run: | + chmod +x scripts/sync-vault.sh + ./scripts/sync-vault.sh + - name: Configure git for public modules run: | # Set up URL rewriting so git uses public URL diff --git a/scripts/sync-vault.sh b/scripts/sync-vault.sh new file mode 100644 index 0000000000..25a45c9c50 --- /dev/null +++ b/scripts/sync-vault.sh @@ -0,0 +1,96 @@ +#!/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!"