Skip to content

Commit f477c06

Browse files
Copilotskjnldsv
andcommitted
feat: add netlify-preview job to sphinxbuild workflow
Agent-Logs-Url: https://github.com/nextcloud/documentation/sessions/12ab3238-1214-4ff1-b0cf-67836a1abc12 Co-authored-by: skjnldsv <14975046+skjnldsv@users.noreply.github.com>
1 parent 79db8a5 commit f477c06

1 file changed

Lines changed: 82 additions & 2 deletions

File tree

.github/workflows/sphinxbuild.yml

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,86 @@ jobs:
502502
env:
503503
GH_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}
504504

505+
# ============================================================================
506+
# NETLIFY PREVIEW
507+
# ============================================================================
508+
# This job deploys a per-PR documentation preview to Netlify.
509+
# It only runs on pull_request events (never on push/merge).
510+
#
511+
# The stable preview URL for PR #N is:
512+
# https://pr-<N>--<site>.netlify.app/
513+
#
514+
# Required repository secrets:
515+
# NETLIFY_AUTH_TOKEN – Netlify personal access token
516+
# NETLIFY_SITE_ID – ID of the target Netlify site
517+
# ============================================================================
518+
netlify-preview:
519+
name: Deploy preview to Netlify
520+
needs: stage-and-check
521+
if: github.event_name == 'pull_request'
522+
runs-on: ubuntu-latest
523+
524+
permissions:
525+
contents: read
526+
pull-requests: write
527+
528+
steps:
529+
- name: Restore staged artifacts from cache
530+
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
531+
with:
532+
path: stage/
533+
key: staged-docs-${{ github.sha }}
534+
fail-on-cache-miss: true
535+
536+
- name: Assemble Netlify deploy directory
537+
run: |
538+
branch="${{ needs.stage-and-check.outputs.branch_name }}"
539+
mkdir -p netlify-deploy
540+
541+
# Flatten stage/<branch>/<manual>/ into netlify-deploy/<manual>/
542+
for manual_dir in "stage/${branch}/"/*/; do
543+
if [ -d "$manual_dir" ]; then
544+
manual_name="$(basename "$manual_dir")"
545+
cp -r "$manual_dir" "netlify-deploy/${manual_name}"
546+
fi
547+
done
548+
549+
# Create a root index linking to each manual
550+
cat > netlify-deploy/index.html << 'ENDHTML'
551+
<!DOCTYPE html>
552+
<html lang="en">
553+
<head>
554+
<meta charset="UTF-8">
555+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
556+
<title>Nextcloud Documentation Preview</title>
557+
</head>
558+
<body>
559+
<h1>Nextcloud Documentation Preview</h1>
560+
<ul>
561+
<li><a href="user_manual/">User Manual</a></li>
562+
<li><a href="admin_manual/">Administration Manual</a></li>
563+
<li><a href="developer_manual/">Developer Manual</a></li>
564+
</ul>
565+
</body>
566+
</html>
567+
ENDHTML
568+
569+
- name: Deploy to Netlify
570+
uses: nwtgck/actions-netlify@4cbaf4c08f1a7bfa537d6113472ef4424e4eb654 # v3.0
571+
with:
572+
publish-dir: './netlify-deploy'
573+
production-deploy: false
574+
github-token: ${{ secrets.GITHUB_TOKEN }}
575+
deploy-message: "Preview for PR #${{ github.event.number }}"
576+
alias: pr-${{ github.event.number }}
577+
enable-pull-request-comment: true
578+
enable-commit-comment: false
579+
env:
580+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
581+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
582+
505583
summary:
506-
needs: [build, stage-and-check, deploy]
584+
needs: [build, stage-and-check, deploy, netlify-preview]
507585
runs-on: ubuntu-latest-low
508586
if: always()
509587

@@ -519,8 +597,10 @@ jobs:
519597
then
520598
echo "This workflow ran for a pull request. We need build and stage-and-check to succeed, but deploy will be skipped"
521599
if ${{ needs.build.result != 'success' || needs.stage-and-check.result != 'success' || needs.deploy.result != 'skipped' }}; then exit 1; fi
600+
if ${{ needs.netlify-preview.result != 'success' && needs.netlify-preview.result != 'skipped' }}; then exit 1; fi
522601
else
523602
echo "This workflow ran for a push. We need all jobs to succeed, including deploy"
524603
if ${{ needs.build.result != 'success' || needs.stage-and-check.result != 'success' || needs.deploy.result != 'success' }}; then exit 1; fi
604+
if ${{ needs.netlify-preview.result != 'skipped' }}; then exit 1; fi
525605
fi
526-
606+

0 commit comments

Comments
 (0)