This commit is contained in:
parent
1617974db1
commit
7aea2fa5b3
2 changed files with 79 additions and 20 deletions
|
|
@ -1,23 +1,27 @@
|
|||
name: MD a HTML y deploy Apache
|
||||
name: Deploy HTML
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- '**.md'
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# El job corre dentro de un contenedor Ubuntu con el htdocs de Apache montado.
|
||||
# El runner tiene autorizado este mount vía valid_volumes en config.yaml.
|
||||
# Todo lo que el script copie a /output aparecerá inmediatamente en https://portaljack.freeddns.org/
|
||||
container:
|
||||
image: ubuntu:22.04
|
||||
volumes:
|
||||
- /srv/devops/data/apache/htdocs:/output
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Convertir y publicar
|
||||
- name: Convertir y desplegar
|
||||
shell: bash
|
||||
run: |
|
||||
chmod +x convertir.sh
|
||||
./convertir.sh
|
||||
77
convertir.sh
77
convertir.sh
|
|
@ -1,28 +1,83 @@
|
|||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# convertir.sh — Convierte archivos Markdown a HTML y los publica en Apache
|
||||
# Proyecto: JAK DevOps — workflow cy.yaml
|
||||
#
|
||||
# Requisitos:
|
||||
# - Ejecutar dentro del job container con /output montado sobre el htdocs de Apache
|
||||
# - El runner debe tener valid_volumes: ['/srv/devops/data/apache/**']
|
||||
# =============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
OUTPUT_DIR="/output"
|
||||
BASE_URL="https://portaljack.freeddns.org"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
dependencies() {
|
||||
echo "[1/3] Instalando dependencias..."
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq pandoc
|
||||
echo " pandoc $(pandoc --version | head -1 | cut -d' ' -f2) instalado"
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
convert_to_html() {
|
||||
echo "[2/3] Convirtiendo Markdown → HTML..."
|
||||
local converted=0
|
||||
local errors=0
|
||||
|
||||
for md in *.md; do
|
||||
# Guarda ante glob sin matches (bash con set -u no expande *.md si no hay ficheros)
|
||||
[ -f "$md" ] || { echo " [WARN] No se encontraron archivos .md en el directorio de trabajo"; return 0; }
|
||||
|
||||
local filename="${md%.md}"
|
||||
echo " Procesando: $md"
|
||||
|
||||
if pandoc "$md" \
|
||||
--standalone \
|
||||
--metadata title="$filename" \
|
||||
--highlight-style=tango \
|
||||
--output "${filename}.html"; then
|
||||
converted=$((converted + 1))
|
||||
else
|
||||
echo " [ERROR] Fallo al convertir: $md"
|
||||
errors=$((errors + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo " Convertidos: ${converted} | Errores: ${errors}"
|
||||
[ "$errors" -eq 0 ] || return 1
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
deploy() {
|
||||
echo "[3/3] Publicando en Apache..."
|
||||
local count=0
|
||||
|
||||
# Itera solo los HTML generados a partir de los .md presentes (no recoge HTMLs previos del repo)
|
||||
for md in *.md; do
|
||||
[ -f "$md" ] || continue
|
||||
filename="${md%.*}"
|
||||
pandoc -o "$filename.html" "$md"
|
||||
echo "Convertido: $md -> $filename.html"
|
||||
done
|
||||
}
|
||||
|
||||
upload(){
|
||||
for html in *.html; do
|
||||
local html="${md%.md}.html"
|
||||
[ -f "$html" ] || continue
|
||||
cp "$html" /output/
|
||||
echo "✅ Publicado: $html"
|
||||
|
||||
cp "$html" "${OUTPUT_DIR}/"
|
||||
count=$((count + 1))
|
||||
echo ""
|
||||
echo " ✅ ${BASE_URL}/${html}"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "======================================================"
|
||||
echo " ${count} página(s) publicada(s) en ${BASE_URL}/"
|
||||
echo "======================================================"
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
main() {
|
||||
dependencies
|
||||
convert_to_html
|
||||
upload
|
||||
deploy
|
||||
}
|
||||
|
||||
main
|
||||
|
|
|
|||
Loading…
Reference in a new issue