Skip to content

Commit e16fd06

Browse files
committed
feat(ci): add lychee broken link test
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 3ca9d7c commit e16fd06

File tree

2 files changed

+166
-84
lines changed

2 files changed

+166
-84
lines changed

.github/workflows/generate-top-index.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,25 @@ jobs:
6161
git config --local user.email "nextcloud-command@users.noreply.github.com"
6262
git config --local user.name "nextcloud-command"
6363
64-
- name: Commit and push changes
64+
- name: Create Pull Request for documentation index deployment
6565
if: github.event_name == 'push'
66-
run: |
67-
# Move the generated index.html and static files to the root of the gh-pages branch
68-
rm -rf index.html static/
69-
mv /tmp/index.html index.html
70-
mv /tmp/static/ static/
71-
git add index.html static/
72-
git commit -m "chore: update index.html for documentation" || echo "No changes to commit"
73-
git push origin gh-pages || echo "Nothing to push (expected if no changes)"
66+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
67+
id: cpr
68+
with:
69+
token: ${{ secrets.COMMAND_BOT_PAT }}
70+
commit-message: 'chore: deploy documentation index for ${{ github.ref_name }}'
71+
committer: nextcloud-command <nextcloud-command@users.noreply.github.com>
72+
author: nextcloud-command <nextcloud-command@users.noreply.github.com>
73+
signoff: true
74+
branch: 'automated/deploy/documentation-index-${{ github.ref_name }}'
75+
base: gh-pages
76+
title: 'Deploy documentation index for ${{ needs.stage.outputs.branch_name }}'
77+
body: 'Automated documentation index deployment from branch ${{ github.ref_name }}'
78+
delete-branch: true
79+
labels: 'automated, 3. to review'
80+
81+
- name: Enable Pull Request Automerge
82+
if: github.event_name == 'push'
83+
run: gh pr merge --merge --auto "${{ steps.cpr.outputs.pull-request-number }}"
7484
env:
7585
GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}

.github/workflows/sphinxbuild.yml

Lines changed: 147 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,42 @@ jobs:
5858
- name: Checkout repository
5959
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
6060

61-
- name: Configure apt cache to use /dev/shm
61+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
62+
with:
63+
python-version: '3.12'
64+
cache: 'pip'
65+
66+
- name: Install pip dependencies
67+
run: pip install -r requirements.txt
68+
69+
- name: Configure apt cache to use /tmp for caching LaTeX packages
6270
if: ${{ matrix.manual.build_pdf_path }}
6371
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
72+
mkdir -p /tmp/apt/cache/archives
73+
echo 'Dir::Cache::archives "/tmp/apt/cache/archives";' | sudo tee /etc/apt/apt.conf.d/apt-cache-tmp
6674
6775
- name: Cache LaTeX apt packages
6876
if: ${{ matrix.manual.build_pdf_path }}
6977
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
7078
with:
71-
path: /dev/shm/apt/cache/archives
79+
path: /tmp/apt/cache/archives
7280
key: latex-apt-${{ runner.os }}-${{ hashFiles('.github/workflows/sphinxbuild.yml') }}
7381
restore-keys: |
7482
latex-apt-${{ runner.os }}-
7583
7684
- name: Install LaTeX dependencies
7785
if: ${{ matrix.manual.build_pdf_path }}
7886
run: |
87+
# Install required packages for PDF generation via LaTeX
7988
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
89+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
90+
python3-pil python3-pip texlive-fonts-recommended latexmk \
91+
texlive-latex-extra texlive-latex-recommended texlive-xetex \
92+
texlive-fonts-extra-links texlive-fonts-extra xindy
9293
9394
- name: Fix apt cache ownership for caching
9495
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.12'
100-
cache: 'pip'
101-
102-
- name: Install pip dependencies
103-
run: pip install -r requirements.txt
96+
run: sudo chown -R $(id -u):$(id -g) /tmp/apt/cache/archives
10497

10598
- name: Build html documentation
10699
run: cd ${{ matrix.manual.directory }} && make ${{ matrix.manual.make_target }}
@@ -134,14 +127,17 @@ jobs:
134127
name: ${{ matrix.manual.name }}
135128
path: ${{ matrix.manual.directory }}/${{ matrix.manual.build_path }}
136129

137-
deploy:
138-
name: Deploy pages
130+
# Assembles all artifacts into the gh-pages layout and uploads a single
131+
# "staged" artifact that both `check` and `deploy` consume. Doing the
132+
# assembly once avoids repeating the checkout + merge logic in both jobs.
133+
stage:
134+
name: Stage documentation
139135
needs: build
140136
runs-on: ubuntu-latest
141-
if: github.event_name == 'push' # Only deploy on push, not PR
142137

143-
permissions:
144-
contents: write
138+
outputs:
139+
branch_name: ${{ steps.branch.outputs.branch_name }}
140+
version_name: ${{ steps.branch.outputs.version_name }}
145141

