Skip to content

Commit 27e0e7f

Browse files
committed
fix: clean up staging artifact structure and deploy logic
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 8e7ca61 commit 27e0e7f

1 file changed

Lines changed: 77 additions & 48 deletions

File tree

.github/workflows/sphinxbuild.yml

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ jobs:
242242
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
243243
with:
244244
ref: gh-pages
245-
fetch-depth: 0
245+
fetch-depth: 1
246246
path: validation-context
247247

248248
# ========================================================================
@@ -305,85 +305,96 @@ jobs:
305305
echo "Additional deployment folder (if applicable): ${{ steps.branch.outputs.additional_deployment }}"
306306
307307
# ========================================================================
308-
# BUILD FULL DEPLOYMENT STRUCTURE
308+
# ORGANIZE ARTIFACTS FOR DEPLOYMENT
309309
# ========================================================================
310-
# Build the complete gh-pages structure in deploy-staging/ so that:
311-
# 1. Lychee can validate the new content in its actual deployment context
312-
# 2. The staged site includes existing versions (for cross-version link validation)
313-
# 3. The staged site is ready to be copied directly to gh-pages
310+
# Create a clean, minimal staging structure:
311+
# - Deploy only the NEW artifacts for this branch
312+
# - No need to include existing versions (we'll merge them during deploy)
314313
# ========================================================================
315-
- name: Build full deployment structure
314+
- name: Organize artifacts for deployment
315+
id: organize
316316
run: |
317317
branch="${{ steps.branch.outputs.branch_name }}"
318-
additional="${{ steps.branch.outputs.additional_deployment }}"
319318
320-
# Start with existing gh-pages content (all current versions)
321-
mkdir -p deploy-staging/server
322-
cp -r validation-context/server/* deploy-staging/server/ || true
323-
324-
# Organize new artifacts into the deployment structure
319+
# Create the branch folder directly
325320
mkdir -p "deploy-staging/${branch}"
326321
322+
# Copy artifacts preserving their manual folder structure
323+
# Each artifact (user_manual, admin_manual, developer_manual) contains
324+
# the build output that should be placed in a folder named after the artifact
327325
for artifact in artifacts/*; do
328326
if [ -d "$artifact" ]; then
329327
manual_name="$(basename "$artifact")"
330-
mkdir -p "deploy-staging/${branch}/$manual_name"
331-
cp -r "$artifact/"* "deploy-staging/${branch}/$manual_name/"
328+
# Create the manual-specific folder
329+
mkdir -p "deploy-staging/${branch}/${manual_name}"
330+
# Copy artifact contents into the manual folder
331+
cp -r "$artifact/"* "deploy-staging/${branch}/${manual_name}/"
332332
fi
333333
done
334334
335-
# Move PDF files to the root of the branch folder
336-
mv "deploy-staging/${branch}"/*/*.pdf "deploy-staging/${branch}/" || true
337-
338-
# If this is the highest stable, also prepare the additional deployment folder
339-
if [ -n "${additional}" ]; then
340-
mkdir -p "deploy-staging/${additional}"
341-
cp -r "deploy-staging/${branch}"/* "deploy-staging/${additional}/"
342-
fi
335+
# Move PDF files to the root of the branch folder for cleaner structure
336+
find "deploy-staging/${branch}/" -maxdepth 2 -name "*.pdf" -type f -exec mv {} "deploy-staging/${branch}/" \;
343337
344338
# Clean up empty directories
345339
find deploy-staging -type d -empty -delete
346340
347-
echo "Full deployment structure prepared:"
348-
find deploy-staging -type d -maxdepth 2
341+
echo "Staged artifacts for ${branch}:"
342+
find deploy-staging -type f | head -20
349343
350344
# ========================================================================
351345
# UPLOAD STAGING ARTIFACTS
352346
# ========================================================================
353-
# Upload only the minimal, organized artifacts needed for deployment.
354-
# The deploy job will download this and place it in the correct location
355-
# on the gh-pages branch.
347+
# Upload only the NEW artifacts in their branch structure.
348+
# The deploy job will handle merging with existing versions on gh-pages.
356349
# ========================================================================
357350
- name: Upload staged artifacts
358351
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
359352
with:
360-
name: staged-site
353+
name: staged-documentation-${{ steps.branch.outputs.branch_name }}
361354
path: deploy-staging/
362355

363356
# ========================================================================
364357
# VALIDATION: CHECK FOR BROKEN LINKS (NEW CONTENT IN FULL CONTEXT)
365358
# ========================================================================
366-
# Run link checker against the new documentation at deploy-staging/<branch>/.
367-
# The deploy-staging/ directory includes all existing versions (from
368-
# validation-context/), so lychee can validate cross-version links like
369-
# references to stable/, other version numbers, etc.
359+
# For link validation, we need the full context (existing versions) so
360+
# lychee can resolve cross-version references. So we:
361+
# 1. Build a temporary validation structure with both old and new content
362+
# 2. Run lychee only against the NEW content
363+
# 3. Clean up the temporary structure
370364
# ========================================================================
365+
- name: Build full validation context
366+
run: |
367+
branch="${{ steps.branch.outputs.branch_name }}"
368+
369+
# Build validation structure: start with existing versions
370+
mkdir -p full-context/server
371+
cp -r validation-context/server/* full-context/server/ || true
372+
373+
# Merge in the new artifacts
374+
mkdir -p "full-context/server/${branch}"
375+
cp -r "deploy-staging/${branch}/"* "full-context/server/${branch}/" || true
376+
377+
echo "Validation structure ready:"
378+
find full-context -type d -maxdepth 2
379+
371380
- name: Check for broken links with lychee
372381
uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2.8.0
373382
with:
374383
fail: true
375384
token: ${{ secrets.GITHUB_TOKEN }}
376385
jobSummary: true
377386
args: |
378-
--root-dir $(pwd)/deploy-staging
379-
--exclude 'file://$(pwd)/deploy-staging/builds'
380-
--exclude 'file://$(pwd)/deploy-staging/projects'
387+
--root-dir $(pwd)/full-context
381388
--offline
382389
--no-progress
383-
--remap 'https://docs.nextcloud.com/server/ file://$(pwd)/deploy-staging/server/'
390+
--remap 'https://docs.nextcloud.com/server/ file://$(pwd)/full-context/server/'
384391
--exclude 'mailto:'
385392
--exclude-path '.*/404\.html'
386-
'deploy-staging/server/${{ steps.branch.outputs.branch_name }}/**/*.html'
393+
'full-context/server/${{ steps.branch.outputs.branch_name }}/**/*.html'
394+
395+
- name: Clean up validation context
396+
if: always()
397+
run: rm -rf full-context
387398

