name: Deploy Vitepress docs to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches:
      - master

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: 'pages'
  cancel-in-progress: true

jobs:
  # Build job
  build-docs:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - uses: pnpm/action-setup@v2

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

      - name: Install Packages
        run: pnpm install --frozen-lockfile

      - name: Setup Pages
        uses: actions/configure-pages@v3

      - name: Run Build
        run: pnpm --filter mermaid run docs:build:vitepress

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1
        with:
          path: packages/mermaid/src/vitepress/.vitepress/dist

  # Deployment job
  deploy-docs:
    environment:
      name: github-pages
    runs-on: ubuntu-latest
    needs: build-docs
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
