Merge pull request #45 from datosgobes/develop #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate PDFs from AsciiDoc files | |
on: | |
push: | |
paths: | |
- 'docs/adoc/**' | |
workflow_dispatch: | |
inputs: | |
convert_md: | |
description: 'Convert Markdown to AsciiDoc' | |
required: false | |
type: boolean | |
default: false | |
jobs: | |
generate_pdfs: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: main # Asegura que obtenemos la versión más reciente de main | |
- name: Set up Docker Compose | |
run: | | |
echo "APP_DIR=/srv/app" > .env | |
echo "DOC_DIR=/srv/app/documents" >> .env | |
echo "OUTPUT_DIR=/srv/app/documents/output" >> .env | |
echo "PDF_PREFIX=dcat-ap-es" >> .env | |
echo "DEFAULT_THEME=datosgobes-theme" >> .env | |
echo "DEBUG=true" >> .env | |
- name: Create directories | |
run: | | |
mkdir -p output | |
mkdir -p refs/dcat-ap-es/pdf | |
- name: Build and run with Docker Compose | |
env: | |
CONVERT_MD: ${{ github.event.inputs.convert_md || 'false' }} | |
run: | | |
if [ "$CONVERT_MD" = "true" ]; then | |
docker compose --profile md2adoc up --build | |
else | |
docker compose up --build | |
fi | |
- name: Move PDFs to final location | |
run: | | |
mv output/*.pdf refs/dcat-ap-es/pdf/ | |
echo "=== Generated PDFs ===" | |
ls -la refs/dcat-ap-es/pdf/ | |
- name: Check for PDF changes | |
id: check_changes | |
run: | | |
# Actualizar antes de verificar | |
git fetch origin main | |
git reset --hard origin/main | |
# Generar un hash de los PDFs actuales en main | |
find refs/dcat-ap-es/pdf/ -type f -name "*.pdf" -exec sha256sum {} \; | sort > /tmp/main_pdf_hashes | |
# Los PDFs ya están en la ubicación final, no necesitamos moverlos de nuevo | |
# Generar un hash de los nuevos PDFs | |
find refs/dcat-ap-es/pdf/ -type f -name "*.pdf" -exec sha256sum {} \; | sort > /tmp/new_pdf_hashes | |
# Comparar los hashes | |
if diff /tmp/main_pdf_hashes /tmp/new_pdf_hashes > /dev/null; then | |
echo "PDFs are identical to those in main branch" | |
echo "has_changes=false" >> $GITHUB_OUTPUT | |
else | |
echo "PDFs have actual changes compared to main branch" | |
echo "has_changes=true" >> $GITHUB_OUTPUT | |
# Guardar los cambios para debugging | |
diff /tmp/main_pdf_hashes /tmp/new_pdf_hashes > /tmp/pdf_diff | |
cat /tmp/pdf_diff | |
fi | |
- name: Create branch with changes | |
if: steps.check_changes.outputs.has_changes == 'true' | |
id: create_branch | |
run: | | |
BRANCH_NAME="pdf-update-$(date +%Y%m%d-%H%M%S)" | |
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
echo "current_date=$(date +'%d-%m-%Y %H:%M:%S')" >> $GITHUB_OUTPUT | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git checkout -b $BRANCH_NAME | |
git add -f refs/dcat-ap-es/pdf/*.pdf | |
git commit -m "Update PDF documents [skip ci]" | |
git push origin $BRANCH_NAME | |
- name: Create Pull Request | |
if: steps.check_changes.outputs.has_changes == 'true' | |
id: create-pr | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ steps.create_branch.outputs.branch_name }} | |
base: main | |
delete-branch: true | |
sign-commits: true | |
title: "Actualización automática de documentos PDF" | |
body: | | |
## Actualización de documentos PDF | |
Este Pull Request actualiza automáticamente [los documentos PDF](https://github.com/datosgobes/DCAT-AP-ES/tree/main/refs/dcat-ap-es/pdf) generados a partir de archivos [AsciiDoc](https://docs.asciidoctor.org/asciidoc/latest/). | |
* 🤖 Generado por: GitHub Actions | |
* 📅 Fecha: ${{ steps.create_branch.outputs.current_date }} | |
@datosgobes/dcat-ap-es Por favor, revisen y aprueben este PR para actualizar los documentos. | |
labels: | | |
automated-pr | |
documentation | |
pdf-update | |
team-reviewers: | | |
datosgobes/dcat-ap-es |