Skip to content

ci: Add hardware documentation workflow and update build workflow #23

ci: Add hardware documentation workflow and update build workflow

ci: Add hardware documentation workflow and update build workflow #23

Workflow file for this run

name: Build and Deploy Documentation
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: write
jobs:
build-doc:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies (Python + LaTeX)
run: |
sudo apt-get update
sudo apt-get install -y texlive-latex-extra texlive-fonts-recommended texlive-lang-english latexmk
pip install -r software/sphinx/requirements.txt
#################################################
# Generar Documentación Sphinx (HTML + PDF)
#################################################
- name: Build Sphinx Documentation
working-directory: software/sphinx
run: |
make clean
make pdfx
#################################################
# Preparar contenido para docs/
#################################################
- name: Prepare docs/ directory
env:
REPO_NAME: ${{ github.event.repository.name }}
run: |
# Backup hardware documentation if it exists
if [ -d "docs/hardware" ]; then
echo "Backing up hardware documentation..."
mv docs/hardware /tmp/hardware_backup
mv docs/hardware.html /tmp/hardware.html.backup 2>/dev/null || true
fi
# Clean docs/ directory (except hardware)
rm -rf docs
mkdir -p docs
# PDF generado por Sphinx
pdf_file=$(ls software/sphinx/pdf/*.pdf 2>/dev/null | head -n1)
if [ -n "$pdf_file" ]; then
cp "$pdf_file" docs/${REPO_NAME}_sphinx.pdf
else
echo "No PDF found in software/sphinx/pdf/"
fi
# HTML generado por Sphinx
cp -r software/sphinx/docs/* docs/
# Restore hardware documentation if it was backed up
if [ -d "/tmp/hardware_backup" ]; then
echo "Restoring hardware documentation..."
mv /tmp/hardware_backup docs/hardware
mv /tmp/hardware.html.backup docs/hardware.html 2>/dev/null || true
fi
# Permitir archivos especiales en GitHub Pages
touch docs/.nojekyll
#################################################
# Publicar cambios a la rama main
#################################################
- name: Commit and push docs/ to main
if: github.ref == 'refs/heads/main'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
# Check if there are changes to commit
git add docs/
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
# Commit changes
git commit -m "Deploy full documentation and product brief [skip ci]"
# Try to push, if fails pull and retry
max_retries=3
for i in $(seq 1 $max_retries); do
if git push origin main; then
echo "Successfully pushed!"
exit 0
fi
echo "Push failed, attempt $i of $max_retries"
echo "Pulling latest changes..."
# Pull with merge strategy
git pull --no-rebase --no-edit origin main || {
echo "Pull failed, forcing merge with ours strategy for docs/"
git checkout --ours docs/
git add docs/
git commit -m "Merge: Resolve conflicts keeping our docs/ [skip ci]" || true
}
done
echo "Failed to push after $max_retries attempts"
exit 1