Skip to content

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

CI: consolidate docs deployment workflows and add PR previews

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

Workflow file for this run

name: Publish Docs
on:
push:
branches: [master]
pull_request:
types:
- opened
- reopened
- synchronize
- closed
permissions:
contents: write
pull-requests: write
concurrency: preview-${{ github.ref }}
env:
PREVIEW_BRANCH: gh-pages
jobs:
deploy-preview:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Calculate BASE_URL
run: |
if [[ "${{ github.event.repository.name }}" == "${{ github.repository_owner }}.github.io" ]]; then
echo "BASE_URL=/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV
else
echo "BASE_URL=/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.pull_request.number }}/" >> $GITHUB_ENV
fi
- name: Install and Build
run: npm ci && npm run build
env:
BASE_URL: ${{ env.BASE_URL }}
- name: Deploy Preview
uses: rossjrw/pr-preview-action@v1
id: preview-step
with:
source-dir: build/
preview-branch: ${{ env.PREVIEW_BRANCH }}
comment: false
- name: Comment Preview URL (Success)
uses: marocchino/sticky-pull-request-comment@v2
if: steps.preview-step.outputs.deployment-action == 'deploy' && env.deployment_status == 'success'
with:
header: pr-preview
message: |
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
:---:
| <p></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
| <h6>Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}. <br> Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete. <br><br> </h6>
- name: Comment Preview Removed
uses: marocchino/sticky-pull-request-comment@v2
if: steps.preview-step.outputs.deployment-action == 'remove' && env.deployment_status == 'success'
with:
header: pr-preview
message: |
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
:---:
Preview removed because the pull request was closed.
${{ steps.preview-step.outputs.action-start-time }}
build-production:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: site
path: build/
deploy-production:
runs-on: ubuntu-latest
needs: build-production
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: site
path: site
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: site
clean-exclude: pr-preview