Skip to content

Commit 39fa543

Browse files
committed
Add local CI setup and E2E tmux scripts
1 parent 7c776d1 commit 39fa543

4 files changed

Lines changed: 389 additions & 0 deletions

File tree

scripts/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Scripts
2+
3+
Shell scripts for local development environment setup and E2E testing.
4+
5+
## Prerequisites
6+
7+
- Node.js 22+
8+
- tmux
9+
- Rust (optional, for cargo check)
10+
11+
## Scripts
12+
13+
### ci-setup.sh
14+
15+
Sets up the local development environment by running the same build steps as GitHub CI.
16+
17+
```bash
18+
./scripts/ci-setup.sh [OPTIONS]
19+
```
20+
21+
**Build Steps:**
22+
1. Check Node.js version (22+)
23+
2. Enable corepack
24+
3. Install dependencies (`yarn install --immutable`)
25+
4. Build CS packages (cait-sith WASM)
26+
5. Build Frost packages (frost-ed25519 WASM)
27+
6. Build internal packages
28+
7. Build SDK packages
29+
8. Run TypeScript typecheck
30+
9. Run Rust cargo check
31+
32+
**Options:**
33+
34+
| Option | Description |
35+
|--------|-------------|
36+
| `--skip-rust` | Skip Rust cargo check |
37+
| `--skip-typecheck` | Skip TypeScript typecheck |
38+
| `-h, --help` | Show help message |
39+
40+
**Examples:**
41+
42+
```bash
43+
# Full setup
44+
./scripts/ci-setup.sh
45+
46+
# Quick setup (skip checks)
47+
./scripts/ci-setup.sh --skip-rust --skip-typecheck
48+
```
49+
50+
---
51+
52+
### tmux-e2e-start.sh
53+
54+
Starts all E2E services in a tmux session with separate windows.
55+
56+
```bash
57+
./scripts/tmux-e2e-start.sh [OPTIONS]
58+
```
59+
60+
**Services Started:**
61+
62+
| Window | Service | Command |
63+
|--------|---------|---------|
64+
| oko_api | Backend API | `yarn dev` |
65+
| oko_attached | Embedded wallet | `yarn dev` |
66+
| demo_web | Demo web app | `yarn dev` |
67+
| ksn_1 | Key Share Node 1 | `yarn start` |
68+
| ksn_2 | Key Share Node 2 | `yarn start_2` |
69+
| ksn_3 | Key Share Node 3 | `yarn start_3` |
70+
71+
**Options:**
72+
73+
| Option | Description |
74+
|--------|-------------|
75+
| `--reset` | Reset database before starting (runs migrations and seed) |
76+
| `-h, --help` | Show help message |
77+
78+
**Database Reset Steps (when using `--reset`):**
79+
1. `yarn ci db_migrate_api --use-env-file`
80+
2. `yarn ci db_seed_api --use-env-file`
81+
3. `yarn ci db_migrate_ksn --use-env-file`
82+
83+
**Examples:**
84+
85+
```bash
86+
# Start services
87+
./scripts/tmux-e2e-start.sh
88+
89+
# Reset database and start
90+
./scripts/tmux-e2e-start.sh --reset
91+
```
92+
93+
---
94+
95+
### tmux-e2e-stop.sh
96+
97+
Stops the E2E tmux session.
98+
99+
```bash
100+
./scripts/tmux-e2e-stop.sh
101+
```
102+
103+
---
104+
105+
## Typical Workflow
106+
107+
```bash
108+
# 1. First time setup (run once)
109+
./scripts/ci-setup.sh
110+
111+
# 2. Start E2E environment with fresh database
112+
./scripts/tmux-e2e-start.sh --reset
113+
114+
# 3. When done, stop all services
115+
./scripts/tmux-e2e-stop.sh
116+
```
117+
118+
## Tmux Navigation
119+
120+
Once attached to the session:
121+
- `Ctrl+b n` - Next window
122+
- `Ctrl+b p` - Previous window
123+
- `Ctrl+b <number>` - Go to window by number (0-5)
124+
- `Ctrl+b d` - Detach from session (services keep running)
125+
- `Ctrl+b w` - List all windows

