45 lines
1.4 KiB
YAML
45 lines
1.4 KiB
YAML
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 }}
|
|
username: ${{ secrets.USERNAME }}
|
|
key: ${{ secrets.KEY }}
|
|
port: 2222 # 此端口主要用于 Action 自身建立连接
|
|
script: |
|
|
# 为 ssh 命令添加 -o StrictHostKeyChecking=no 选项
|
|
rsync -avz --delete -e 'ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' ./public/ ${{ secrets.USERNAME }}@${{ secrets.HOST }}:${{ secrets.TARGET }}
|
|
|
|
|