CI: consolidate docs deployment workflows and add PR previews #3
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: Publish Docs | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| branches: [master] | |
| types: [opened, synchronize, reopened, closed] | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR number to deploy preview for' | |
| required: true | |
| type: number | |
| run_id: | |
| description: 'Run ID of the build workflow (from the PR checks)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| statuses: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| if: github.event_name != 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout ποΈ | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install and Build π§ | |
| run: | | |
| npm ci | |
| npm run build | |
| - name: Upload PR Preview Artifact π¦ | |
| if: github.event_name == 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pr-preview-${{ github.event.pull_request.number }} | |
| path: build/ | |
| retention-days: 7 | |
| - name: Deploy to GitHub Pages π | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| branch: gh-pages | |
| folder: build | |
| deploy-preview: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout ποΈ | |
| uses: actions/checkout@v4 | |
| - name: Download PR Preview Artifact π₯ | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: pr-preview-${{ inputs.pr_number }} | |
| path: preview-build/ | |
| run-id: ${{ inputs.run_id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Deploy Preview π | |
| uses: rossjrw/pr-preview-action@v1 | |
| with: | |
| source-dir: ./preview-build/ | |
| preview-branch: gh-pages-pr-previews | |
| umbrella-dir: pr-preview | |
| action: deploy | |
| - name: Comment PR with Preview URL π¬ | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = ${{ inputs.pr_number }}; | |
| const previewUrl = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${prNumber}/`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: `π Preview deployed! View it at: ${previewUrl}` | |
| }); |