scripts/ci-setup.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/bin/bash
2+
set -e
3+
4+
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5+
cd "$PROJECT_ROOT"
6+
7+
# Color definitions
8+
RED='\033[0;31m'
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
BLUE='\033[0;34m'
12+
NC='\033[0m'
13+
14+
print_info() {
15+
echo -e "${GREEN}[INFO]${NC} $1"
16+
}
17+
18+
print_step() {
19+
echo -e "${BLUE}[STEP]${NC} $1"
20+
}
21+
22+
print_warn() {
23+
echo -e "${YELLOW}[WARN]${NC} $1"
24+
}
25+
26+
print_error() {
27+
echo -e "${RED}[ERROR]${NC} $1"
28+
}
29+
30+
# Parse options
31+
SKIP_RUST=false
32+
SKIP_TYPECHECK=false
33+
34+
while [[ $# -gt 0 ]]; do
35+
case $1 in
36+
--skip-rust)
37+
SKIP_RUST=true
38+
shift
39+
;;
40+
--skip-typecheck)
41+
SKIP_TYPECHECK=true
42+
shift
43+
;;
44+
-h|--help)
45+
echo "Usage: $0 [OPTIONS]"
46+
echo ""
47+
echo "Local CI setup script - prepares the development environment"
48+
echo ""
49+
echo "Options:"
50+
echo " --skip-rust Skip Rust cargo check"
51+
echo " --skip-typecheck Skip TypeScript typecheck"
52+
echo " -h, --help Show this help message"
53+
exit 0
54+
;;
55+
*)
56+
print_error "Unknown option: $1"
57+
echo "Use -h or --help for usage information"
58+
exit 1
59+
;;
60+
esac
61+
done
62+
63+
echo ""
64+
echo "=========================================="
65+
echo " Oko Local CI Setup"
66+
echo "=========================================="
67+
echo ""
68+
69+
# Check Node.js version
70+
print_step "Checking Node.js version..."
71+
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
72+
if [ "$NODE_VERSION" -lt 22 ]; then
73+
print_error "Node.js 22+ required. Current: $(node -v)"
74+
exit 1
75+
fi
76+
print_info "Node.js $(node -v) OK"
77+
78+
# Enable corepack
79+
print_step "Enabling corepack..."
80+
corepack enable
81+
print_info "Corepack enabled"
82+
83+
# Install dependencies
84+
print_step "Installing dependencies..."
85+
yarn install --immutable
86+
print_info "Dependencies installed"
87+
88+
# Build CS packages (WASM)
89+
print_step "Building CS packages (cait-sith WASM)..."
90+
yarn ci build_cs
91+
print_info "CS packages built"
92+
93+
# Build Frost packages (EdDSA WASM)
94+
print_step "Building Frost packages (frost-ed25519 WASM)..."
95+
yarn ci build_frost
96+
print_info "Frost packages built"
97+
98+
# Build internal packages
99+
print_step "Building internal packages..."
100+
yarn ci build_pkgs
101+
print_info "Internal packages built"
102+
103+
# Build SDK packages
104+
print_step "Building SDK packages..."
105+
yarn ci build_sdk
106+
print_info "SDK packages built"
107+
108+
# TypeScript typecheck
109+
if [ "$SKIP_TYPECHECK" = false ]; then
110+
print_step "Running TypeScript typecheck..."
111+
yarn ci typecheck
112+
print_info "Typecheck passed"
113+
else
114+
print_warn "Skipping TypeScript typecheck"
115+
fi
116+
117+
# Rust check
118+
if [ "$SKIP_RUST" = false ]; then
119+
if command -v cargo &> /dev/null; then
120+
print_step "Running Rust cargo check..."
121+
cargo check --workspace
122+
print_info "Rust check passed"
123+
else
124+
print_warn "Rust not installed, skipping cargo check"
125+
fi
126+
else
127+
print_warn "Skipping Rust cargo check"
128+
fi
129+
130+
echo ""
131+
echo "=========================================="
132+
echo -e " ${GREEN}Setup Complete!${NC}"
133+
echo "=========================================="
134+
echo ""
135+
print_info "You can now run: ./scripts/tmux-e2e-start.sh"
136+
echo ""