388399
# ============================================================================
389400
# DEPLOY
@@ -420,37 +431,47 @@ jobs:
420431
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
421432
with:
422433
ref: gh-pages
423-
fetch-depth: 0
434+
fetch-depth: 1
424435
persist-credentials: false
425436

426437
- name: Download staged artifacts
427438
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
428439
with:
429-
name: staged-site
430-
path: deploy-staging/
440+
name: staged-documentation-${{ needs.stage-and-check.outputs.branch_name }}
441+
path: stage/
431442

432443
# ========================================================================
433444
# APPLY STAGED ARTIFACTS TO GH-PAGES
434445
# ========================================================================
435446
# Strategy:
436-
# - Copy from deploy-staging/ to server/<branch_name>/
447+
# - Copy from stage/<branch_name>/ to server/<branch_name>/
437448
# - If version_name is set, ALSO copy to server/<version_name>/
438449
# - This allows the highest stable to live in both locations
439450
# ========================================================================
440451
- name: Apply staged artifacts to gh-pages
452+
id: apply
441453
run: |
442454
branch="${{ needs.stage-and-check.outputs.branch_name }}"
443455
additional="${{ needs.stage-and-check.outputs.additional_deployment }}"
444456
457+
changed=0
458+
459+
# Deploy to primary branch folder
445460
echo "Deploying to server/${branch}/"
446-
rm -rf "server/${branch}"
447-
cp -r deploy-staging "server/${branch}"
461+
if [ -d "stage/${branch}" ]; then
462+
rm -rf "server/${branch}"
463+
mkdir -p "server/${branch}"
464+
cp -r "stage/${branch}/"* "server/${branch}/" || true
465+
changed=1
466+
fi
448467
449468
# If this is the highest stable branch, also deploy to its versioned folder
450469
if [ -n "${additional}" ]; then
451470
echo "Also deploying to server/${additional}/ (additional versioned deployment)"
452471
rm -rf "server/${additional}"
453-
cp -r deploy-staging "server/${additional}"
472+
mkdir -p "server/${additional}"
473+
cp -r "stage/${branch}/"* "server/${additional}/" || true
474+
changed=1
454475
fi
455476
456477
# Clean up empty directories
@@ -460,19 +481,27 @@ jobs:
460481
echo "Final server/ structure:"
461482
find server -type d -maxdepth 2
462483
484+
# Check if there are actual changes
485+
if git diff --quiet HEAD; then
486+
echo "has_changes=false" >> $GITHUB_OUTPUT
487+
else
488+
echo "has_changes=true" >> $GITHUB_OUTPUT
489+
fi
490+
463491
- name: Create Pull Request for documentation deployment
464492
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
465493
id: cpr
494+
if: steps.apply.outputs.has_changes == 'true'
466495
with:
467496
token: ${{ secrets.COMMAND_BOT_PAT }}
468-
commit-message: "chore: deploy documentation for ${{ needs.stage-and-check.outputs.branch_name }}"
497+
commit-message: "chore: update documentation for ${{ needs.stage-and-check.outputs.branch_name }}"
469498
committer: nextcloud-command <nextcloud-command@users.noreply.github.com>
470499
author: nextcloud-command <nextcloud-command@users.noreply.github.com>
471500
signoff: true
472501
branch: "automated/deploy/documentation-${{ needs.stage-and-check.outputs.branch_name }}"
473502
base: gh-pages
474-
title: "Deploy documentation for ${{ needs.stage-and-check.outputs.branch_name }}"
475-
body: "Automated documentation deployment from branch ${{ github.ref_name }}"
503+
title: "Documentation update for ${{ needs.stage-and-check.outputs.branch_name }}"
504+
body: "Automated documentation update from branch ${{ github.ref_name }}"
476505
delete-branch: true
477506
labels: "automated, 3. to review"
478507

0 commit comments

Comments
 (0)