|
| 1 | +name: Build and publish documentation |
| 2 | + |
| 3 | +on: workflow_call |
| 4 | + |
| 5 | +env: |
| 6 | + DEFAULT_BRANCH: 'release' |
| 7 | + #SPHINXOPTS: '-W --keep-going -T' |
| 8 | + # ^-- If these SPHINXOPTS are enabled, then be strict about the builds and fail on any warnings |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-and-publish-docs: |
| 12 | + name: Build and publish documentation |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout active branch |
| 16 | + uses: actions/checkout@v5 |
| 17 | + with: |
| 18 | + lfs: true |
| 19 | + - name: Install uv |
| 20 | + uses: astral-sh/setup-uv@v7 |
| 21 | + with: |
| 22 | + enable-cache: true |
| 23 | + cache-dependency-glob: 'uv.lock' |
| 24 | + - name: Install the project |
| 25 | + run: uv sync --frozen |
| 26 | + - name: Print debugging information |
| 27 | + run: | |
| 28 | + echo "github.ref:" ${{github.ref}} |
| 29 | + echo "github.event_name:" ${{github.event_name}} |
| 30 | + echo "github.head_ref:" ${{github.head_ref}} |
| 31 | + echo "github.base_ref:" ${{github.base_ref}} |
| 32 | + set -x |
| 33 | + git rev-parse --abbrev-ref HEAD |
| 34 | + git branch |
| 35 | + git branch -a |
| 36 | + git remote -v |
| 37 | + uv run python -V |
| 38 | + uv pip list |
| 39 | +
|
| 40 | + # Build documentation |
| 41 | + - uses: sphinx-doc/github-problem-matcher@master |
| 42 | + - name: Build documentation |
| 43 | + run: | |
| 44 | + cd docs |
| 45 | + uv run make html |
| 46 | +
|
| 47 | + - name: Clone and cleanup gh-pages branch |
| 48 | + run: | |
| 49 | + set -x |
| 50 | + git fetch |
| 51 | + ( git branch gh-pages remotes/origin/gh-pages && git clone . --branch=gh-pages _gh-pages/ ) || mkdir _gh-pages |
| 52 | + rm -rf _gh-pages/.git/ |
| 53 | + mkdir -p _gh-pages/branch/ |
| 54 | +
|
| 55 | + # Delete orphaned branch-folders: |
| 56 | + # Go through each subfolder in _gh-pages/branch/ |
| 57 | + # If it relates to an orphaned branch, delete it. |
| 58 | + - name: Delete orphaned branch-folders |
| 59 | + run: | |
| 60 | + set -x |
| 61 | + for brdir in `ls _gh-pages/branch/` ; do |
| 62 | + brname=${brdir//--/\/} # replace '--' with '/' |
| 63 | + if ! git show-ref remotes/origin/$brname ; then |
| 64 | + echo "Removing $brdir" |
| 65 | + rm -r _gh-pages/branch/$brdir/ |
| 66 | + fi |
| 67 | + done |
| 68 | +
|
| 69 | + # Copy documentation to _gh-pages/ (if push happened on release branch) |
| 70 | + - name: Copy documentation to _gh-pages/ |
| 71 | + if: | |
| 72 | + contains(github.ref, env.DEFAULT_BRANCH) |
| 73 | + run: | |
| 74 | + set -x |
| 75 | + # Delete everything under _gh-pages/ that is from the |
| 76 | + # primary branch deployment. Excludes the other branches |
| 77 | + # _gh-pages/branch-* paths, and not including |
| 78 | + # _gh-pages itself. |
| 79 | + find _gh-pages/ -mindepth 1 ! -path '_gh-pages/branch*' -delete |
| 80 | + rsync -a docs/build/html/ _gh-pages/ |
| 81 | +
|
| 82 | + # Copy documentation to _gh-pages/branch/$brname (if push happened on any other branch) |
| 83 | + # ('/' gets replaced by '--') |
| 84 | + - name: Copy documentation to _gh-pages/branch/${{github.ref}} |
| 85 | + if: | |
| 86 | + !contains(github.ref, env.DEFAULT_BRANCH) |
| 87 | + run: | |
| 88 | + set -x |
| 89 | + #brname=$(git rev-parse --abbrev-ref HEAD) |
| 90 | + brname="${{github.ref}}" |
| 91 | + brname="${brname##refs/heads/}" |
| 92 | + brdir=${brname//\//--} # replace '/' with '--' |
| 93 | + rm -rf _gh-pages/branch/${brdir} |
| 94 | + rsync -a docs/build/html/ _gh-pages/branch/${brdir} |
| 95 | +
|
| 96 | + # Add .nojekyll file |
| 97 | + - name: Add .nojekyll file |
| 98 | + run: touch _gh-pages/.nojekyll |
| 99 | + |
| 100 | + # Publish: Commit gh-pages branch and publish it to GitHub Pages |
| 101 | + - name: Publish documentation |
| 102 | + uses: peaceiris/actions-gh-pages@v4 |
| 103 | + with: |
| 104 | + publish_branch: gh-pages |
| 105 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + publish_dir: _gh-pages/ |
| 107 | + force_orphan: true |
0 commit comments