[CORE-376] Limit Single Response Per User #103
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy PR Preview Docs | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - closed | |
| concurrency: | |
| group: pr-preview-docs-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy-preview: | |
| name: Build and deploy preview docs | |
| if: github.event.pull_request.head.repo.fork == false && github.event.action != 'closed' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v5 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: "24" | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build OpenAPI | |
| run: pnpm compile:openapi | |
| - name: Copy OpenAPI spec | |
| run: | | |
| mkdir -p website/tsp-output/schema | |
| cp tsp-output/schema/openapi.1.0.0.yaml website/openapi.1.0.0.yaml | |
| - name: Build Redocly and Typedoc | |
| run: | | |
| pnpm build:redocly | |
| pnpm build:sdk | |
| pnpm compile:sdk | |
| pnpm build:typedoc | |
| - name: Deploy preview to gh-pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_branch: gh-pages | |
| publish_dir: ./website | |
| destination_dir: preview-${{ github.event.pull_request.number }} | |
| keep_files: true | |
| - name: Comment preview URL on PR | |
| uses: actions/github-script@v8 | |
| env: | |
| PREVIEW_BASE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/preview-${{ github.event.pull_request.number }}/ | |
| with: | |
| script: | | |
| const marker = "<!-- pr-preview-docs -->"; | |
| const previewBaseUrl = process.env.PREVIEW_BASE_URL; | |
| const redoclyUrl = `${previewBaseUrl}redocly/`; | |
| const swaggerUrl = `${previewBaseUrl}swagger/`; | |
| const sdkUrl = `${previewBaseUrl}sdk/`; | |
| const updatedAt = new Date().toISOString(); | |
| const body = `${marker} | |
| ## ✅ PR Preview Deploy Success | |
| <table> | |
| <thead> | |
| <tr> | |
| <th>Target</th> | |
| <th>Status</th> | |
| <th>Preview</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr> | |
| <td>Scalar</td> | |
| <td><img alt="ready" src="https://img.shields.io/badge/Preview-Ready-0ea5e9"></td> | |
| <td><a href="${previewBaseUrl}" target="_blank">Open Scalar</a></td> | |
| </tr> | |
| <tr> | |
| <td>Redocly API Docs</td> | |
| <td><img alt="success" src="https://img.shields.io/badge/Deployed-Success-22c55e"></td> | |
| <td><a href="${redoclyUrl}" target="_blank">Open Redocly</a></td> | |
| </tr> | |
| <tr> | |
| <td>Swagger UI</td> | |
| <td><img alt="ready" src="https://img.shields.io/badge/Preview-Ready-0ea5e9"></td> | |
| <td><a href="${swaggerUrl}" target="_blank">Open Swagger</a></td> | |
| </tr> | |
| <tr> | |
| <td>SDK TypeDoc</td> | |
| <td><img alt="ready" src="https://img.shields.io/badge/API-Synced-f59e0b"></td> | |
| <td><a href="${sdkUrl}" target="_blank">Open SDK Docs</a></td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <sub>PR #${context.payload.pull_request.number} · Updated at ${updatedAt}</sub>`; | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.payload.pull_request.number; | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner, | |
| repo, | |
| issue_number, | |
| per_page: 100, | |
| }); | |
| const botComment = comments.find( | |
| (comment) => comment.user.type === "Bot" && comment.body.includes(marker), | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: botComment.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } | |
| cleanup-preview: | |
| name: Remove preview docs on PR close | |
| if: github.event.pull_request.head.repo.fork == false && github.event.action == 'closed' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout gh-pages branch | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: gh-pages | |
| fetch-depth: 0 | |
| - name: Remove preview directory | |
| run: | | |
| target="preview-${{ github.event.pull_request.number }}" | |
| if [ -d "$target" ]; then | |
| rm -rf "$target" | |
| git add -A | |
| if ! git diff --cached --quiet; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git commit -m "chore: remove preview for PR #${{ github.event.pull_request.number }}" | |
| git push origin gh-pages | |
| fi | |
| fi | |
| - name: Comment cleanup result | |
| uses: actions/github-script@v8 | |
| env: | |
| PREVIEW_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/preview-${{ github.event.pull_request.number }}/ | |
| with: | |
| script: | | |
| const marker = "<!-- pr-preview-docs -->"; | |
| const body = `${marker}\n🧹 PR is closed. Preview docs removed.\n\n🔗 ${process.env.PREVIEW_URL}`; | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.payload.pull_request.number; | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner, | |
| repo, | |
| issue_number, | |
| per_page: 100, | |
| }); | |
| const botComment = comments.find( | |
| (comment) => comment.user.type === "Bot" && comment.body.includes(marker), | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: botComment.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } |