|
| 1 | +name: Docs Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pages: write |
| 12 | + id-token: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: docs-${{ github.event.pull_request.number || github.ref }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Enable Corepack |
| 27 | + run: corepack enable |
| 28 | + |
| 29 | + - name: Setup PNPM |
| 30 | + uses: pnpm/action-setup@v4 |
| 31 | + with: |
| 32 | + version: 10.7.0 |
| 33 | + |
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: 20 |
| 38 | + cache: pnpm |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: pnpm install --frozen-lockfile |
| 42 | + |
| 43 | + - name: Setup Pages |
| 44 | + uses: actions/configure-pages@v5 |
| 45 | + |
| 46 | + - name: Build docs |
| 47 | + run: pnpm docs:build |
| 48 | + |
| 49 | + - name: Upload artifact |
| 50 | + uses: actions/upload-pages-artifact@v3 |
| 51 | + with: |
| 52 | + path: packages/docs/dist |
| 53 | + |
| 54 | + deploy: |
| 55 | + needs: build |
| 56 | + runs-on: ubuntu-latest |
| 57 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 58 | + environment: |
| 59 | + name: github-pages |
| 60 | + url: ${{ steps.deployment.outputs.page_url }} |
| 61 | + outputs: |
| 62 | + page_url: ${{ steps.deployment.outputs.page_url }} |
| 63 | + steps: |
| 64 | + - name: Deploy to GitHub Pages |
| 65 | + id: deployment |
| 66 | + uses: actions/deploy-pages@v4 |
| 67 | + with: |
| 68 | + preview: ${{ github.event_name == 'pull_request' }} |
| 69 | + |
| 70 | + comment: |
| 71 | + needs: deploy |
| 72 | + runs-on: ubuntu-latest |
| 73 | + if: github.event_name == 'pull_request' && needs.deploy.outputs.page_url != '' |
| 74 | + steps: |
| 75 | + - name: Share preview link |
| 76 | + uses: actions/github-script@v7 |
| 77 | + env: |
| 78 | + PAGE_URL: ${{ needs.deploy.outputs.page_url }} |
| 79 | + SHA: ${{ github.event.pull_request.head.sha }} |
| 80 | + with: |
| 81 | + script: | |
| 82 | + const core = require('@actions/core'); |
| 83 | + const pageUrl = process.env.PAGE_URL; |
| 84 | + if (!pageUrl) { |
| 85 | + core.warning('No preview URL available, skipping comment.'); |
| 86 | + return; |
| 87 | + } |
| 88 | +
|
| 89 | + const marker = '<!-- docs-preview -->'; |
| 90 | + const sha = process.env.SHA || context.payload.pull_request.head.sha || context.sha; |
| 91 | + const shortSha = sha ? sha.slice(0, 7) : 'unknown'; |
| 92 | + const body = `${marker}\n🚀 Docs preview ready: ${pageUrl}\n\nLatest commit: \`${shortSha}\``; |
| 93 | +
|
| 94 | + const { owner, repo } = context.repo; |
| 95 | + const issue_number = context.issue.number; |
| 96 | +
|
| 97 | + const existingComments = await github.rest.issues.listComments({ |
| 98 | + owner, |
| 99 | + repo, |
| 100 | + issue_number, |
| 101 | + per_page: 100, |
| 102 | + }); |
| 103 | +
|
| 104 | + const existing = existingComments.data.find((comment) => comment.body && comment.body.includes(marker)); |
| 105 | +
|
| 106 | + if (existing) { |
| 107 | + await github.rest.issues.updateComment({ |
| 108 | + owner, |
| 109 | + repo, |
| 110 | + comment_id: existing.id, |
| 111 | + body, |
| 112 | + }); |
| 113 | + } else { |
| 114 | + await github.rest.issues.createComment({ |
| 115 | + owner, |
| 116 | + repo, |
| 117 | + issue_number, |
| 118 | + body, |
| 119 | + }); |
| 120 | + } |
0 commit comments