Skip to content

Commit a83a58a

Browse files
committed
Add GitHub Actions workflow for deployment
1 parent b7678d9 commit a83a58a

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Deploy Hugo site to Pages
2+
3+
on:
4+
# Runs on pushes targeting the default branch (e.g., main)
5+
push:
6+
branches:
7+
- main # 或者你的默认源码分支名,如 master
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
# Default to bash
25+
defaults:
26+
run:
27+
shell: bash
28+
29+
jobs:
30+
# Build job
31+
build:
32+
runs-on: ubuntu-latest
33+
env:
34+
HUGO_VERSION: 0.146.7 # 指定你希望使用的 Hugo 版本 (建议使用你本地的版本或更新)
35+
steps:
36+
- name: Install Hugo CLI
37+
run: |
38+
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
39+
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
40+
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
with:
44+
submodules: recursive # Fetch Hugo themes (true OR recursive)
45+
fetch-depth: 0 # Fetch all history for .GitInfo, .Lastmod, etc.
46+
47+
- name: Setup Pages
48+
id: pages
49+
uses: actions/configure-pages@v4 # 使用官方的 configure-pages action
50+
51+
- name: Build with Hugo
52+
env:
53+
# For maximum backward compatibility with Hugo modules
54+
HUGO_ENVIRONMENT: production
55+
HUGO_ENV: production
56+
# 设置 baseURL 为 GitHub Pages 的 URL
57+
HUGO_BASEURL: ${{ steps.pages.outputs.base_url }}
58+
run: |
59+
hugo --gc --minify --baseURL "${{ steps.pages.outputs.base_url }}"
60+
# --gc: 清理旧文件
61+
# --minify: 压缩输出文件
62+
63+
- name: Upload artifact
64+
uses: actions/upload-pages-artifact@v3 # 使用官方的 upload-pages-artifact action
65+
with:
66+
# Upload entire directory by default
67+
path: ./public
68+
69+
# Deployment job
70+
deploy:
71+
environment:
72+
name: github-pages
73+
url: ${{ steps.deployment.outputs.page_url }}
74+
runs-on: ubuntu-latest
75+
needs: build
76+
steps:
77+
- name: Deploy to GitHub Pages
78+
id: deployment
79+
uses: actions/deploy-pages@v4 # 使用官方的 deploy-pages action

0 commit comments

Comments
 (0)