diff --git a/.DS_Store b/.DS_Store index 99de026..b520dd3 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000..a8c52b3 Binary files /dev/null and b/.github/.DS_Store differ diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b63714e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,43 @@ +name: Deploy Hugo to Own Server + +on: + push: + branches: + - main # 或者你的主分支名称,如 master + +jobs: + build-and-deploy: + name: Build and Deploy + runs-on: ubuntu-latest + steps: + # 1. 检出你的代码 + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true # 如果你的主题是 git submodule + fetch-depth: 0 # 获取所有 git 历史记录以支持 .Lastmod + + # 2. 设置 Hugo 环境 + - name: Setup Hugo + uses: peaceiris/actions-hugo@v2 + with: + hugo-version: 'latest' + # extended: true # 如果你使用 Hugo 扩展版 (Sass/SCSS) + + # 3. 构建 Hugo 网站 + - name: Build + run: hugo --minify + + # 4. 使用 rsync 部署到服务器 + # 这里使用了 'appleboy/ssh-action' 来执行 rsync 命令 + - name: Deploy with rsync + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} # 服务器 IP 或域名 + username: ${{ secrets.USERNAME }} # 服务器登录用户名 + key: ${{ secrets.KEY }} # SSH 私钥 + port: 2222 # SSH 端口,默认为 22 + script: | + # 使用 rsync 同步文件 + # -a: 归档模式, -v: 显示详细信息, -z: 压缩传输, --delete: 删除目标目录中源目录没有的文件 + rsync -avz --delete ./public/ ${{ secrets.USERNAME }}@${{ secrets.HOST }}:${{ secrets.TARGET }}