From f3d3d95c7086f9c7b2011c35450413805ba3172b Mon Sep 17 00:00:00 2001 From: dscadmin Date: Thu, 2 Jul 2026 03:30:45 -0600 Subject: [PATCH] Add deploy.yaml --- .gitea/workflows/deploy.yaml | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 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..d1a3c87 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,85 @@ +name: Despliegue Automatizado Universal + +on: + push: + branches: + - develop + - master + +jobs: + 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 + id: setup + run: | + # 1. Obtener el nombre del repositorio actual en Gitea (ej: front-Censo) + REPO_NAME="${{ github.event.repository.name }}" + + # 2. Determinar si buscamos un entorno -dev (develop) o producción (master) + if [ "${{ github.ref_name }}" = "develop" ]; then + SUFFIX="-dev" + else + SUFFIX="" + fi + + echo "Buscando qué sección de apps.conf tiene REPO=$REPO_NAME y termina en '$SUFFIX'..." + + # 3. Buscar en /etc/apps.conf el bloque que contenga REPO=nombre_del_repo + TARGET_APP=$(awk -v repo="REPO=$REPO_NAME" -v suf="$SUFFIX" ' + /^\[/ { gsub(/[\[\]]/, "", $0); current_box=$0; next } + $0 == repo { + if ((suf == "-dev" && current_box ~ /-dev$/) || (suf == "" && current_box !~ /-dev$/)) { + print current_box; + exit + } + } + ' /etc/apps.conf) + + if [ -z "$TARGET_APP" ]; then + echo "ERROR: No se encontró ninguna sección en /etc/apps.conf para el repositorio $REPO_NAME con el sufijo correcto." + exit 1 + fi + + # 4. Leer la versión de Node del bloque encontrado + VERSION=$(awk -v app="$TARGET_APP" ' + $0=="["app"]" { found=1; next } + /^\[/ && found { exit } + found && /^NODE=/ { split($0, a, "="); print a[2]; exit } + ' /etc/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" + + echo "app=${TARGET_APP}" >> $GITHUB_OUTPUT + echo "version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT + + 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 + + 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 }}" + + sudo -u deploy /home/deploy/scripts/deploy-front.sh "$TARGET_APP" "$BRANCH_NAME"