Ops Lab 2024-02-12 1 分钟
用 GitHub Actions 自动部署 Hugo
#CI/CD
#GITHUB ACTIONS
#HUGO
借助 GitHub Actions,我们可以在推送代码时自动执行 hugo 构建并将 public/ 发布到 Pages 或对象存储。
工作流示例
name: Deploy Hugo
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.119.0'
- run: hugo --minify
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
小贴士
- 使用 Hugo Extended 版本以支持 SCSS。
- 构建产物最好开启缓存,减少流水线时间。
- 对于多语言站点,可在
hugo命令中加入--gc清理缓存。