-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci.sh
More file actions
executable file
·155 lines (127 loc) · 3.77 KB
/
Copy pathci.sh
File metadata and controls
executable file
·155 lines (127 loc) · 3.77 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
152
153
154
155
#!/usr/bin/env bash
set -euo pipefail
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
run_component() {
local component=$1
local dir="$ROOT/$component"
log_info "Starting CI for $component..."
if [ ! -d "$dir" ]; then
log_error "Directory $dir does not exist."
exit 1
fi
pushd "$dir" > /dev/null
log_info "Installing dependencies for $component..."
npm install
log_info "Linting $component..."
npm run lint
log_info "Testing $component..."
npm test
popd > /dev/null
log_success "CI for $component completed successfully."
}
run_electron() {
log_info "Starting CI for electron..."
# First, ensure frontend is built (electron needs the static export)
log_info "Building frontend for electron..."
pushd "$ROOT/frontend" > /dev/null
npm install
npm run build
popd > /dev/null
# Install electron dependencies
log_info "Installing electron dependencies..."
pushd "$ROOT/electron" > /dev/null
npm install
# Build the electron app (pack creates unpacked directory for testing)
log_info "Building electron app..."
npm run pack
# Verify the build was created
if [ -d "$ROOT/electron/dist" ]; then
log_success "Electron build completed successfully."
log_info "Build output:"
ls -la "$ROOT/electron/dist/"
else
log_error "Electron build failed - dist directory not found."
exit 1
fi
# Run the electron app headlessly to check for startup errors
log_info "Testing electron app startup..."
export ELECTRON_ENABLE_LOGGING=1
# Find the unpacked app binary
if [ -d "$ROOT/electron/dist/linux-unpacked" ]; then
ELECTRON_APP="$ROOT/electron/dist/linux-unpacked/chat-electron"
elif [ -d "$ROOT/electron/dist/mac" ]; then
ELECTRON_APP="$ROOT/electron/dist/mac/ChatForge.app/Contents/MacOS/ChatForge"
else
log_info "Unpacked app not found, skipping runtime test."
popd > /dev/null
return 0
fi
if [ -f "$ELECTRON_APP" ]; then
log_info "Running electron app: $ELECTRON_APP"
# Check if we have a display available, otherwise use Xvfb
if [ -z "${DISPLAY:-}" ]; then
# No display available, try to use Xvfb if installed
if command -v Xvfb &> /dev/null; then
log_info "Starting Xvfb virtual framebuffer..."
Xvfb :99 -screen 0 1024x768x24 &
XVFB_PID=$!
export DISPLAY=:99
sleep 1 # Give Xvfb time to start
# Run the app with a timeout and capture any startup errors
timeout 10 "$ELECTRON_APP" --no-sandbox 2>&1 | head -50 || true
# Clean up Xvfb
kill $XVFB_PID 2>/dev/null || true
else
log_info "No display available and Xvfb not installed, skipping runtime test."
log_info "Install xvfb package to enable electron runtime testing in headless environments."
fi
else
# Display is available, run directly
timeout 10 "$ELECTRON_APP" --no-sandbox 2>&1 | head -50 || true
fi
log_success "Electron app startup test completed."
else
log_info "Electron binary not found at expected path, skipping runtime test."
fi
popd > /dev/null
log_success "CI for electron completed successfully."
}
cmd=${1:-all}
case "$cmd" in
backend)
run_component "backend"
;;
frontend)
run_component "frontend"
;;
electron)
run_electron
;;
all)
run_component "backend"
run_component "frontend"
;;
-h|--help)
echo "Usage: $0 [all|backend|frontend|electron]"
exit 0
;;
*)
log_error "Unknown command: $cmd"
echo "Usage: $0 [all|backend|frontend|electron]"
exit 1
;;
esac