|
| 1 | +name: Build and Deploy Documentation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - oxbow # Build docs for development branch as well |
| 8 | + paths: |
| 9 | + - 'docs/**' |
| 10 | + - 'coolbox/**' |
| 11 | + - '.github/workflows/docs.yml' |
| 12 | + pull_request: |
| 13 | + branches: |
| 14 | + - master |
| 15 | + paths: |
| 16 | + - 'docs/**' |
| 17 | + - 'coolbox/**' |
| 18 | + workflow_dispatch: # Allow manual trigger |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write # Required for pushing to gh-pages branch |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-and-deploy: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 # Fetch full history for version info |
| 32 | + |
| 33 | + - name: Set up Python |
| 34 | + uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: '3.11' |
| 37 | + cache: 'pip' |
| 38 | + |
| 39 | + - name: Install system dependencies |
| 40 | + run: | |
| 41 | + sudo apt-get update |
| 42 | + sudo apt-get install -y pandoc |
| 43 | +
|
| 44 | + - name: Install Python dependencies |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + # Install project with documentation dependencies |
| 48 | + pip install -e ".[doc]" |
| 49 | +
|
| 50 | + - name: Build documentation |
| 51 | + run: | |
| 52 | + cd docs |
| 53 | + # Clean old build artifacts if any |
| 54 | + rm -rf build/ |
| 55 | + # Build documentation with Sphinx |
| 56 | + sphinx-build -b html source build/html -W --keep-going |
| 57 | + # Create .nojekyll file to tell GitHub Pages not to ignore underscore-prefixed directories |
| 58 | + touch build/html/.nojekyll |
| 59 | + env: |
| 60 | + SPHINXOPTS: "-W --keep-going" |
| 61 | + |
| 62 | + - name: Check documentation |
| 63 | + run: | |
| 64 | + cd docs/build/html |
| 65 | + echo "Documentation build completed successfully!" |
| 66 | + echo "Generated files:" |
| 67 | + ls -lh |
| 68 | + echo "" |
| 69 | + echo "Total size:" |
| 70 | + du -sh . |
| 71 | +
|
| 72 | + # Only deploy when pushing to master branch |
| 73 | + - name: Deploy to GitHub Pages |
| 74 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 75 | + uses: peaceiris/actions-gh-pages@v4 |
| 76 | + with: |
| 77 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + publish_dir: ./docs/build/html |
| 79 | + publish_branch: gh-pages |
| 80 | + force_orphan: true # Create orphan gh-pages branch without history |
| 81 | + user_name: 'github-actions[bot]' |
| 82 | + user_email: 'github-actions[bot]@users.noreply.github.com' |
| 83 | + commit_message: 'Deploy documentation from ${{ github.sha }}' |
| 84 | + |
| 85 | + - name: Upload documentation artifact |
| 86 | + if: github.event_name == 'pull_request' |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: documentation |
| 90 | + path: docs/build/html |
| 91 | + retention-days: 7 |
0 commit comments