-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
221 lines (183 loc) · 8.04 KB
/
Justfile
File metadata and controls
221 lines (183 loc) · 8.04 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import? 'implementation/client/agents.just'
set shell := ["bash", "-c"]
# Project Roots
node_client := "implementation/client/client-node"
java_client := "implementation/client/client-java"
cms := "implementation/server/teststate-cms"
gen_cli := "implementation/client/cli"
client_root := "implementation/client"
spec := justfile_directory() + "/specification"
# Discovery: List all agent directories (excludes SDKs and CLI)
clients := `find implementation/client -maxdepth 1 -type d | sed 's|implementation/client/||' | grep -vE "^implementation/client$|^client-|^cli" | tr '\n' ' '`
# Default Build
all: refresh-agents build-cms build-sdk build-all-clients
# --- Build Recipes ---
build-cms:
mvn -f {{cms}} clean compile
run-cms:
mvn -f {{cms}} quarkus:dev
force := "false"
build-node-client:
@if [ "$FORCE" = "true" ] || [ "{{force}}" = "true" ] || [ ! -d "{{node_client}}/dist" ]; then \
export SPECIFICATION_DIR="{{spec}}"; \
cd {{node_client}} && npm install && npm run build; \
else \
echo "[Just] Node SDK already built, skipping..."; \
fi
build-java-client:
@if [ "$FORCE" = "true" ] || [ "{{force}}" = "true" ] || ! ls {{java_client}}/target/teststate-client-java-*.jar >/dev/null 2>&1; then \
mvn -f {{java_client}} clean install -Dspecification.dir="{{spec}}"; \
else \
echo "[Just] Java SDK already built, skipping..."; \
fi
build-sdk: build-node-client build-java-client
build-gen-cli:
cd {{gen_cli}} && npm install && npm run build
# --- Generic Client Recipes ---
# List discovered agent clients
list-clients:
@echo "Discovered Agents:"
@printf " - %s\n" {{clients}}
# Build a specific client by name
build-client name:
@echo "[Just] Building client: {{name}}"
@if [ -f "{{client_root}}/{{name}}/package.json" ]; then \
if [ "{{name}}" != "client-node" ]; then \
just build-node-client; \
fi; \
cd {{client_root}}/{{name}} && { \
npm install; \
if [ "{{name}}" != "client-node" ]; then \
npm install ../client-node --no-save; \
fi; \
npm run build; \
}; \
elif [ -f "{{client_root}}/{{name}}/pom.xml" ]; then \
just build-java-client; \
mvn -f {{client_root}}/{{name}}/pom.xml clean compile -Dspecification.dir="{{spec}}"; \
else \
echo "Error: Unsupported project type in {{name}}"; exit 1; \
fi
# Build all discovered clients
build-all-clients:
@printf "%s\n" {{clients}} | xargs -I {} just build-client {}
# Run a specific client
# Usage: just run-client <name> [args...]
run-client name *args:
@echo "[Just] Running client: {{name}}"
@export CLIENT_DIR="{{client_root}}/{{name}}"; \
if [ -f "$CLIENT_DIR/.env" ]; then \
echo "[Just] Loading $CLIENT_DIR/.env"; \
set -o allexport; source "$CLIENT_DIR/.env"; set +o allexport; \
fi; \
if [ -f "$CLIENT_DIR/package.json" ]; then \
cd $CLIENT_DIR && npm start -- {{args}}; \
elif [ -f "$CLIENT_DIR/pom.xml" ]; then \
mvn -f $CLIENT_DIR/pom.xml exec:java -Dexec.args="{{args}}"; \
else \
echo "Error: Unsupported project type in {{name}}"; exit 1; \
fi
# Install Playwright browsers for a specific client
install-playwright name:
mvn -f {{client_root}}/{{name}}/pom.xml exec:java -Dexec.mainClass="com.microsoft.playwright.CLI" -Dexec.args="install"
# --- Generator & Maintenance ---
# Generate a new client project
# Usage: just gen-client <name> [options]
gen-client name *args: build-gen-cli
cd {{client_root}} && node cli/dist/index.js {{name}} {{args}}
just refresh-agents
# Refresh dynamic agent recipes for tab completion
refresh-agents: build-gen-cli
cd {{client_root}} && node cli/dist/index.js --refresh
# --- Utility ---
clean:
mvn -f {{cms}} clean
mvn -f {{java_client}} clean
@for client in {{clients}}; do \
if [ -f "{{client_root}}/$$client/pom.xml" ]; then \
mvn -f {{client_root}}/$$client clean; \
elif [ -f "{{client_root}}/$$client/package.json" ]; then \
rm -rf {{client_root}}/$$client/{dist,node_modules}; \
fi; \
done
rm -rf {{node_client}}/{dist,node_modules,src/generated}
rm -rf .docker/
# Update all submodules to their latest remote versions and commit
update-submodules:
@echo "[Just] Updating all submodules..."
git submodule update --remote --merge
@if [ -n "$(git status --porcelain implementation/ specification/)" ]; then \
echo "[Just] Committing submodule updates..."; \
git add implementation/ specification/; \
git commit -m "chore: update all submodules to latest remote versions"; \
echo "[Just] Successfully updated and committed submodules."; \
else \
echo "[Just] All submodules are already up to date."; \
fi
# --- Deployment Configuration ---
VPS_FILE := ".vps"
# --- Deployment Recipes ---
# Deploy to a VPS via SSH (Sync & Build)
# Create a versioned deployment bundle (ZIP)
bundle:
#!/usr/bin/env bash
VERSION=$(grep -m1 '<version>' implementation/server/teststate-cms/pom.xml | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
OUTPUT_FILE="teststate-v${VERSION}.zip"
echo "[Bundle] Creating v${VERSION} into ${OUTPUT_FILE}..."
rm -f teststate-v*.zip
git ls-files --cached --others --exclude-standard > .bundle_files
git submodule foreach --recursive --quiet 'git ls-files --cached --others --exclude-standard | sed "s|^|$sm_path/|"' >> .bundle_files
zip -q "$OUTPUT_FILE" -@ < .bundle_files
rm .bundle_files
echo "[Bundle] Done! Created ${OUTPUT_FILE}"
# Deploy to a VPS via SSH (Sync & Build)
# Usage: just deploy [type=native|java] [remote_path] [user@host]
deploy type="native" path="~/TestState" host="":
#!/usr/bin/env bash
VPS_FILE=".vps"
REMOTE_PATH="{{path}}"
HOST="{{host}}"
if [ -z "$HOST" ] && [ -f "$VPS_FILE" ]; then HOST=$(head -n 1 "$VPS_FILE"); fi
if [ -z "$HOST" ]; then HOST="host@ip"; fi
SSH_CMD="ssh"
RSYNC_OPTS="-avz --delete"
if [ -f "$VPS_FILE" ]; then
export SSHPASS=$(tail -n 1 "$VPS_FILE")
SSH_CMD="sshpass -e ssh"
RSYNC_OPTS="$RSYNC_OPTS -e 'sshpass -e ssh'"
fi
TARGET="native"
if [ "{{type}}" == "java" ]; then TARGET="jvm"; fi
echo "[Deploy] Syncing files to $HOST:$REMOTE_PATH..."
eval "rsync $RSYNC_OPTS --exclude-from='.dockerignore' ./ \"$HOST:$REMOTE_PATH\""
echo "[Deploy] Stopping existing services and building ({{type}}) on remote..."
$SSH_CMD "$HOST" "cd $REMOTE_PATH && docker compose down && CMS_TARGET=$TARGET docker compose up --build -d --remove-orphans"
# Deploy via ZIP bundle (Upload -> Unzip -> Build)
# Usage: just deploy-zip [type=native|java] [remote_path] [user@host]
deploy-zip type="native" path="~/TestState" host="": bundle
#!/usr/bin/env bash
VPS_FILE=".vps"
REMOTE_PATH="{{path}}"
HOST="{{host}}"
if [ -z "$HOST" ] && [ -f "$VPS_FILE" ]; then HOST=$(head -n 1 "$VPS_FILE"); fi
if [ -z "$HOST" ]; then HOST="host@ip"; fi
SSH_CMD="ssh"
SCP_CMD="scp"
if [ -f "$VPS_FILE" ]; then
export SSHPASS=$(tail -n 1 "$VPS_FILE")
SSH_CMD="sshpass -e ssh"
SCP_CMD="sshpass -e scp"
fi
BUNDLE=$(ls teststate-*.zip 2>/dev/null | sort -V | tail -n 1)
if [ -z "$BUNDLE" ]; then echo "Error: No bundle found."; exit 1; fi
TARGET="native"
if [ "{{type}}" == "java" ]; then TARGET="jvm"; fi
echo "[Deploy] Uploading bundle $BUNDLE to $HOST..."
$SCP_CMD "$BUNDLE" "$HOST:$REMOTE_PATH.zip"
echo "[Deploy] Extracting and rebuilding ({{type}}) on remote..."
$SSH_CMD "$HOST" "mkdir -p $REMOTE_PATH && unzip -o $REMOTE_PATH.zip -d $REMOTE_PATH && cd $REMOTE_PATH && docker compose down && CMS_TARGET=$TARGET docker compose up --build -d --remove-orphans"
# Configure a remote Docker context (Alternative method)
# Usage: just setup-remote-context <name> <ssh-url>
setup-remote-context name url:
docker context create {{name}} --docker "host={{url}}"
@echo "Success! Use 'docker --context {{name}} compose up --build -d' to deploy."