Skip to content

Commit 850ddd8

Browse files
chore: update .github/workflows/sphinxbuild.yml from master branch
Signed-off-by: GitHub <noreply@github.com>
1 parent 5ec4223 commit 850ddd8

1 file changed

Lines changed: 255 additions & 23 deletions

File tree

.github/workflows/sphinxbuild.yml

Lines changed: 255 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Pull Request Docs Check"
1+
name: "Build documentation"
22

33
on:
44
pull_request:
@@ -7,34 +7,266 @@ on:
77
- master
88
- stable*
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
11-
user_manual:
14+
build:
15+
16+
name: Build ${{ matrix.manual.name }}
1217
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
manual:
22+
- name: "user_manual"
23+
directory: "user_manual"
24+
make_target: "html"
25+
build_path: "_build/html"
26+
build_pdf_path: "_build/latex"
27+
publish: true
28+
29+
- name: "user_manual-en"
30+
directory: "user_manual"
31+
make_target: "html-lang-en"
32+
build_path: "_build/html"
33+
publish: false
34+
35+
- name: "developer_manual"
36+
directory: "developer_manual"
37+
make_target: "html"
38+
build_path: "_build/html/com"
39+
publish: true
40+
41+
- name: "admin_manual"
42+
directory: "admin_manual"
43+
make_target: "html"
44+
build_path: "_build/html/com"
45+
build_pdf_path: "_build/latex"
46+
publish: true
47+
1348
steps:
14-
- uses: actions/checkout@v1
15-
- uses: ammaraskar/sphinx-action@master
49+
- name: Cache git metadata
50+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
51+
with:
52+
path: .git
53+
key: git-metadata-${{ github.sha }}
54+
restore-keys: |
55+
git-metadata-${{ github.sha }}
56+
git-metadata
57+
58+
- name: Checkout repository
59+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
60+
61+
- name: Configure apt cache to use /dev/shm
62+
if: ${{ matrix.manual.build_pdf_path }}
63+
run: |
64+
mkdir -p /dev/shm/apt/cache/archives
65+
echo 'Dir::Cache::archives "/dev/shm/apt/cache/archives";' | sudo tee /etc/apt/apt.conf.d/apt-cache-shm
66+
67+
- name: Cache LaTeX apt packages
68+
if: ${{ matrix.manual.build_pdf_path }}
69+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
70+
with:
71+
path: /dev/shm/apt/cache/archives
72+
key: latex-apt-${{ runner.os }}-${{ hashFiles('.github/workflows/sphinxbuild.yml') }}
73+
restore-keys: |
74+
latex-apt-${{ runner.os }}-
75+
76+
- name: Install LaTeX dependencies
77+
if: ${{ matrix.manual.build_pdf_path }}
78+
run: |
79+
sudo DEBIAN_FRONTEND=noninteractive apt-get update
80+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
81+
--no-install-recommends \
82+
python3-pil \
83+
python3-pip \
84+
texlive-fonts-recommended \
85+
latexmk \
86+
texlive-latex-extra \
87+
texlive-latex-recommended \
88+
texlive-xetex \
89+
texlive-fonts-extra-links \
90+
texlive-fonts-extra \
91+
xindy
92+
93+
- name: Fix apt cache ownership for caching
94+
if: ${{ matrix.manual.build_pdf_path }}
95+
run: sudo chown -R $(id -u):$(id -g) /dev/shm/apt/cache/archives
96+
97+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
98+
with:
99+
python-version: '3.10'
100+
cache: 'pip'
101+
102+
- name: Install pip dependencies
103+
run: pip install -r requirements.txt
104+
105+
- name: Build html documentation
106+
run: cd ${{ matrix.manual.directory }} && make ${{ matrix.manual.make_target }}
107+
108+
- name: Compute PDF release version
109+
if: ${{ matrix.manual.build_pdf_path }}
110+
id: pdf_version
111+
run: |
112+
branch="${GITHUB_REF#refs/heads/}"
113+
if [[ "$branch" == stable* ]]; then
114+
echo "release=${branch#stable}" >> $GITHUB_OUTPUT
115+
else
116+
echo "release=latest" >> $GITHUB_OUTPUT
117+
fi
118+
119+
- name: Build pdf documentation
120+
if: ${{ matrix.manual.build_pdf_path }}
121+
env:
122+
DOCS_RELEASE: ${{ steps.pdf_version.outputs.release }}
123+
run: |
124+
set -e
125+
cd ${{ matrix.manual.directory }}
126+
make latexpdf
127+
ls -la ${{ matrix.manual.build_pdf_path }}
128+
cp ${{ matrix.manual.build_pdf_path }}/*.pdf ${{ matrix.manual.build_path }}/
129+
130+
- name: Upload static documentation
131+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
132+
if: ${{ matrix.manual.publish }}
16133
with:
17-
docs-folder: "user_manual/"
18-
pre-build-command: pip install -r requirements.txt
19-
build-command: make html
20-
repo-token: "${{ secrets.GITHUB_TOKEN }}"
21-
developer_manual:
134+
name: ${{ matrix.manual.name }}
135+
path: ${{ matrix.manual.directory }}/${{ matrix.manual.build_path }}
136+
137+
deploy:
138+
name: Deploy pages
139+
needs: build
22140
runs-on: ubuntu-latest
141+
if: github.event_name == 'push' # Only deploy on push, not PR
142+
143+
permissions:
144+
contents: write
145+
23146
steps:
24-
- uses: actions/checkout@v1
25-
- uses: ammaraskar/sphinx-action@master
147+
- name: Cache git metadata
148+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
26149
with:
27-
docs-folder: "developer_manual/"
28-
pre-build-command: pip install -r requirements.txt
29-
build-command: make html
30-
repo-token: "${{ secrets.GITHUB_TOKEN }}"
31-
admin_manual:
150+
path: .git
151+
key: git-metadata-${{ github.sha }}
152+
restore-keys: |
153+
git-metadata-${{ github.sha }}
154+
git-metadata
155+
156+
- name: Checkout Github Pages branch
157+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
158+
with:
159+
ref: gh-pages
160+
fetch-depth: 0
161+
token: ${{ secrets.COMMAND_BOT_PAT }}
162+
163+
- name: Download all ${{ needs.build.outputs.branch_name }} artifacts
164+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
165+
with:
166+
path: artifacts/
167+
168+
- name: Get branch name and find latest stable
169+
id: branch
170+
run: |
171+
current_branch="${GITHUB_REF#refs/heads/}"
172+
173+
# Find the highest numbered stable branch from the remote
174+
highest_stable=$(git ls-remote --heads origin | sed -n 's?.*refs/heads/stable\([0-9]\{2\}\)$?\1?p' | sort -n | tail -1)
175+
highest_stable_branch="stable${highest_stable}"
176+
177+
echo "Current branch: $current_branch"
178+
echo "Highest stable branch found: $highest_stable_branch"
179+
180+
# Map actual branch names to deployment folder names
181+
case "$current_branch" in
182+
"master")
183+
echo "branch_name=latest" >> $GITHUB_OUTPUT
184+
;;
185+
"$highest_stable_branch")
186+
echo "branch_name=stable" >> $GITHUB_OUTPUT
187+
# Also record the numeric version so we can publish to server/<number>/ too
188+
echo "version_name=${highest_stable}" >> $GITHUB_OUTPUT
189+
;;
190+
*)
191+
# Remove stable prefix for current branch
192+
current_branch="${current_branch#stable}"
193+
echo "branch_name=$current_branch" >> $GITHUB_OUTPUT
194+
;;
195+
esac
196+
197+
echo "Deployment folder name: ${{ steps.branch.outputs.branch_name }}"
198+
echo "Version name for additional deployment (if applicable): ${{ steps.branch.outputs.version_name }}"
199+
200+
- name: Merge ${{ steps.branch.outputs.branch_name }} documentation artifacts into gh-pages
201+
run: |
202+
# List artifacts
203+
ls -la artifacts/*/
204+
205+
# Cleanup old documentation
206+
rm -rf ${{ steps.branch.outputs.branch_name }}
207+
rm -rf server/${{ steps.branch.outputs.branch_name }}
208+
mkdir -p server/${{ steps.branch.outputs.branch_name }}
209+
210+
# Copy all built documentation into dedicated subdirectories
211+
for artifact in artifacts/*; do
212+
if [ -d "$artifact" ]; then
213+
manual_name="$(basename "$artifact")"
214+
mkdir -p "server/${{ steps.branch.outputs.branch_name }}/$manual_name"
215+
cp -r "$artifact/"* "server/${{ steps.branch.outputs.branch_name }}/$manual_name/"
216+
fi
217+
done
218+
219+
# Move pdf files to the root of the branch_name
220+
mv server/${{ steps.branch.outputs.branch_name }}/*/*.pdf server/${{ steps.branch.outputs.branch_name }}/ || true
221+
222+
# If this is the highest stable branch, also deploy to its versioned folder
223+
if [ -n "${{ steps.branch.outputs.version_name }}" ]; then
224+
rm -rf server/${{ steps.branch.outputs.version_name }}
225+
cp -r server/${{ steps.branch.outputs.branch_name }} server/${{ steps.branch.outputs.version_name }}
226+
fi
227+
228+
# Cleanup
229+
find . -type d -empty -delete
230+
rm -rf artifacts
231+
232+
- name: Add various redirects for go.php and user_manual english version
233+
run: |
234+
# Fetch source branches so git checkout origin/... works from the gh-pages checkout
235+
git fetch origin ${{ github.event.repository.default_branch }} ${{ github.ref_name }}
236+
237+
# Generate go.php redirect from main branch
238+
git checkout origin/${{ github.event.repository.default_branch }} -- go.php/index.html
239+
mkdir -p server/${{ steps.branch.outputs.branch_name }}/go.php
240+
mv go.php/index.html server/${{ steps.branch.outputs.branch_name }}/go.php/index.html
241+
242+
# Generate user_manual english redirect
243+
git checkout origin/${{ github.ref_name }} -- user_manual/index.html
244+
mkdir -p server/${{ steps.branch.outputs.branch_name }}/user_manual
245+
mv user_manual/index.html server/${{ steps.branch.outputs.branch_name }}/user_manual/index.html
246+
247+
- name: Commit ${{ steps.branch.outputs.branch_name }} documentation and push to gh-pages
248+
run: |
249+
git config --local user.email "nextcloud-command@users.noreply.github.com"
250+
git config --local user.name "nextcloud-command"
251+
git add .
252+
git diff --staged --quiet || git commit -m "chore: deploy documentation for ${{ steps.branch.outputs.branch_name }}"
253+
# Ensure we are up to date with the remote gh-pages branch
254+
git pull --rebase origin gh-pages || true
255+
git push origin gh-pages || echo "Nothing to push (expected if no changes)"
256+
env:
257+
GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}
258+
259+
summary:
260+
needs: build
32261
runs-on: ubuntu-latest
262+
if: always()
263+
264+
permissions:
265+
contents: read
266+
267+
name: build-deploy-summary
268+
33269
steps:
34-
- uses: actions/checkout@v1
35-
- uses: ammaraskar/sphinx-action@master
36-
with:
37-
docs-folder: "admin_manual/"
38-
pre-build-command: pip install -r requirements.txt
39-
build-command: make html
40-
repo-token: "${{ secrets.GITHUB_TOKEN }}"
270+
# Only check if the build was successful
271+
- name: Summary status
272+
run: if ${{ needs.build.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)