146142
steps:
147143
- name: Cache git metadata
@@ -153,7 +149,7 @@ jobs:
153149
git-metadata-${{ github.sha }}
154150
git-metadata
155151
156-
- name: Checkout Github Pages branch
152+
- name: Checkout gh-pages (for redirect sources)
157153
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
158154
with:
159155
ref: gh-pages
@@ -199,65 +195,142 @@ jobs:
199195
200196
- name: Merge ${{ steps.branch.outputs.branch_name }} documentation artifacts into gh-pages
201197
run: |
202-
# List artifacts
203-
ls -la artifacts/*/
204-
205-
# Cleanup old documentation
206-
rm -rf ${{ steps.branch.outputs.branch_name }}
198+
# Remove old documentation for this branch
207199
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
200+
201+
# Move all documentation artifacts into the server directory
202+
mv artifacts/* server/ || true
203+
204+
# Move PDF files to branch root
205+
mv server/*/*.pdf server/${{ steps.branch.outputs.branch_name }}/ || true
206+
207+
# For stable branches, also deploy to versioned folder (e.g., server/28/)
223208
if [ -n "${{ steps.branch.outputs.version_name }}" ]; then
224209
rm -rf server/${{ steps.branch.outputs.version_name }}
225210
cp -r server/${{ steps.branch.outputs.branch_name }} server/${{ steps.branch.outputs.version_name }}
226211
fi
227-
228-
# Cleanup
212+
213+
# Clean up empty directories
229214
find . -type d -empty -delete
230-
rm -rf artifacts
231215
232216
- name: Add various redirects for go.php and user_manual english version
233217
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 }}
218+
# Fetch default branch to get base redirect files
219+
git fetch origin ${{ github.event.repository.default_branch }}
220+
221+
# Checkout redirect files from default branch
222+
git checkout origin/${{ github.event.repository.default_branch }} -- go.php/index.html user_manual/index.html
223+
224+
# Create deployment directories and move redirects into place
225+
mkdir -p server/${{ steps.branch.outputs.branch_name }}/{go.php,user_manual}
226+
mv go.php/index.html server/${{ steps.branch.outputs.branch_name }}/go.php/
227+
mv user_manual/index.html server/${{ steps.branch.outputs.branch_name }}/user_manual/
228+
229+
- name: Upload staged site
230+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
231+
with:
232+
name: staged-site
233+
path: server/
236234

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
235+
check:
236+
name: Check staged documentation
237+
needs: stage
238+
runs-on: ubuntu-latest
239+
240+
steps:
241+
- name: Download staged site
242+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
243+
with:
244+
name: staged-site
245+
path: server/
246+
247+
- name: Check for broken links with lychee
248+
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0
249+
with:
250+
fail: true
251+
token: ${{ secrets.GITHUB_TOKEN }}
252+
jobSummary: true
253+
args: |
254+
--offline --no-progress --verbose
255+
--remap "https://docs.nextcloud.com/server/${{ needs.stage.outputs.branch_name }} file://$(pwd)/server/${{ needs.stage.outputs.branch_name }}"
256+
'server/${{ needs.stage.outputs.branch_name }}/**/*.html'
241257
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
246258
247-
- name: Commit ${{ steps.branch.outputs.branch_name }} documentation and push to gh-pages
259+
deploy:
260+
name: Deploy documentation to gh-pages
261+
needs: [stage, check]
262+
runs-on: ubuntu-latest
263+
if: github.event_name == 'push'
264+
265+
permissions:
266+
contents: write
267+
pull-requests: write
268+
269+
steps:
270+
- name: Cache git metadata
271+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
272+
with:
273+
path: .git
274+
key: git-metadata-${{ github.sha }}
275+
restore-keys: |
276+
git-metadata-${{ github.sha }}
277+
git-metadata
278+
279+
- name: Checkout gh-pages branch
280+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
281+
with:
282+
ref: gh-pages
283+
fetch-depth: 0
284+
persist-credentials: false
285+
286+
- name: Download staged site
287+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
288+
with:
289+
name: staged-site
290+
path: incoming/
291+
292+
- name: Apply staged site to gh-pages working tree
248293
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)"
294+
branch="${{ needs.stage.outputs.branch_name }}"
295+
version="${{ needs.stage.outputs.version_name }}"
296+
297+
rm -rf "server/${branch}"
298+
cp -r "incoming/${branch}" "server/${branch}"
299+
300+
if [ -n "${version}" ]; then
301+
rm -rf "server/${version}"
302+
cp -r "incoming/${version}" "server/${version}"
303+
fi
304+
305+
find . -type d -empty -delete
306+
307+
# QUickly log the directory structure for debugging purposes
308+
echo "Directory structure after applying staged site:"
309+
find server -type d -print
310+
311+
- name: Create Pull Request for documentation deployment
312+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
313+
id: cpr
314+
with:
315+
token: ${{ secrets.COMMAND_BOT_PAT }}
316+
commit-message: 'chore: deploy documentation for ${{ needs.stage.outputs.branch_name }}'
317+
committer: nextcloud-command <nextcloud-command@users.noreply.github.com>
318+
author: nextcloud-command <nextcloud-command@users.noreply.github.com>
319+
signoff: true
320+
branch: 'automated/deploy/documentation-${{ needs.stage.outputs.branch_name }}'
321+
base: gh-pages
322+
title: 'Deploy documentation for ${{ needs.stage.outputs.branch_name }}'
323+
body: 'Automated documentation deployment from branch ${{ github.ref_name }}'
324+
delete-branch: true
325+
labels: 'automated, 3. to review'
326+
327+
- name: Enable Pull Request Automerge
328+
run: gh pr merge --merge --auto "${{ steps.cpr.outputs.pull-request-number }}"
256329
env:
257330
GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}
258331

259332
summary:
260-
needs: build
333+
needs: [build, check]
261334
runs-on: ubuntu-latest-low
262335
if: always()
263336

@@ -267,6 +340,5 @@ jobs:
267340
name: build-deploy-summary
268341

269342
steps:
270-
# Only check if the build was successful
271343
- name: Summary status
272-
run: if ${{ needs.build.result != 'success' }}; then exit 1; fi
344+
run: if ${{ needs.build.result != 'success' || needs.check.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)