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