Skip to content

CI: consolidate docs deployment workflows and add PR previews #3

CI: consolidate docs deployment workflows and add PR previews

CI: consolidate docs deployment workflows and add PR previews #3

Workflow file for this run

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}`
});