name: Docs and Script Auto Deploy
on:
  push:
    branches:
      - main
    paths:
      - 'docs/**'
      - 'ext/**'

jobs:
  build:
    name: Deploy docs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout master
        uses: actions/checkout@v3

      - name: Deploy docs to GitHub Pages
        uses: jenkey2011/vuepress-deploy@master
        env:
          ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BUILD_SCRIPT: yarn && yarn docs:build
          BUILD_DIR: docs/.vuepress/dist/
      - name: Copy deployment to current folder
        run: |
          cp -r "${GITHUB_WORKSPACE}/docs/.vuepress/dist" "./deploy"
      - name: Deploy to Zhamao Server
        uses: easingthemes/ssh-deploy@main
        env:
          SSH_PRIVATE_KEY: ${{ secrets.ZHAMAO_XIN_PRIVATE_KEY }}
          ARGS: "-rltgoDzvO --delete"
          SOURCE: "deploy/"
          REMOTE_HOST: ${{ secrets.ZHAMAO_XIN_HOST }}
          REMOTE_USER: ${{ secrets.ZHAMAO_XIN_USER }}
          TARGET: ${{ secrets.FRAMEWORK_ZHAMAO_XIN_TARGET }}
      - name: deploy script file
        uses: wlixcc/SFTP-Deploy-Action@v1.2
        with:
          username: ${{ secrets.ZHAMAO_XIN_USER }}
          server: ${{ secrets.ZHAMAO_XIN_HOST }}
          ssh_private_key: ${{ secrets.ZHAMAO_XIN_PRIVATE_KEY }}
          local_path: './ext/go.sh'
          remote_path: ${{ secrets.ZHAMAO_XIN_MAIN_TARGET }}
      - name: deploy script file
        uses: wlixcc/SFTP-Deploy-Action@v1.2
        with:
          username: ${{ secrets.ZHAMAO_XIN_USER }}
          server: ${{ secrets.ZHAMAO_XIN_HOST }}
          ssh_private_key: ${{ secrets.ZHAMAO_XIN_PRIVATE_KEY }}
          local_path: './ext/v3.sh'
          remote_path: ${{ secrets.ZHAMAO_XIN_MAIN_TARGET }}
