|
| 1 | +name: Build and deploy documentation 📝 |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + # When called from publish.yml, the caller's build_and_test job has |
| 6 | + # already produced the wheel artifact this workflow needs. The internal |
| 7 | + # build_and_test job below is skipped in that case. |
| 8 | + inputs: |
| 9 | + deploy: |
| 10 | + description: 'Deploy to GitHub Pages after building' |
| 11 | + required: false |
| 12 | + type: boolean |
| 13 | + default: true |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + deploy: |
| 17 | + description: 'Deploy to GitHub Pages after building' |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + default: true |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: docs-${{ github.ref }} |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + build_and_test: |
| 28 | + name: Build wheel (for docs) |
| 29 | + # Only run when triggered manually. workflow_call invocations assume the |
| 30 | + # caller already ran build_and_test in the same workflow run, so the |
| 31 | + # wheel artifact is already available. |
| 32 | + if: github.event_name == 'workflow_dispatch' |
| 33 | + uses: ./.github/workflows/build_and_test.yml |
| 34 | + with: |
| 35 | + # Docs only need the ubuntu-latest / python-3.11 wheel; skip the full |
| 36 | + # OS/Python matrix and the wheel/C++ test jobs. |
| 37 | + minimal: true |
| 38 | + |
| 39 | + build_docs: |
| 40 | + name: Build docs |
| 41 | + needs: [build_and_test] |
| 42 | + # `build_and_test` is skipped when invoked via workflow_call; treat that |
| 43 | + # as success so build_docs runs in both modes. |
| 44 | + if: | |
| 45 | + always() && |
| 46 | + (needs.build_and_test.result == 'success' || needs.build_and_test.result == 'skipped') |
| 47 | + runs-on: ubuntu-latest |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v5 |
| 50 | + with: |
| 51 | + # gitpython (used by python/docs/source/conf.py to derive version) |
| 52 | + # needs the full history; the default depth=1 leaves it unable to |
| 53 | + # resolve HEAD's commit object on some refs. |
| 54 | + fetch-depth: 0 |
| 55 | + |
| 56 | + - name: Set up Python |
| 57 | + uses: actions/setup-python@v5 |
| 58 | + with: |
| 59 | + python-version: '3.11' |
| 60 | + |
| 61 | + - name: Compute build metadata |
| 62 | + id: meta |
| 63 | + run: | |
| 64 | + SHA=$(git rev-parse HEAD) |
| 65 | + SHORT=$(git rev-parse --short HEAD) |
| 66 | + DATE=$(date -u +'%Y-%m-%d %H:%M UTC') |
| 67 | + echo "sha=$SHA" >> "$GITHUB_OUTPUT" |
| 68 | + echo "short=$SHORT" >> "$GITHUB_OUTPUT" |
| 69 | + echo "date=$DATE" >> "$GITHUB_OUTPUT" |
| 70 | + echo "Build metadata: $SHORT ($SHA) at $DATE" |
| 71 | +
|
| 72 | + - name: Install system dependencies (Doxygen) |
| 73 | + run: | |
| 74 | + sudo apt-get update |
| 75 | + sudo apt-get install -y doxygen graphviz |
| 76 | +
|
| 77 | + - name: Fetch doxygen-awesome-css |
| 78 | + run: | |
| 79 | + curl -sSL https://github.com/jothepro/doxygen-awesome-css/archive/refs/tags/v2.3.4.tar.gz | tar -xz |
| 80 | + mv doxygen-awesome-css-2.3.4 doxygen-awesome-css |
| 81 | +
|
| 82 | + - name: Build C++ docs (Doxygen) |
| 83 | + env: |
| 84 | + PROJECT_NUMBER: "${{ steps.meta.outputs.short }} (${{ steps.meta.outputs.date }})" |
| 85 | + run: | |
| 86 | + mkdir -p build/docs/cpp site |
| 87 | + # Append PROJECT_NUMBER override via stdin; Doxygen reads stdin |
| 88 | + # config when invoked with `-` and merges with the file. |
| 89 | + (cat Doxyfile; echo "PROJECT_NUMBER = $PROJECT_NUMBER") | doxygen - |
| 90 | + mv build/docs/cpp site/cpp |
| 91 | +
|
| 92 | + - name: Install Python deps for Sphinx |
| 93 | + # The bertini2 wheel bundles the eigenpy C++ libraries it links |
| 94 | + # against; no Python `eigenpy` install is required to import bertini |
| 95 | + # for sphinx autodoc. |
| 96 | + run: | |
| 97 | + python -m pip install --upgrade pip |
| 98 | + pip install \ |
| 99 | + sphinx sphinx-rtd-theme sphinxcontrib-bibtex gitpython \ |
| 100 | + scikit-build-core build numpy |
| 101 | +
|
| 102 | + - name: Download built wheel |
| 103 | + uses: actions/download-artifact@v5 |
| 104 | + with: |
| 105 | + name: wheels-ubuntu-latest-3.11 |
| 106 | + path: dist/ |
| 107 | + |
| 108 | + - name: Install bertini from built wheel |
| 109 | + run: pip install --no-index --find-links dist/ bertini2 |
| 110 | + |
| 111 | + - name: Build Python docs (Sphinx) |
| 112 | + working-directory: python/docs |
| 113 | + env: |
| 114 | + BERTINI_GIT_SHA: ${{ steps.meta.outputs.sha }} |
| 115 | + BERTINI_BUILD_DATE: ${{ steps.meta.outputs.date }} |
| 116 | + run: | |
| 117 | + sphinx-build -b html -W --keep-going source ../../site/python |
| 118 | +
|
| 119 | + - name: Add landing page |
| 120 | + env: |
| 121 | + COMMIT_SHA: ${{ steps.meta.outputs.sha }} |
| 122 | + COMMIT_SHORT: ${{ steps.meta.outputs.short }} |
| 123 | + BUILD_DATE: ${{ steps.meta.outputs.date }} |
| 124 | + run: | |
| 125 | + sed \ |
| 126 | + -e "s|__COMMIT_SHA__|${COMMIT_SHA}|g" \ |
| 127 | + -e "s|__COMMIT_SHORT__|${COMMIT_SHORT}|g" \ |
| 128 | + -e "s|__BUILD_DATE__|${BUILD_DATE}|g" \ |
| 129 | + doc_resources/landing/index.html > site/index.html |
| 130 | + cp doc_resources/landing/style.css site/style.css |
| 131 | +
|
| 132 | + - name: Upload Pages artifact |
| 133 | + uses: actions/upload-pages-artifact@v3 |
| 134 | + with: |
| 135 | + path: site |
| 136 | + |
| 137 | + deploy_docs: |
| 138 | + name: Deploy to GitHub Pages |
| 139 | + needs: |
| 140 | + - build_docs |
| 141 | + if: needs.build_docs.result == 'success' && inputs.deploy |
| 142 | + runs-on: ubuntu-latest |
| 143 | + permissions: |
| 144 | + pages: write |
| 145 | + id-token: write |
| 146 | + environment: |
| 147 | + name: github-pages |
| 148 | + url: ${{ steps.deployment.outputs.page_url }} |
| 149 | + steps: |
| 150 | + - name: Deploy |
| 151 | + id: deployment |
| 152 | + uses: actions/deploy-pages@v4 |
0 commit comments