|
| 1 | +name: Build and Deploy Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main, master] |
| 8 | + workflow_dispatch: # Allow manual triggering |
| 9 | + |
| 10 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + pages: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +# Allow only one concurrent deployment (but don't cancel PR builds) |
| 17 | +concurrency: |
| 18 | + group: "pages-${{ github.event_name }}-${{ github.head_ref || github.ref }}" |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout scDiffEq |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Clone analysis notebooks |
| 29 | + run: | |
| 30 | + git clone --depth 1 https://github.com/scDiffEq/scdiffeq-analyses.git /tmp/scdiffeq-analyses |
| 31 | + |
| 32 | + # Create target directories |
| 33 | + mkdir -p docs/source/_analyses |
| 34 | + mkdir -p docs/source/_tutorials |
| 35 | + |
| 36 | + # Copy notebooks from manuscript figures |
| 37 | + for dir in /tmp/scdiffeq-analyses/manuscript/figure_*/notebooks/; do |
| 38 | + if [ -d "$dir" ]; then |
| 39 | + cp -v "$dir"*.ipynb docs/source/_analyses/ 2>/dev/null || true |
| 40 | + fi |
| 41 | + done |
| 42 | + |
| 43 | + # Copy tutorial notebooks |
| 44 | + cp -v /tmp/scdiffeq-analyses/tutorials/*.ipynb docs/source/_tutorials/ 2>/dev/null || true |
| 45 | + |
| 46 | + # List what we copied |
| 47 | + echo "=== Copied analysis notebooks ===" |
| 48 | + ls -la docs/source/_analyses/ |
| 49 | + echo "=== Copied tutorial notebooks ===" |
| 50 | + ls -la docs/source/_tutorials/ |
| 51 | + |
| 52 | + - name: Setup Python |
| 53 | + uses: actions/setup-python@v5 |
| 54 | + with: |
| 55 | + python-version: '3.12' |
| 56 | + cache: 'pip' |
| 57 | + |
| 58 | + - name: Free up disk space |
| 59 | + run: | |
| 60 | + # Remove unnecessary pre-installed software to free up space |
| 61 | + sudo rm -rf /usr/share/dotnet |
| 62 | + sudo rm -rf /usr/local/lib/android |
| 63 | + sudo rm -rf /opt/ghc |
| 64 | + sudo rm -rf /opt/hostedtoolcache/CodeQL |
| 65 | + df -h |
| 66 | + |
| 67 | + - name: Install pandoc |
| 68 | + run: | |
| 69 | + sudo apt-get update |
| 70 | + sudo apt-get install -y pandoc |
| 71 | + |
| 72 | + - name: Install dependencies |
| 73 | + run: | |
| 74 | + pip install --upgrade pip |
| 75 | + # Install CPU-only PyTorch first (much smaller than CUDA version) |
| 76 | + pip install torch --index-url https://download.pytorch.org/whl/cpu |
| 77 | + # Install remaining dependencies |
| 78 | + pip install -r docs/requirements.txt |
| 79 | + |
| 80 | + - name: Build documentation |
| 81 | + env: |
| 82 | + GITHUB_ACTIONS: true |
| 83 | + run: | |
| 84 | + cd docs |
| 85 | + # Build docs; warnings are logged but don't fail the build |
| 86 | + # (Many warnings are from type hints that don't resolve via intersphinx) |
| 87 | + sphinx-build -b html source _build/html --keep-going |
| 88 | + |
| 89 | + # Upload preview artifact for PRs (downloadable zip) |
| 90 | + - name: Upload PR preview artifact |
| 91 | + if: github.event_name == 'pull_request' |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: docs-preview-pr-${{ github.event.number }} |
| 95 | + path: docs/_build/html |
| 96 | + retention-days: 7 |
| 97 | + |
| 98 | + # Upload for GitHub Pages deployment (main branch only) |
| 99 | + - name: Upload Pages artifact |
| 100 | + if: github.event_name != 'pull_request' |
| 101 | + uses: actions/upload-pages-artifact@v3 |
| 102 | + with: |
| 103 | + path: docs/_build/html |
| 104 | + |
| 105 | + deploy: |
| 106 | + if: github.event_name != 'pull_request' |
| 107 | + environment: |
| 108 | + name: github-pages |
| 109 | + url: ${{ steps.deployment.outputs.page_url }} |
| 110 | + runs-on: ubuntu-latest |
| 111 | + needs: build |
| 112 | + steps: |
| 113 | + # NOTE: GitHub Pages must be enabled in repository settings: |
| 114 | + # https://github.com/scDiffEq/scDiffEq/settings/pages |
| 115 | + # Source should be set to "GitHub Actions" |
| 116 | + - name: Deploy to GitHub Pages |
| 117 | + id: deployment |
| 118 | + uses: actions/deploy-pages@v4 |
0 commit comments