Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/build_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Docusaurus CI, Previews & Cleanup

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]

permissions:
contents: write
pages: write
id-token: write
pull-requests: write


jobs:
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- name: Install dependencies
run: npm ci

- name: Build Docusaurus site
run: npm run build

- name: Upload site build as artifact
uses: actions/upload-artifact@v4
with:
name: docusaurus-build
path: build

deploy:
if: github.event.action != 'closed'
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: docusaurus-build
path: build

- name: Determine deploy target
id: vars
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "branch=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.number }}/" >> $GITHUB_OUTPUT
else
echo "branch=gh-pages" >> $GITHUB_OUTPUT
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" >> $GITHUB_OUTPUT
fi

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
publish_branch: ${{ steps.vars.outputs.branch }}

- name: Comment preview link on PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: docusaurus-preview
message: |
🚀 **Docusaurus preview deployed!**
🔗 [View Preview](${{ steps.vars.outputs.url }})

cleanup:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest

steps:
- name: Delete preview branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: pr-${{ github.event.pull_request.number }}
soft_fail: true

Loading