1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| name: Deploy Hugo to GitHub Pages
on:
push: # Trigger condition: push code to master branch
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest # Use Ubuntu environment
steps:
# 1. Check out repository code (recursively pull theme submodule)
- uses: actions/checkout@v4
with:
submodules: true
# 2. Install Hugo (use extended version, supports SASS)
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest' # Or specify version (e.g., '0.147.2')
extended: true
# 3. Cache dependencies (speed up subsequent builds)
- uses: actions/cache@v3
with:
path: |
resources/_gen
public
key: ${{ runner.os }}-hugo-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugo-
# 4. Build Hugo site (enable compression)
- name: Build Hugo site
run: hugo --minify
# 5. Deploy to GitHub Pages (automatically push public directory to gh-pages branch)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # GitHub automatically provided Token (no manual creation needed)
publish_dir: ./public # Point to Hugo generated static files directory
force_orphan: true # Force create new commit (avoid branch history confusion)
|