feat: DSPX-2316 quickstart guide #2
Workflow file for this run
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 | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| paths: | |
| - 'docs/**' | |
| - 'blog/**' | |
| - 'src/**' | |
| - 'static/**' | |
| - 'code_samples/**' | |
| - 'specs/**' | |
| - 'specs-processed/**' | |
| - 'docusaurus.config.ts' | |
| - 'docusaurus-lib-list-remote.js' | |
| - 'openapi-generated-clients.ts' | |
| - 'sidebars.js' | |
| - 'package.json' | |
| - 'package-lock.json' | |
| - 'babel.config.js' | |
| - 'tsconfig.json' | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR number to deploy preview for' | |
| required: true | |
| type: number | |
| jobs: | |
| deploy-preview: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Get PR number | |
| id: pr | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/head', inputs.pr_number) || github.ref }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build website with base URL | |
| run: npm run build | |
| env: | |
| BASE_URL: /pr-${{ steps.pr.outputs.number }}/ | |
| - name: Remove CNAME file from build (conflicts with subdirectory deployment) | |
| run: rm -f build/CNAME | |
| - name: Checkout gh-pages branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: gh-pages | |
| path: gh-pages | |
| - name: Deploy to PR subdirectory | |
| run: | | |
| # Create PR directory if it doesn't exist | |
| mkdir -p gh-pages/pr-${{ steps.pr.outputs.number }} | |
| # Remove old content and copy new build | |
| rm -rf gh-pages/pr-${{ steps.pr.outputs.number }}/* | |
| cp -r build/* gh-pages/pr-${{ steps.pr.outputs.number }}/ | |
| # Configure git | |
| cd gh-pages | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Commit and push | |
| git add . | |
| git commit -m "Deploy preview for PR #${{ steps.pr.outputs.number }}" || echo "No changes to commit" | |
| git push origin gh-pages | |
| - name: Comment PR with preview URL | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = ${{ steps.pr.outputs.number }}; | |
| const repo = context.repo; | |
| // Get the GitHub Pages URL (handles custom domains) | |
| let pagesUrl = 'opentdf.io'; // Custom CNAME configured for this repo | |
| const previewUrl = `https://${pagesUrl}/pr-${prNumber}/`; | |
| // Find existing preview comment | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: repo.owner, | |
| repo: repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('Preview deployment') | |
| ); | |
| const commentBody = `## 🚀 Preview deployment | |
| Your preview is ready! | |
| **Preview URL:** ${previewUrl} | |
| *Updated: ${new Date().toUTCString()}*`; | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| owner: repo.owner, | |
| repo: repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody, | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| owner: repo.owner, | |
| repo: repo.repo, | |
| issue_number: prNumber, | |
| body: commentBody, | |
| }); | |
| } |