From a58c80e9eeb94cf3860167233f8914c3b017cc65 Mon Sep 17 00:00:00 2001 From: JazMin Date: Thu, 2 Jul 2026 02:03:14 -0600 Subject: [PATCH] Add workflow --- .gitea/workflows/deploy.yaml | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .gitea/workflows/deploy.yaml diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..83c99d8 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,81 @@ +name: Despliegue Automatizado Universal + +on: + push: + branches: + - develop + - master + +jobs: + # 1. PASO INTELIGENTE: Obtiene el contexto y lee apps.conf usando la ruta actual + get-context: + runs-on: host + outputs: + node_version: ${{ steps.setup.outputs.version }} + target_app: ${{ steps.setup.outputs.app }} + steps: + - name: Resolver Aplicación desde apps.conf por Ruta + id: setup + run: | + # 1. Obtener la ruta absoluta donde está clonado este proyecto en el runner (ej: /var/www/html/front/pruebas/presupuesto) + CURRENT_PATH=$(pwd) + + echo "Buscando qué sección de apps.conf coincide con la ruta: $CURRENT_PATH" + + # 2. Buscar en apps.conf el bloque que tenga exactamente ese APP_PATH + # Usamos awk para encontrar el bloque [nombre] asociado a esa ruta + TARGET_APP=$(awk -v path="$CURRENT_PATH" ' + /^\[/ { gsub(/[\[\]]/, "", $0); current_box=$0; next } + $0 ~ "^APP_PATH="path"$" { print current_box; exit } + ' /home/deploy/apps.conf) + + if [ -z "$TARGET_APP" ]; then + echo "ERROR: No se encontró ninguna aplicación en apps.conf que coincida con la ruta $CURRENT_PATH" + exit 1 + fi + + # 3. Una vez que sabemos el nombre del bloque (ej: presupuesto-dev), leemos su versión de Node + VERSION=$(awk -v app="$TARGET_APP" ' + $0=="["app"]" { found=1; next } + /^\[/ && found { exit } + found && /^NODE=/ { split($0, a, "="); print a[2]; exit } + ' /home/deploy/apps.conf) + + MAJOR_VERSION=$(echo "$VERSION" | tr -d '[:space:]' | grep -oE '[0-9]+' | head -n1) + + echo "-> ID de Aplicación encontrado: $TARGET_APP" + echo "-> Versión Mayor de Node resuelta: $MAJOR_VERSION" + + # Exportar variables para los siguientes pasos + echo "app=${TARGET_APP}" >> $GITHUB_OUTPUT + echo "version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT + + # 2. PASO DE COMPILACIÓN: Se ejecuta seguro en Docker con la versión correcta + build: + needs: get-context + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Configurar Node.js dinámicamente + uses: actions/setup-node@v4 + with: + node-version: ${{ needs.get-context.outputs.node_version }} + + - run: npm ci + - run: npm run build + + # 3. PASO DE DESPLIEGUE: Invoca tu script enviando el ID dinámico + deploy: + needs: [get-context, build] + runs-on: host + steps: + - name: Ejecutar Despliegue en Servidor Físico + run: | + TARGET_APP="${{ needs.get-context.outputs.target_app }}" + BRANCH_NAME="${{ github.ref_name }}" + + echo "Iniciando script de despliegue para el identificador: $TARGET_APP" + + # Llama a tu script pasándole el ID que descubrimos en el primer paso + sudo -u deploy /home/deploy/scripts/deploy-front.sh "$TARGET_APP" "$BRANCH_NAME"