add github deploy file
This commit is contained in:
BIN
.github/.DS_Store
vendored
Normal file
BIN
.github/.DS_Store
vendored
Normal file
Binary file not shown.
43
.github/workflows/deploy.yml
vendored
Normal file
43
.github/workflows/deploy.yml
vendored
Normal file
@@ -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 }}
|
||||
Reference in New Issue
Block a user