Fix: Buscar aplicacion por nombre de repositorio REPO en apps.conf
This commit is contained in:
@@ -7,50 +7,58 @@ on:
|
|||||||
- master
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# 1. PASO INTELIGENTE: Obtiene el contexto y lee apps.conf usando la ruta actual
|
|
||||||
get-context:
|
get-context:
|
||||||
runs-on: host
|
runs-on: host
|
||||||
outputs:
|
outputs:
|
||||||
node_version: ${{ steps.setup.outputs.version }}
|
node_version: ${{ steps.setup.outputs.version }}
|
||||||
target_app: ${{ steps.setup.outputs.app }}
|
target_app: ${{ steps.setup.outputs.app }}
|
||||||
steps:
|
steps:
|
||||||
- name: Resolver Aplicación desde apps.conf por Ruta
|
- name: Resolver Aplicación desde apps.conf
|
||||||
id: setup
|
id: setup
|
||||||
run: |
|
run: |
|
||||||
# 1. Obtener la ruta absoluta donde está clonado este proyecto en el runner (ej: /var/www/html/front/pruebas/presupuesto)
|
# 1. Obtener el nombre del repositorio actual en Gitea (ej: front-Censo)
|
||||||
CURRENT_PATH=$(pwd)
|
REPO_NAME="${{ github.event.repository.name }}"
|
||||||
|
|
||||||
echo "Buscando qué sección de apps.conf coincide con la ruta: $CURRENT_PATH"
|
# 2. Determinar si buscamos un entorno -dev (develop) o producción (master)
|
||||||
|
if [ "${{ github.ref_name }}" = "develop" ]; then
|
||||||
# 2. Buscar en apps.conf el bloque que tenga exactamente ese APP_PATH
|
SUFFIX="-dev"
|
||||||
# Usamos awk para encontrar el bloque [nombre] asociado a esa ruta
|
else
|
||||||
TARGET_APP=$(awk -v path="$CURRENT_PATH" '
|
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 }
|
/^\[/ { gsub(/[\[\]]/, "", $0); current_box=$0; next }
|
||||||
$0 ~ "^APP_PATH="path"$" { print current_box; exit }
|
$0 == repo {
|
||||||
|
if ((suf == "-dev" && current_box ~ /-dev$/) || (suf == "" && current_box !~ /-dev$/)) {
|
||||||
|
print current_box;
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
}
|
||||||
' /etc/apps.conf)
|
' /etc/apps.conf)
|
||||||
|
|
||||||
if [ -z "$TARGET_APP" ]; then
|
if [ -z "$TARGET_APP" ]; then
|
||||||
echo "ERROR: No se encontró ninguna aplicación en apps.conf que coincida con la ruta $CURRENT_PATH"
|
echo "ERROR: No se encontró ninguna sección en /etc/apps.conf para el repositorio $REPO_NAME con el sufijo correcto."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Una vez que sabemos el nombre del bloque (ej: presupuesto-dev), leemos su versión de Node
|
# 4. Leer la versión de Node del bloque encontrado
|
||||||
VERSION=$(awk -v app="$TARGET_APP" '
|
VERSION=$(awk -v app="$TARGET_APP" '
|
||||||
$0=="["app"]" { found=1; next }
|
$0=="["app"]" { found=1; next }
|
||||||
/^\[/ && found { exit }
|
/^\[/ && found { exit }
|
||||||
found && /^NODE=/ { split($0, a, "="); print a[2]; exit }
|
found && /^NODE=/ { split($0, a, "="); print a[2]; exit }
|
||||||
' /etc/apps.conf)
|
' /etc/apps.conf)
|
||||||
|
|
||||||
MAJOR_VERSION=$(echo "$VERSION" | tr -d '[:space:]' | grep -oE '[0-9]+' | head -n1)
|
MAJOR_VERSION=$(echo "$VERSION" | tr -d '[:space:]' | grep -oE '[0-9]+' | head -n1)
|
||||||
|
|
||||||
echo "-> ID de Aplicación encontrado: $TARGET_APP"
|
echo "-> ID de Aplicación encontrado: $TARGET_APP"
|
||||||
echo "-> Versión Mayor de Node resuelta: $MAJOR_VERSION"
|
echo "-> Versión Mayor de Node resuelta: $MAJOR_VERSION"
|
||||||
|
|
||||||
# Exportar variables para los siguientes pasos
|
|
||||||
echo "app=${TARGET_APP}" >> $GITHUB_OUTPUT
|
echo "app=${TARGET_APP}" >> $GITHUB_OUTPUT
|
||||||
echo "version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT
|
echo "version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# 2. PASO DE COMPILACIÓN: Se ejecuta seguro en Docker con la versión correcta
|
|
||||||
build:
|
build:
|
||||||
needs: get-context
|
needs: get-context
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -65,7 +73,6 @@ jobs:
|
|||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
|
||||||
# 3. PASO DE DESPLIEGUE: Invoca tu script enviando el ID dinámico
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: [get-context, build]
|
needs: [get-context, build]
|
||||||
runs-on: host
|
runs-on: host
|
||||||
@@ -74,8 +81,5 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
TARGET_APP="${{ needs.get-context.outputs.target_app }}"
|
TARGET_APP="${{ needs.get-context.outputs.target_app }}"
|
||||||
BRANCH_NAME="${{ github.ref_name }}"
|
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"
|
sudo -u deploy /home/deploy/scripts/deploy-front.sh "$TARGET_APP" "$BRANCH_NAME"
|
||||||
|
|||||||
Reference in New Issue
Block a user