Compare commits

..

No commits in common. "main" and "v2.0.10" have entirely different histories.

4 changed files with 38 additions and 178 deletions

View file

@ -1,91 +1,52 @@
name: Deploy HTML + release name: Build and Release
on: on:
push: push:
branches: [main] tags:
- 'v*'
jobs: jobs:
deploy: build-and-release:
runs-on: ubuntu-22.04 runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-22.04
volumes:
- /srv/devops/data/apache/htdocs:/output
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Convertir y desplegar - name: Ejecutar script de build
shell: bash run: bash build.sh
run: |
chmod +x convertir.sh
./convertir.sh
# Opcional: copiar a release-dir lo que vaya a ir como asset - name: Crear release con los archivos generados
rm -rf release-dir
mkdir -p release-dir
cp /output/*.html release-dir/ || true
- name: Obtener última tag
run: |
# Esto falla si no hay tags: crea al menos una antes (v0.1.0, etc.)
TAG=$(git describe --tags --abbrev=0)
echo "Ultima tag encontrada: $TAG"
echo "TAG=$TAG" >> "$GITHUB_ENV"
- name: Crear release
env: env:
TOKEN: ${{ secrets.RELEASE_TOKEN }} RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
FORGEJO_API: ${{ github.api_url }}
REPO: ${{ github.repository }}
TAG: ${{ env.TAG }}
run: | run: |
if [ -z "$TAG" ]; then tag="${GITHUB_REF_NAME}"
echo "No hay TAG definida, no creo release"
exit 1
fi
JSON_PAYLOAD=$(cat <<EOF # Crear el release
{ release_response=$(curl -s -X POST \
"tag_name": "${TAG}", -H "Authorization: token $FORGEJO_TOKEN" \
"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" \ -H "Content-Type: application/json" \
-d "${JSON_PAYLOAD}" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" \
"${FORGEJO_API}/repos/${REPO}/releases") -d "{
\"tag_name\": \"${tag}\",
\"name\": \"Release ${tag}\",
\"body\": \"Release automático generado por build.sh\",
\"draft\": false,
\"prerelease\": false
}")
echo "Respuesta: ${RESPONSE}" echo "$release_response"
release_id=$(echo "$release_response" | jq -r '.id')
echo "Release creado con ID: $release_id"
RELEASE_ID=$(echo "${RESPONSE}" | jq -r '.id') # Subir todos los archivos que generó el script
for file in release-dir/*; do
if [ "${RELEASE_ID}" = "null" ] || [ -z "${RELEASE_ID}" ]; then filename=$(basename "$file")
echo "Error creando release" echo "Subiendo $filename al release..."
exit 1 curl -X POST \
fi -H "Authorization: token $FORGEJO_TOKEN" \
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" \ -H "Content-Type: application/octet-stream" \
--data-binary @"${FILE}" \ --data-binary @"$file" \
"${FORGEJO_API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=${filename}"
done done
echo "Release completado correctamente" echo "Release completado con todos los archivos"

View file

@ -1,22 +0,0 @@
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

View file

@ -1,79 +0,0 @@
#!/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

View file

@ -1 +1 @@
echo "holaaaa" echo "holaaaaa"