name: Deploy V2 Site

on:
  push:
    branches: [2.x]
    paths:
      - 'docs/**'

  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@v2
        with:
          ref: '2.x'

      - name: Set Node Version
        uses: actions/setup-node@v1
        with:
          node-version: '14.x'

      - name: Install dependencies
        uses: bahmutov/npm-install@v1

      - name: Build Site
        run: npx --no-install vant-cli build-site

      - name: Deploy 🚀
        uses: JamesIves/github-pages-deploy-action@v4.4.1
        with:
          branch: gh-pages
          folder: site
          target-folder: v2

      - name: Deploy for GitHub 🚀
        uses: JamesIves/github-pages-deploy-action@v4.4.1
        with:
          branch: main
          folder: site
          token: ${{ secrets.VANT_UI_TOKEN }}
          repository-name: vant-ui/vant-ui.github.io
          target-folder: vant/v2