scripts/tmux-e2e-start.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SESSION_NAME="oko-e2e"
5+
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6+
RESET_DB=false
7+
8+
# Color definitions
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m'
13+
14+
print_info() {
15+
echo -e "${GREEN}[INFO]${NC} $1"
16+
}
17+
18+
print_warn() {
19+
echo -e "${YELLOW}[WARN]${NC} $1"
20+
}
21+
22+
print_error() {
23+
echo -e "${RED}[ERROR]${NC} $1"
24+
}
25+
26+
# Parse options
27+
while [[ $# -gt 0 ]]; do
28+
case $1 in
29+
--reset)
30+
RESET_DB=true
31+
shift
32+
;;
33+
-h|--help)
34+
echo "Usage: $0 [OPTIONS]"
35+
echo ""
36+
echo "Options:"
37+
echo " --reset Reset database before starting services"
38+
echo " -h, --help Show this help message"
39+
exit 0
40+
;;
41+
*)
42+
print_error "Unknown option: $1"
43+
echo "Use -h or --help for usage information"
44+
exit 1
45+
;;
46+
esac
47+
done
48+
49+
# Check tmux installation
50+
if ! command -v tmux &> /dev/null; then
51+
print_error "tmux is not installed. Please install tmux first."
52+
exit 1
53+
fi
54+
55+
# Check and kill existing session
56+
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
57+
print_warn "Existing session '$SESSION_NAME' found. Killing it..."
58+
tmux kill-session -t "$SESSION_NAME"
59+
fi
60+
61+
# Reset database
62+
if [ "$RESET_DB" = true ]; then
63+
print_info "Resetting database..."
64+
cd "$PROJECT_ROOT"
65+
66+
print_info "Running: yarn ci db_migrate_api --use-env-file"
67+
yarn ci db_migrate_api --use-env-file
68+
69+
print_info "Running: yarn ci db_seed_api --use-env-file"
70+
yarn ci db_seed_api --use-env-file
71+
72+
print_info "Running: yarn ci db_migrate_ksn --use-env-file"
73+
yarn ci db_migrate_ksn --use-env-file
74+
75+
print_info "Database reset complete!"
76+
fi
77+
78+
print_info "Creating tmux session: $SESSION_NAME"
79+
80+
# 1. oko_api (create session with first window)
81+
tmux new-session -d -s "$SESSION_NAME" -n "oko_api" -c "$PROJECT_ROOT/backend/oko_api/server"
82+
tmux send-keys -t "$SESSION_NAME:oko_api" "yarn dev" C-m
83+
84+
# 2. oko_attached
85+
tmux new-window -t "$SESSION_NAME" -n "oko_attached" -c "$PROJECT_ROOT/embed/oko_attached"
86+
tmux send-keys -t "$SESSION_NAME:oko_attached" "yarn dev" C-m
87+
88+
# 3. demo_web
89+
tmux new-window -t "$SESSION_NAME" -n "demo_web" -c "$PROJECT_ROOT/apps/demo_web"
90+
tmux send-keys -t "$SESSION_NAME:demo_web" "yarn dev" C-m
91+
92+
# 4. ksn_1
93+
tmux new-window -t "$SESSION_NAME" -n "ksn_1" -c "$PROJECT_ROOT/key_share_node/server"
94+
tmux send-keys -t "$SESSION_NAME:ksn_1" "yarn start" C-m
95+
96+
# 5. ksn_2
97+
tmux new-window -t "$SESSION_NAME" -n "ksn_2" -c "$PROJECT_ROOT/key_share_node/server"
98+
tmux send-keys -t "$SESSION_NAME:ksn_2" "yarn start_2" C-m
99+
100+
# 6. ksn_3
101+
tmux new-window -t "$SESSION_NAME" -n "ksn_3" -c "$PROJECT_ROOT/key_share_node/server"
102+
tmux send-keys -t "$SESSION_NAME:ksn_3" "yarn start_3" C-m
103+
104+
# Select first window
105+
tmux select-window -t "$SESSION_NAME:oko_api"
106+
107+
print_info "All services started in tmux session: $SESSION_NAME"
108+
print_info "Windows: oko_api, oko_attached, demo_web, ksn_1, ksn_2, ksn_3"
109+
echo ""
110+
print_info "Attaching to session..."
111+
112+
# Attach to session
113+
tmux attach-session -t "$SESSION_NAME"

scripts/tmux-e2e-stop.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
SESSION_NAME="oko-e2e"
4+
5+
# Color definitions
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[1;33m'
8+
NC='\033[0m'
9+
10+
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
11+
tmux kill-session -t "$SESSION_NAME"
12+
echo -e "${GREEN}[INFO]${NC} Session '$SESSION_NAME' terminated."
13+
else
14+
echo -e "${YELLOW}[WARN]${NC} Session '$SESSION_NAME' not found."
15+
fi

0 commit comments

Comments
 (0)