feat: add scripts/build.sh, check.sh

This commit is contained in:
mirivlad 2026-06-16 12:12:05 +08:00
parent 8ca5617d0a
commit 330adc42f2
3 changed files with 172 additions and 0 deletions

Binary file not shown.

84
scripts/build.sh Executable file
View File

@ -0,0 +1,84 @@
#!/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-official-plugins build ==="
BUILT=0
SKIPPED=0
FAILED_PLUGINS=""
for plugin_dir in "$ROOT"/plugins/*/; do
[ -d "$plugin_dir" ] || continue
plugin_name="$(basename "$plugin_dir")"
echo ""
echo "--- [$plugin_name] ---"
# Validate plugin.json
if [ ! -f "$plugin_dir/plugin.json" ]; then
echo " ❌ plugin.json not found"
FAILED=1
FAILED_PLUGINS="$FAILED_PLUGINS $plugin_name"
continue
fi
if command -v python3 &>/dev/null; then
if python3 -c "import json; json.load(open('$plugin_dir/plugin.json'))" 2>/dev/null; then
echo " ✅ plugin.json: valid JSON"
else
echo " ❌ plugin.json: invalid JSON"
FAILED=1
FAILED_PLUGINS="$FAILED_PLUGINS $plugin_name"
continue
fi
else
echo " python3 not available — skipping JSON validation"
fi
# Frontend build
if [ -f "$plugin_dir/frontend/package.json" ]; then
echo " → frontend: npm ci + build"
(cd "$plugin_dir/frontend" && npm ci --no-audit --no-fund)
report "npm ci" $?
(cd "$plugin_dir/frontend" && npm run build)
report "frontend build" $?
BUILT=1
else
echo " no frontend/package.json — skipping frontend"
fi
# Backend build (Go)
if [ -f "$plugin_dir/backend/go.mod" ] || [ -f "$plugin_dir/backend/main.go" ]; then
echo " → backend: go build"
if [ -d "$plugin_dir/backend" ]; then
(cd "$plugin_dir/backend" && go build ./...)
report "backend go build" $?
BUILT=1
fi
else
echo " no backend/ — skipping backend"
fi
done
echo ""
echo "=== summary ==="
echo " plugins found: $(ls -d "$ROOT"/plugins/*/ 2>/dev/null | wc -l)"
if [ -n "$FAILED_PLUGINS" ]; then
echo " failed: $FAILED_PLUGINS"
fi
if [ "$FAILED" -eq 0 ]; then
echo "✅ build passed"
else
echo "❌ build failed"
fi
exit "$FAILED"

88
scripts/check.sh Executable file
View File

@ -0,0 +1,88 @@
#!/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-official-plugins check ==="
# Validate all plugin manifests against the SDK schema
if command -v python3 &>/dev/null; then
echo "[manifest validation]"
SDK_SCHEMA="$ROOT/../verstak-sdk/schemas/manifest.json"
if [ -f "$SDK_SCHEMA" ]; then
python3 -c "
import json, glob
skipped = []
problems = []
for plugin_dir in glob.glob('$ROOT/plugins/*/'):
manifest_path = plugin_dir + 'plugin.json'
try:
with open(manifest_path) as f:
manifest = json.load(f)
except FileNotFoundError:
skipped.append(plugin_dir.split('/')[-2])
continue
except json.JSONDecodeError as e:
problems.append(f'{plugin_dir.split(\"/\")[-2]}: invalid JSON — {e}')
continue
checks = {
'id': isinstance(manifest.get('id'), str) and '.' in manifest['id'],
'version': isinstance(manifest.get('version'), str),
'schemaVersion': manifest.get('schemaVersion') == 1,
'provides': isinstance(manifest.get('provides'), list),
'requires': isinstance(manifest.get('requires'), list),
}
for check, ok in checks.items():
if not ok:
problems.append(f'{manifest.get(\"id\", plugin_dir.split(\"/\")[-2])}: missing/empty \"{check}\"')
if skipped:
print(f' ⚠️ skipped (no plugin.json): {\", \".join(skipped)}')
if problems:
for p in problems:
print(f' ❌ {p}')
else:
print(' ✅ all manifests valid')
"
report "manifests valid" $?
else
echo " SDK schema not found at $SDK_SCHEMA — run build.sh in verstak-sdk first"
fi
else
echo " python3 not available — skipping manifest validation"
fi
echo ""
# Check all scripts in plugins are executable
echo "[script permissions]"
MISSING_EXEC=0
while IFS= read -r script; do
if [ ! -x "$script" ]; then
echo " ❌ not executable: $script"
MISSING_EXEC=1
fi
done < <(find "$ROOT/plugins" -name '*.sh' -o -name '*.py' 2>/dev/null)
if [ "$MISSING_EXEC" -eq 0 ]; then
echo " ✅ all scripts executable"
fi
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ all checks passed"
else
echo "❌ some checks failed"
fi
exit "$FAILED"