-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsync-localization.sh
More file actions
executable file
·151 lines (122 loc) · 4.54 KB
/
sync-localization.sh
File metadata and controls
executable file
·151 lines (122 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Script to sync session-localization submodule commit from session-desktop to session-playwright
# Usage: ./sync-localization-submodule.sh [path-to-session-desktop] [path-to-session-playwright]
set -e # Exit on error
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored messages
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Get directory paths from arguments or try to read from .env
DESKTOP_DIR="${1}"
PLAYWRIGHT_DIR="${2}"
# If playwright dir not provided, use current directory
if [ -z "$PLAYWRIGHT_DIR" ]; then
PLAYWRIGHT_DIR="$(pwd)"
print_info "Using current directory as session-playwright: $PLAYWRIGHT_DIR"
fi
# If desktop dir not provided, try to read from .env file in playwright repo
if [ -z "$DESKTOP_DIR" ]; then
if [ -f "$PLAYWRIGHT_DIR/.env" ]; then
print_info "Reading session-desktop path from .env file..."
# Look for SESSION_DESKTOP_ROOT variable in .env
DESKTOP_DIR=$(grep "^SESSION_DESKTOP_ROOT=" "$PLAYWRIGHT_DIR/.env" | cut -d '=' -f2- | tr -d '"' | tr -d "'")
if [ -z "$DESKTOP_DIR" ]; then
print_error "Could not find SESSION_DESKTOP_ROOT in .env file"
echo "Usage: $0 <path-to-session-desktop> [path-to-session-playwright]"
exit 1
fi
# Resolve relative path if needed
if [[ "$DESKTOP_DIR" == ../* ]] || [[ "$DESKTOP_DIR" == ./* ]]; then
DESKTOP_DIR="$PLAYWRIGHT_DIR/$DESKTOP_DIR"
fi
print_info "Found session-desktop path: $DESKTOP_DIR"
else
print_error "No .env file found and no desktop directory provided"
echo "Usage: $0 <path-to-session-desktop> [path-to-session-playwright]"
exit 1
fi
fi
# Verify directories exist
if [ ! -d "$DESKTOP_DIR" ]; then
print_error "session-desktop directory not found: $DESKTOP_DIR"
exit 1
fi
if [ ! -d "$PLAYWRIGHT_DIR" ]; then
print_error "session-playwright directory not found: $PLAYWRIGHT_DIR"
exit 1
fi
# Function to get submodule path from .gitmodules
get_submodule_path() {
local repo_dir="$1"
local gitmodules="$repo_dir/.gitmodules"
if [ ! -f "$gitmodules" ]; then
print_error ".gitmodules file not found in: $repo_dir"
return 1
fi
# Look for submodule with "localization" in the name
local submodule_path=$(grep -A 2 "localization" "$gitmodules" | grep "path" | head -1 | cut -d '=' -f2- | xargs)
if [ -z "$submodule_path" ]; then
print_error "Could not find localization submodule path in .gitmodules"
return 1
fi
echo "$submodule_path"
}
# Get submodule paths from .gitmodules files
print_info "Reading submodule paths from .gitmodules files..."
DESKTOP_SUBMODULE_PATH=$(get_submodule_path "$DESKTOP_DIR")
if [ $? -ne 0 ]; then
exit 1
fi
print_info "session-desktop submodule path: $DESKTOP_SUBMODULE_PATH"
PLAYWRIGHT_SUBMODULE_PATH=$(get_submodule_path "$PLAYWRIGHT_DIR")
if [ $? -ne 0 ]; then
exit 1
fi
print_info "session-playwright submodule path: $PLAYWRIGHT_SUBMODULE_PATH"
# Verify both repos have the localization submodule
DESKTOP_SUBMODULE="$DESKTOP_DIR/$DESKTOP_SUBMODULE_PATH"
PLAYWRIGHT_SUBMODULE="$PLAYWRIGHT_DIR/$PLAYWRIGHT_SUBMODULE_PATH"
if [ ! -d "$DESKTOP_SUBMODULE" ]; then
print_error "Localization submodule not found in session-desktop: $DESKTOP_SUBMODULE"
exit 1
fi
if [ ! -d "$PLAYWRIGHT_SUBMODULE" ]; then
print_error "Localization submodule not found in session-playwright: $PLAYWRIGHT_SUBMODULE"
exit 1
fi
print_info "Getting commit hash from session-desktop submodule..."
cd "$DESKTOP_SUBMODULE"
DESKTOP_COMMIT=$(git rev-parse HEAD)
print_info "session-desktop is using commit: $DESKTOP_COMMIT"
print_info "Checking current commit in session-playwright submodule..."
cd "$PLAYWRIGHT_SUBMODULE"
PLAYWRIGHT_COMMIT=$(git rev-parse HEAD)
print_info "session-playwright is using commit: $PLAYWRIGHT_COMMIT"
if [ "$DESKTOP_COMMIT" == "$PLAYWRIGHT_COMMIT" ]; then
print_info "Submodules are already synchronized!"
exit 0
fi
print_warning "Commits differ. Updating session-playwright submodule..."
# Update the submodule
cd "$PLAYWRIGHT_SUBMODULE"
git fetch
git checkout "$DESKTOP_COMMIT"
# Go to playwright repo root and stage the submodule change
cd "$PLAYWRIGHT_DIR"
git add "$PLAYWRIGHT_SUBMODULE_PATH"
print_info "Submodule updated successfully!"
print_info "New commit: $DESKTOP_COMMIT"
print_warning "Don't forget to commit the change in session-playwright:"
echo " cd $PLAYWRIGHT_DIR"
echo " git commit -m 'Update localization submodule to match session-desktop'"