Compare commits
18 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cc2fa76fe | ||
|
|
b1c531861e | ||
|
|
9bf5071842 | ||
|
|
2823a6b8f7 | ||
|
|
8000a94687 | ||
|
|
6f1c2d6037 | ||
|
|
fe9cf12d4f | ||
|
|
3171fa1363 | ||
|
|
9d3fdbccb2 | ||
|
|
0110ab2633 | ||
|
|
379f817e1e | ||
|
|
36c2a5a228 | ||
|
|
f517ef1eed | ||
|
|
70d19fd022 | ||
|
|
a85b6b6e90 | ||
|
|
c92b575bf4 | ||
|
|
dec62a9e70 | ||
|
|
f209927867 |
3 changed files with 192 additions and 49 deletions
|
|
@ -1,49 +1,91 @@
|
||||||
- name: Crear release con debug
|
name: Deploy HTML + release
|
||||||
env:
|
|
||||||
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
||||||
run: |
|
|
||||||
echo "=== Debug de token ==="
|
|
||||||
if [ -z "$RELEASE_TOKEN" ]; then
|
|
||||||
echo "❌ ERROR: RELEASE_TOKEN está vacío"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "✅ Token presente (longitud: ${#RELEASE_TOKEN})"
|
|
||||||
fi
|
|
||||||
|
|
||||||
tag="${GITHUB_REF_NAME}"
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
echo "=== Creando release ==="
|
jobs:
|
||||||
release_response=$(curl -s -w "\nHTTP:%{http_code}" -X POST \
|
deploy:
|
||||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
runs-on: ubuntu-22.04
|
||||||
-H "Content-Type: application/json" \
|
container:
|
||||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" \
|
image: catthehacker/ubuntu:act-22.04
|
||||||
-d "{
|
volumes:
|
||||||
\"tag_name\": \"${tag}\",
|
- /srv/devops/data/apache/htdocs:/output
|
||||||
\"name\": \"Release ${tag}\",
|
|
||||||
\"body\": \"Release automático\",
|
|
||||||
\"draft\": false,
|
|
||||||
\"prerelease\": false
|
|
||||||
}")
|
|
||||||
|
|
||||||
echo "$release_response"
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
http_code=$(echo "$release_response" | grep "HTTP:" | cut -d: -f2)
|
- name: Convertir y desplegar
|
||||||
echo "Status HTTP: $http_code"
|
shell: bash
|
||||||
|
run: |
|
||||||
|
chmod +x convertir.sh
|
||||||
|
./convertir.sh
|
||||||
|
|
||||||
if [ "$http_code" = "201" ]; then
|
# Opcional: copiar a release-dir lo que vaya a ir como asset
|
||||||
release_id=$(echo "$release_response" | grep -v "HTTP:" | jq -r '.id')
|
rm -rf release-dir
|
||||||
echo "✅ Release ID: $release_id"
|
mkdir -p release-dir
|
||||||
|
cp /output/*.html release-dir/ || true
|
||||||
|
|
||||||
for file in release-dir/*; do
|
- name: Obtener última tag
|
||||||
filename=$(basename "$file")
|
run: |
|
||||||
echo "Subiendo $filename..."
|
# Esto falla si no hay tags: crea al menos una antes (v0.1.0, etc.)
|
||||||
curl -X POST \
|
TAG=$(git describe --tags --abbrev=0)
|
||||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
echo "Ultima tag encontrada: $TAG"
|
||||||
-H "Content-Type: application/octet-stream" \
|
echo "TAG=$TAG" >> "$GITHUB_ENV"
|
||||||
--data-binary @"$file" \
|
|
||||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=${filename}"
|
- name: Crear release
|
||||||
done
|
env:
|
||||||
else
|
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
echo "❌ Error creando release"
|
FORGEJO_API: ${{ github.api_url }}
|
||||||
exit 1
|
REPO: ${{ github.repository }}
|
||||||
fi
|
TAG: ${{ env.TAG }}
|
||||||
|
run: |
|
||||||
|
if [ -z "$TAG" ]; then
|
||||||
|
echo "No hay TAG definida, no creo release"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JSON_PAYLOAD=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag_name": "${TAG}",
|
||||||
|
"name": "Release ${TAG}",
|
||||||
|
"body": "Release automatico",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "Creando release para tag: ${TAG}"
|
||||||
|
|
||||||
|
RESPONSE=$(curl -s -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "${JSON_PAYLOAD}" \
|
||||||
|
"${FORGEJO_API}/repos/${REPO}/releases")
|
||||||
|
|
||||||
|
echo "Respuesta: ${RESPONSE}"
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "${RESPONSE}" | jq -r '.id')
|
||||||
|
|
||||||
|
if [ "${RELEASE_ID}" = "null" ] || [ -z "${RELEASE_ID}" ]; then
|
||||||
|
echo "Error creando release"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Release creado con ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
|
for FILE in release-dir/*; do
|
||||||
|
[ -e "$FILE" ] || continue
|
||||||
|
FILENAME=$(basename "${FILE}")
|
||||||
|
echo "Subiendo ${FILENAME}..."
|
||||||
|
|
||||||
|
curl -s -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary @"${FILE}" \
|
||||||
|
"${FORGEJO_API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Release completado correctamente"
|
||||||
22
archivo.md
Normal file
22
archivo.md
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
hola, que tal
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\- primer intento
|
||||||
|
|
||||||
|
\- segundo intento
|
||||||
|
|
||||||
|
\- tercer intento
|
||||||
|
|
||||||
|
\- con tag
|
||||||
|
|
||||||
|
\- después tag
|
||||||
|
|
||||||
|
\- con tag creado de antes
|
||||||
|
|
||||||
|
\- segunda prueba
|
||||||
|
|
||||||
|
\- tercera prueba
|
||||||
|
|
||||||
|
\- cuarta prueba
|
||||||
|
|
||||||
79
convertir.sh
Normal file
79
convertir.sh
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
#!/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
|
||||||
|
local html="${md%.md}.html"
|
||||||
|
[ -f "$html" ] || continue
|
||||||
|
|
||||||
|
cp "$html" "${OUTPUT_DIR}/"
|
||||||
|
count=$((count + 1))
|
||||||
|
echo ""
|
||||||
|
echo " ${BASE_URL}/${html}"
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
main() {
|
||||||
|
dependencies
|
||||||
|
convert_to_html
|
||||||
|
deploy
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
Loading…
Reference in a new issue