|
| 1 | +name: Deploy Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + # Rebuild docs when content, config, or screenshots spec changes |
| 8 | + - 'docs/**' |
| 9 | + - 'tests/screenshots/**' |
| 10 | + - '.github/workflows/deploy-docs.yml' |
| 11 | + # Also rebuild whenever the screenshots workflow finishes successfully |
| 12 | + # so the docs always show the latest captures. |
| 13 | + workflow_run: |
| 14 | + workflows: ['Generate Screenshots'] |
| 15 | + types: [completed] |
| 16 | + branches: [main] |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: deploy-docs |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-and-deploy: |
| 25 | + name: Build Starlight & deploy to gh-pages |
| 26 | + # Skip if triggered by a failed screenshots run |
| 27 | + if: > |
| 28 | + github.event_name != 'workflow_run' || |
| 29 | + github.event.workflow_run.conclusion == 'success' |
| 30 | + runs-on: ubuntu-latest |
| 31 | + timeout-minutes: 20 |
| 32 | + |
| 33 | + permissions: |
| 34 | + contents: write # needed by peaceiris/actions-gh-pages |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + # ── Screenshots ──────────────────────────────────────────────────────── |
| 41 | + - name: Download screenshots artifact (from screenshots workflow) |
| 42 | + if: github.event_name == 'workflow_run' |
| 43 | + uses: actions/download-artifact@v4 |
| 44 | + with: |
| 45 | + name: app-screenshots |
| 46 | + # Artifacts belong to the triggering workflow run |
| 47 | + run-id: ${{ github.event.workflow_run.id }} |
| 48 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + path: screenshots/ |
| 50 | + continue-on-error: true # Don't fail if no artifact yet |
| 51 | + |
| 52 | + - name: Download latest screenshots artifact (direct push / manual) |
| 53 | + if: github.event_name != 'workflow_run' |
| 54 | + uses: dawidd6/action-download-artifact@v9 |
| 55 | + with: |
| 56 | + workflow: screenshots.yml |
| 57 | + branch: main |
| 58 | + name: app-screenshots |
| 59 | + path: screenshots/ |
| 60 | + if_no_artifact_found: warn # First deploy may have no artifact |
| 61 | + continue-on-error: true |
| 62 | + |
| 63 | + - name: Copy screenshots into docs public directory |
| 64 | + run: | |
| 65 | + if [ -d screenshots ] && [ "$(ls -A screenshots)" ]; then |
| 66 | + mkdir -p docs/public/screenshots |
| 67 | + cp -r screenshots/. docs/public/screenshots/ |
| 68 | + echo "✓ Copied $(ls screenshots | wc -l | tr -d ' ') screenshots" |
| 69 | + else |
| 70 | + echo "⚠ No screenshots found — docs will build without them" |
| 71 | + mkdir -p docs/public/screenshots |
| 72 | + fi |
| 73 | +
|
| 74 | + # ── Docs build ───────────────────────────────────────────────────────── |
| 75 | + - name: Setup pnpm |
| 76 | + uses: pnpm/action-setup@v4 |
| 77 | + with: |
| 78 | + version: 10 |
| 79 | + |
| 80 | + - name: Setup Node.js |
| 81 | + uses: actions/setup-node@v4 |
| 82 | + with: |
| 83 | + node-version: '20' |
| 84 | + cache: 'pnpm' |
| 85 | + cache-dependency-path: docs/pnpm-lock.yaml |
| 86 | + |
| 87 | + - name: Install docs dependencies |
| 88 | + working-directory: docs |
| 89 | + run: pnpm install --frozen-lockfile |
| 90 | + |
| 91 | + - name: Build Starlight docs |
| 92 | + working-directory: docs |
| 93 | + run: pnpm build |
| 94 | + |
| 95 | + # ── Preserve update.json from existing gh-pages ─────────────────────── |
| 96 | + # The release workflow (release.yml) pushes update.json to gh-pages for |
| 97 | + # Tauri's auto-updater. We include it in this deploy so it isn't clobbered. |
| 98 | + - name: Preserve update.json |
| 99 | + run: | |
| 100 | + curl -sf \ |
| 101 | + "https://raw.githubusercontent.com/${{ github.repository }}/gh-pages/update.json" \ |
| 102 | + -o docs/dist/update.json \ |
| 103 | + || echo '{}' > docs/dist/update.json |
| 104 | + echo "✓ update.json preserved" |
| 105 | +
|
| 106 | + # ── Deploy ────────────────────────────────────────────────────────────── |
| 107 | + - name: Deploy to gh-pages |
| 108 | + uses: peaceiris/actions-gh-pages@v4 |
| 109 | + with: |
| 110 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + publish_dir: ./docs/dist |
| 112 | + publish_branch: gh-pages |
| 113 | + # Single orphan commit keeps gh-pages history clean. |
| 114 | + # update.json is included in docs/dist above. |
| 115 | + force_orphan: true |
| 116 | + commit_message: 'docs: deploy ${{ github.sha }}' |
| 117 | + user_name: 'github-actions[bot]' |
| 118 | + user_email: 'github-actions[bot]@users.noreply.github.com' |
0 commit comments