name: Deploy site to Pages
on:
  push:
    branches: [ main ]
  workflow_dispatch:
# 设置 GITHUB_TOKEN 的权限，以允许部署到 GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write
# 只允许同时进行一次部署
concurrency:
  group: pages
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: latest
          run_install: true
      - name: Setup Node
        uses: actions/setup-node@v6
        with:
          node-version: lts/*
          cache: pnpm
      - name: Setup Pages
        uses: actions/configure-pages@v5
      - name: Build with VitePress
        run: pnpm docs:build
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v4
        with:
          path: .vitepress/dist
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
