+ 部署代码
name: Deploy Hugo Site

on:
  push:
    branches:
      - main

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

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          submodules: true  # 启用 Git 子模块

      - name: Set up Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.111.3'
          extended: true  # 开启 Hugo Extended 版 (支持 SCSS/SASS)
			
			- name: Build Hugo site
				run: hugo --minify -F --cleanDestinationDir

      - name: Deploy to remote server
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          SSH_IP: ${{ secrets.SSH_IP }}
          SSH_PORT: ${{ secrets.SSH_PORT }}
        run: |
          set -x  # Enable debugging
          mkdir -p ~/.ssh
          echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          # Add debugging information to help diagnose ssh-keyscan issues
          ssh-keyscan -p $SSH_PORT $SSH_IP || true  # Continue even if ssh-keyscan fails
          ssh-keyscan -p $SSH_PORT $SSH_IP >> ~/.ssh/known_hosts
          ssh -o StrictHostKeyChecking=no -p $SSH_PORT deployuser@$SSH_IP "mkdir -p /var/www/public"
          rsync -avz -e "ssh -p $SSH_PORT" ./public/ deployuser@$SSH_IP:/var/www/public

参考链接

1.https://kitin.cn/archives/hugo_actions/