Compare commits
32 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3086cc7523 | ||
|
|
b8b6e87a89 | ||
|
|
22c5b5e502 | ||
|
|
6a7d65b187 | ||
|
|
0cc2fa76fe | ||
|
|
b1c531861e | ||
|
|
9bf5071842 | ||
|
|
2823a6b8f7 | ||
|
|
8000a94687 | ||
|
|
6f1c2d6037 | ||
|
|
fe9cf12d4f | ||
|
|
3171fa1363 | ||
|
|
9d3fdbccb2 | ||
|
|
0110ab2633 | ||
|
|
379f817e1e | ||
|
|
36c2a5a228 | ||
|
|
f517ef1eed | ||
|
|
70d19fd022 | ||
|
|
a85b6b6e90 | ||
|
|
c92b575bf4 | ||
|
|
dec62a9e70 | ||
|
|
f209927867 | ||
|
|
7e1e41c789 | ||
|
|
43c152ac0b | ||
|
|
b1d1465156 | ||
|
|
eb71eb8d4d | ||
|
|
532f8cb2b7 | ||
|
|
0916804b5c | ||
|
|
9954a9cd0c | ||
|
|
444606d63b | ||
|
|
4c56d6fc51 | ||
| 7ecd9a0c7a |
6 changed files with 169 additions and 35 deletions
|
|
@ -1,52 +1,82 @@
|
||||||
name: Build and Release
|
name: Build tar/zip y Release por version
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*' # Se ejecuta al pushear tags como v1.0.0, v0.1.0, etc.
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-release:
|
build-and-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Ejecutar script de build
|
- name: Preparar entorno
|
||||||
run: bash build.sh
|
|
||||||
|
|
||||||
- name: Crear release con los archivos generados
|
|
||||||
env:
|
|
||||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
tag="${GITHUB_REF_NAME}"
|
apt-get update
|
||||||
|
apt-get install -y jq
|
||||||
|
|
||||||
# Crear el release
|
- name: Crear tar y zip de la version
|
||||||
release_response=$(curl -s -X POST \
|
run: |
|
||||||
-H "Authorization: token $FORGEJO_TOKEN" \
|
mkdir -p release-dir
|
||||||
|
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
echo "Version/tag actual: $TAG"
|
||||||
|
|
||||||
|
# Empaquetar SOLO archivos versionados en esa tag
|
||||||
|
git archive --format=tar.gz --output="release-dir/repo-${TAG}.tar.gz" "$TAG"
|
||||||
|
git archive --format=zip --output="release-dir/repo-${TAG}.zip" "$TAG"
|
||||||
|
|
||||||
|
echo "Contenido de release-dir/"
|
||||||
|
ls -lh release-dir
|
||||||
|
|
||||||
|
- name: Crear release y subir assets
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
|
run: |
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
|
||||||
|
JSON_PAYLOAD=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag_name": "${TAG}",
|
||||||
|
"name": "Release ${TAG}",
|
||||||
|
"body": "Release automatico a partir de la tag ${TAG}",
|
||||||
|
"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" \
|
||||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" \
|
-d "${JSON_PAYLOAD}" \
|
||||||
-d "{
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases")
|
||||||
\"tag_name\": \"${tag}\",
|
|
||||||
\"name\": \"Release ${tag}\",
|
|
||||||
\"body\": \"Release automático generado por build.sh\",
|
|
||||||
\"draft\": false,
|
|
||||||
\"prerelease\": false
|
|
||||||
}")
|
|
||||||
|
|
||||||
echo "$release_response"
|
echo "Respuesta: ${RESPONSE}"
|
||||||
release_id=$(echo "$release_response" | jq -r '.id')
|
|
||||||
echo "Release creado con ID: $release_id"
|
|
||||||
|
|
||||||
# Subir todos los archivos que generó el script
|
RELEASE_ID=$(echo "${RESPONSE}" | jq -r '.id')
|
||||||
for file in release-dir/*; do
|
|
||||||
filename=$(basename "$file")
|
if [ "${RELEASE_ID}" = "null" ] || [ -z "${RELEASE_ID}" ]; then
|
||||||
echo "Subiendo $filename al release..."
|
echo "Error creando release"
|
||||||
curl -X POST \
|
exit 1
|
||||||
-H "Authorization: token $FORGEJO_TOKEN" \
|
fi
|
||||||
|
|
||||||
|
echo "Release creado con ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
|
for FILE in release-dir/*; do
|
||||||
|
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}" \
|
||||||
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=${filename}"
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Release completado con todos los archivos"
|
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
|
||||||
|
|
||||||
3
archivo.txt
Normal file
3
archivo.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Este es un documento de prueba.
|
||||||
|
Tiene varias líneas.
|
||||||
|
Y será convertido a Markdown.
|
||||||
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
|
||||||
2
test.sh
2
test.sh
|
|
@ -1 +1 @@
|
||||||
echo "holaaaaaa"
|
echo "holaaaa"
|
||||||
Loading…
Reference in a new issue