@@ -380,64 +380,6 @@ jobs:
380380 path : stage/
381381 key : staged-docs-${{ github.sha }}
382382
383- # ========================================================================
384- # ASSEMBLE FULL NETLIFY PREVIEW CONTENT
385- # ========================================================================
386- # Combine the existing gh-pages content (all versions) with the newly
387- # built artifacts so the Netlify preview shows the complete site.
388- #
389- # Structure of the merged output (netlify-full/):
390- # netlify-full/
391- # ├── index.html ← generated version listing
392- # ├── latest/ ← from gh-pages or newly built
393- # ├── stable/ ← from gh-pages or newly built
394- # └── <N>/ ← older versions from gh-pages
395- # ========================================================================
396- - name : Assemble full documentation for Netlify preview
397- run : |
398- branch="${{ steps.branch.outputs.branch_name }}"
399- additional="${{ steps.branch.outputs.additional_deployment }}"
400-
401- mkdir -p netlify-full
402-
403- # Start with the full existing gh-pages content as the base
404- if [ -d "validation-context/server" ]; then
405- cp -r validation-context/server/. netlify-full/
406- fi
407-
408- # Override the current branch's folder with the freshly built content
409- rm -rf "netlify-full/${branch}"
410- cp -r "stage/${branch}" "netlify-full/${branch}"
411-
412- # For the highest stable branch, also override its versioned folder
413- if [ -n "${additional}" ]; then
414- rm -rf "netlify-full/${additional}"
415- cp -r "stage/${branch}" "netlify-full/${additional}"
416- fi
417-
418- # Generate a root index.html listing all version folders
419- echo '<!DOCTYPE html>' > netlify-full/index.html
420- echo '<html lang="en"><head>' >> netlify-full/index.html
421- echo '<meta charset="UTF-8">' >> netlify-full/index.html
422- echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">' >> netlify-full/index.html
423- echo '<title>Nextcloud Documentation Preview</title>' >> netlify-full/index.html
424- echo '</head><body>' >> netlify-full/index.html
425- echo '<h1>Nextcloud Documentation Preview</h1><ul>' >> netlify-full/index.html
426- for version_dir in netlify-full/*/; do
427- version="$(basename "$version_dir")"
428- echo "<li><a href=\"${version}/\">${version}</a></li>" >> netlify-full/index.html
429- done
430- echo '</ul></body></html>' >> netlify-full/index.html
431-
432- echo "Full Netlify deploy structure:"
433- find netlify-full -maxdepth 2 -type d
434-
435- - name : Cache full documentation for Netlify preview
436- uses : actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
437- with :
438- path : netlify-full/
439- key : netlify-full-docs-${{ github.sha }}
440-
441383 # ============================================================================
442384 # DEPLOY
443385 # ============================================================================
@@ -567,6 +509,9 @@ jobs:
567509 # This job deploys a per-PR documentation preview to Netlify.
568510 # It only runs on pull_request events (never on push/merge).
569511 #
512+ # Only the artifacts built for the current branch are deployed, with a simple
513+ # index.html listing the available manuals.
514+ #
570515 # The stable preview URL for PR #N is:
571516 # https://pr-<N>--<site>.netlify.app/
572517 #
@@ -585,26 +530,95 @@ jobs:
585530 pull-requests : write
586531
587532 steps :
588- - name : Restore full documentation from cache
533+ - name : Restore staged artifacts from cache
589534 uses : actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
590535 with :
591- path : netlify-full /
592- key : netlify-full -docs-${{ github.sha }}
536+ path : stage /
537+ key : staged -docs-${{ github.sha }}
593538 fail-on-cache-miss : true
594539
540+ - name : Generate index.html for preview
541+ run : |
542+ branch="${{ needs.stage-and-check.outputs.branch_name }}"
543+ preview_dir="stage/${branch}"
544+
545+ cat > "${preview_dir}/index.html" <<'EOF'
546+ <!DOCTYPE html>
547+ <html lang="en">
548+ <head>
549+ <meta charset="UTF-8">
550+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
551+ <title>Nextcloud Documentation Preview</title>
552+ </head>
553+ <body>
554+ <h1>Nextcloud Documentation Preview</h1>
555+ <ul>
556+ EOF
557+
558+ for manual_dir in "${preview_dir}"/*/; do
559+ [ -d "$manual_dir" ] || continue
560+ manual="$(basename "$manual_dir")"
561+ echo " <li><a href=\"${manual}/\">${manual}</a></li>" >> "${preview_dir}/index.html"
562+ done
563+
564+ cat >> "${preview_dir}/index.html" <<'EOF'
565+ </ul>
566+ </body>
567+ </html>
568+ EOF
569+
570+ - name : Install Netlify CLI
571+ run : npm install -g netlify-cli
572+
595573 - name : Deploy to Netlify
596- uses : nwtgck/actions-netlify@4cbaf4c08f1a7bfa537d6113472ef4424e4eb654 # v3.0
574+ id : netlify
575+ run : |
576+ branch="${{ needs.stage-and-check.outputs.branch_name }}"
577+ output=$(netlify deploy \
578+ --dir="stage/${branch}" \
579+ --site="${{ secrets.NETLIFY_SITE_ID }}" \
580+ --auth="${{ secrets.NETLIFY_AUTH_TOKEN }}" \
581+ --alias="pr-${{ github.event.number }}" \
582+ --message="Preview for PR #${{ github.event.number }}" \
583+ --json)
584+ deploy_url=$(echo "$output" | jq -r '.deploy_url // .url')
585+ if [ -z "$deploy_url" ] || [ "$deploy_url" = "null" ]; then
586+ echo "Failed to get deploy URL from Netlify output:" >&2
587+ echo "$output" >&2
588+ exit 1
589+ fi
590+ echo "deploy_url=${deploy_url}" >> $GITHUB_OUTPUT
591+
592+ - name : Comment preview URL on PR
593+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
597594 with :
598- publish-dir : ' ./netlify-full'
599- production-deploy : false
600- github-token : ${{ secrets.GITHUB_TOKEN }}
601- deploy-message : " Preview for PR #${{ github.event.number }}"
602- alias : pr-${{ github.event.number }}
603- enable-pull-request-comment : true
604- enable-commit-comment : false
605- env :
606- NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
607- NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
595+ script : |
596+ const deployUrl = '${{ steps.netlify.outputs.deploy_url }}';
597+ const marker = '<!-- netlify-preview -->';
598+ const body = `${marker}\n:rocket: **Netlify preview deployed:** ${deployUrl}`;
599+
600+ const { data: comments } = await github.rest.issues.listComments({
601+ owner: context.repo.owner,
602+ repo: context.repo.repo,
603+ issue_number: context.issue.number,
604+ });
605+
606+ const existing = comments.find(c => c.body.includes(marker));
607+ if (existing) {
608+ await github.rest.issues.updateComment({
609+ owner: context.repo.owner,
610+ repo: context.repo.repo,
611+ comment_id: existing.id,
612+ body,
613+ });
614+ } else {
615+ await github.rest.issues.createComment({
616+ owner: context.repo.owner,
617+ repo: context.repo.repo,
618+ issue_number: context.issue.number,
619+ body,
620+ });
621+ }
608622
609623 summary :
610624 needs : [build, stage-and-check, deploy, netlify-preview]
0 commit comments