name: Build and Deploy Qingshuige

on:
  push:
    branches:
      - main

jobs:
  build-deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout source
        run: |
          git clone https://gitea.qingshuige.ink/qingshuige-authors/qingshuige-hugo.git repo
          chmod -R 777 .
          cd repo
          git checkout main

      - name: Test Hugo
        run: |
          hugo version

      - name: Build Hugo site
        run: |
          cd repo
          ls -R
          hugo --minify

      - name: Deploy to local directory
        run: |
          cd repo
          TARGET_DIR=/www/wwwroot/qingshuige.ink
          sudo -n mkdir -p $TARGET_DIR
          sudo -n rsync --exclude='.user.ini' -av --delete public/ $TARGET_DIR/
