From cb17434f715385cdb8cb30ae5721a24abd4c6e17 Mon Sep 17 00:00:00 2001 From: Pablinux Date: Wed, 17 Jun 2026 10:02:25 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20agrega=20desplegar.sh=20=E2=80=94=20bui?= =?UTF-8?q?ld=20y=20publish=20a=20WebControlSigma=20CLI=20Sync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compila APK Android y bundle Linux, luego sube al endpoint POST /api/upload_app.php con la version leída de pubspec.yaml. Uso: ./desplegar.sh [android|linux|all] servers.conf (gitignored) contiene WEBCONTROL_API_KEY y APP_NOMBRE. servers.conf.example documenta la plantilla para nuevos desarrolladores. Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 3 + desplegar.sh | 145 +++++++++++++++++++++++++++++++++++++++++++ servers.conf.example | 11 ++++ 3 files changed, 159 insertions(+) create mode 100755 desplegar.sh create mode 100644 servers.conf.example diff --git a/.gitignore b/.gitignore index 2bd531d..9dcbc35 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ app.*.map.json # Documentación interna de agentes IA (contiene IPs y credenciales) .agente/ + +# Configuración local de despliegue (contiene API keys — nunca commitear) +servers.conf diff --git a/desplegar.sh b/desplegar.sh new file mode 100755 index 0000000..0753ea3 --- /dev/null +++ b/desplegar.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env bash +# desplegar.sh — Compila y publica Agente Ventas en WebControlSigma (CLI Sync) +# Uso: ./desplegar.sh [android|linux|all] (default: all) +set -euo pipefail + +# ── Configuración ────────────────────────────────────────────────────────────── + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CONF="$SCRIPT_DIR/servers.conf" +UPLOAD_URL="https://siax-system.net/api/upload_app.php" +FECHA_HOY="$(date +%Y-%m-%d)" + +# ── Leer servers.conf ────────────────────────────────────────────────────────── + +if [[ ! -f "$CONF" ]]; then + echo "❌ servers.conf no encontrado." + echo " Copia servers.conf.example → servers.conf y completa los valores." + exit 1 +fi +# shellcheck source=/dev/null +source "$CONF" + +if [[ -z "${WEBCONTROL_API_KEY:-}" || "$WEBCONTROL_API_KEY" == "TU_API_KEY_AQUI" ]]; then + echo "❌ WEBCONTROL_API_KEY no configurado en servers.conf." + exit 1 +fi + +APP_NOMBRE="${APP_NOMBRE:-Agente Ventas}" + +# ── Leer versión desde pubspec.yaml ─────────────────────────────────────────── + +VERSION=$(grep '^version:' "$SCRIPT_DIR/pubspec.yaml" | sed 's/version: //' | cut -d'+' -f1 | tr -d '[:space:]') +if [[ -z "$VERSION" ]]; then + echo "❌ No se pudo leer la versión de pubspec.yaml." + exit 1 +fi +echo "📦 App: $APP_NOMBRE | Versión: $VERSION | Fecha: $FECHA_HOY" +echo "" + +# ── Plataformas a compilar ──────────────────────────────────────────────────── + +PLATAFORMA="${1:-all}" + +BUILD_ANDROID=false +BUILD_LINUX=false +case "$PLATAFORMA" in + android) BUILD_ANDROID=true ;; + linux) BUILD_LINUX=true ;; + all) BUILD_ANDROID=true; BUILD_LINUX=true ;; + *) + echo "Uso: $0 [android|linux|all]" + exit 1 + ;; +esac + +# ── Helper: subir a CLI Sync ────────────────────────────────────────────────── + +upload() { + local plataforma="$1" + local archivo="$2" + local changelog="${3:-}" + + echo "⬆️ Subiendo $plataforma → $(basename "$archivo") …" + + local response + response=$(curl -s -w "\n%{http_code}" \ + -X POST "$UPLOAD_URL" \ + -H "x-api-key: $WEBCONTROL_API_KEY" \ + -F "nombre=$APP_NOMBRE" \ + -F "version=$VERSION" \ + -F "plataforma=$plataforma" \ + -F "fecha_release=$FECHA_HOY" \ + ${changelog:+-F "changelog=$changelog"} \ + -F "archivo=@$archivo") + + local body http_code + body=$(echo "$response" | head -n -1) + http_code=$(echo "$response" | tail -n 1) + + if [[ "$http_code" == "200" ]]; then + local ok + ok=$(echo "$body" | grep -o '"ok":true' || true) + if [[ -n "$ok" ]]; then + local url md5 + url=$(echo "$body" | grep -o '"url_descarga":"[^"]*"' | cut -d'"' -f4) + md5=$(echo "$body" | grep -o '"archivo_md5":"[^"]*"' | cut -d'"' -f4) + echo " ✅ OK — $plataforma registrado" + [[ -n "$url" ]] && echo " 🔗 URL: $url" + [[ -n "$md5" ]] && echo " 🔑 MD5: $md5" + else + echo " ⚠️ HTTP 200 pero respuesta inesperada:" + echo " $body" + fi + else + echo " ❌ Error HTTP $http_code:" + echo " $body" + exit 1 + fi + echo "" +} + +# ── Build + upload ANDROID ──────────────────────────────────────────────────── + +if $BUILD_ANDROID; then + echo "🤖 Compilando Android APK …" + JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 flutter build apk --release 2>&1 | \ + grep -E "Running|Building|Built|error:|warning:" || true + + APK="$SCRIPT_DIR/build/app/outputs/flutter-apk/app-release.apk" + if [[ ! -f "$APK" ]]; then + echo "❌ APK no generado: $APK" + exit 1 + fi + SIZE=$(du -sh "$APK" | cut -f1) + echo " APK listo — $SIZE" + echo "" + upload "ANDROID" "$APK" "v$VERSION — auth completo, registro cloud/local, upload pedidos" +fi + +# ── Build + upload LINUX ────────────────────────────────────────────────────── + +if $BUILD_LINUX; then + echo "🐧 Compilando Linux bundle …" + flutter build linux --release 2>&1 | \ + grep -E "Building|Built|error:|warning:" || true + + BUNDLE_DIR="$SCRIPT_DIR/build/linux/x64/release/bundle" + if [[ ! -d "$BUNDLE_DIR" ]]; then + echo "❌ Bundle Linux no encontrado: $BUNDLE_DIR" + exit 1 + fi + + TAR="$SCRIPT_DIR/build/linux/x64/release/agente_ventas_${VERSION}_linux.tar.gz" + echo " Empaquetando bundle …" + tar -czf "$TAR" -C "$(dirname "$BUNDLE_DIR")" bundle/ + SIZE=$(du -sh "$TAR" | cut -f1) + echo " Tar listo — $SIZE" + echo "" + upload "LINUX" "$TAR" "v$VERSION — auth completo, registro cloud/local, upload pedidos" +fi + +# ── Resultado final ─────────────────────────────────────────────────────────── + +echo "🎉 Release $VERSION publicado en WebControlSigma." +echo " Panel: https://siax-system.net/app/software/index.php?tab=cli-sync" diff --git a/servers.conf.example b/servers.conf.example new file mode 100644 index 0000000..8212956 --- /dev/null +++ b/servers.conf.example @@ -0,0 +1,11 @@ +# servers.conf — configuración local de despliegue +# NO commitear este archivo (está en .gitignore). +# Copiar a servers.conf y completar los valores reales. +# +# Obtener API key: https://siax-system.net → Clientes → API Keys → Tab "Central" + +WEBCONTROL_API_KEY=TU_API_KEY_AQUI + +# Nombre exacto de la app registrado en WebControlSigma +# Verificar con: curl https://api.siax-system.net/api/apps -H "x-api-key: $WEBCONTROL_API_KEY" +APP_NOMBRE="Agente Ventas"