feat: add scripts/build.sh, test.sh, check.sh + gofmt + go mod tidy

This commit is contained in:
2026-06-16 12:11:55 +08:00
parent ec8ceee7f3
commit aefb9e9a9c
10 changed files with 243 additions and 72 deletions
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-desktop build ==="
# ── Go backend ──
echo "[backend]"
(cd "$ROOT" && go vet ./...)
report "go vet" $?
(cd "$ROOT" && go build ./...)
report "go build" $?
if command -v go-test-summary &>/dev/null || go test -list . ./... &>/dev/null 2>&1; then
(cd "$ROOT" && go test -count=1 ./... 2>&1 || true)
report "go test" $?
else
echo " ️ go test: no tests to run"
fi
# ── Wails ──
echo "[wails]"
if command -v wails &>/dev/null; then
(cd "$ROOT" && wails build -clean)
report "wails build" $?
else
echo " ❌ wails: command not found. Install with: go install github.com/wailsapp/wails/v2/cmd/wails@latest"
FAILED=1
fi
# ── Frontend ──
echo "[frontend]"
if [ -f "$ROOT/frontend/package.json" ]; then
(cd "$ROOT/frontend" && npm ci --no-audit --no-fund)
report "npm ci" $?
(cd "$ROOT/frontend" && npm run build)
report "frontend build" $?
else
echo " ️ frontend/package.json not found — skipping"
fi
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ build passed"
else
echo "❌ build failed"
fi
exit "$FAILED"
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-desktop check ==="
# Go vet
(cd "$ROOT" && go vet ./...)
report "go vet" $?
# Go fmt (non-destructive — only report unformatted files)
UNFORMATTED=$(cd "$ROOT" && gofmt -l . 2>/dev/null || go fmt -n ./... 2>&1 || true)
if [ -z "$UNFORMATTED" ]; then
echo " ✅ gofmt: all files formatted"
else
echo " ❌ gofmt: unformatted files:"
echo "$UNFORMATTED" | sed 's/^/ /'
FAILED=1
fi
# Go mod tidy check (non-destructive — report only)
(cd "$ROOT" && go mod tidy -diff 2>&1 || echo " ⚠️ go mod tidy check skipped")
report "go mod tidy" $?
# Frontend lint
if [ -f "$ROOT/frontend/package.json" ]; then
# Check if npm ci is needed (node_modules missing)
if [ ! -d "$ROOT/frontend/node_modules" ]; then
echo " ️ frontend/node_modules missing — run build.sh first"
fi
if grep -q '"lint"' "$ROOT/frontend/package.json" 2>/dev/null; then
(cd "$ROOT/frontend" && npx tsc --noEmit 2>&1 || true)
report "frontend tsc --noEmit" $?
else
echo " ️ no lint script in frontend/package.json"
fi
fi
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ all checks passed"
else
echo "❌ some checks failed"
fi
exit "$FAILED"
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-desktop test ==="
# Go tests
(cd "$ROOT" && go test -count=1 -v ./... 2>&1 || true)
report "go test" $?
# Frontend tests
if [ -f "$ROOT/frontend/package.json" ]; then
# Only run if vitest or jest is in the config
if grep -q '"test"' "$ROOT/frontend/package.json" 2>/dev/null; then
(cd "$ROOT/frontend" && npm test 2>&1 || true)
report "frontend test" $?
else
echo " ️ no test script in frontend/package.json"
fi
else
echo " ️ no frontend/package.json"
fi
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ all tests passed"
else
echo "❌ some tests failed"
fi
exit "$FAILED"