-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (67 loc) · 2.71 KB
/
Copy pathdeploy.yml
File metadata and controls
78 lines (67 loc) · 2.71 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# .github/workflows/gh-pages.yml
name: Deploy Hugo site to Pages
on:
# 在推送到默认分支(通常是 main 或 master)时运行
push:
branches:
- main # 根据你的默认分支名称修改 (例如 master)
# 允许你从 Actions 标签页手动运行此工作流程
workflow_dispatch:
# 设置 GITHUB_TOKEN 的权限以允许部署到 GitHub Pages
permissions:
contents: read # 需要读取仓库内容
pages: write # 需要写入 GitHub Pages
id-token: write # 需要 OIDC token 认证
# 只允许一个并发部署,跳过在进行中的运行和最新排队的运行之间的排队运行。
# 但是,不要取消进行中的运行,因为我们希望允许这些生产部署完成。
concurrency:
group: "pages"
cancel-in-progress: false
# 默认使用 bash
defaults:
run:
shell: bash
jobs:
# 构建任务
build:
runs-on: ubuntu-latest # 使用最新的 Ubuntu 运行器
env:
HUGO_VERSION: 0.147.3 # 指定你想要使用的 Hugo 版本 (建议使用最新稳定版)
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Checkout repository
uses: actions/checkout@v4 #检出你的仓库代码
with:
submodules: recursive # 如果你的主题是作为 submodule 添加的,设置为 true 或 recursive
fetch-depth: 0 # 获取所有历史记录,用于 .GitInfo 和 .Lastmod
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5 # 配置 GitHub Pages 构建环境
- name: Build with Hugo
env:
# 对于企业服务器,构建时可能需要覆盖 baseURL
# HUGO_ENV: production # 通常 Hugo 会自动设为 production
HUGO_baseURL: ${{ steps.pages.outputs.base_url }} # 使用 configure-pages action 提供的 baseURL
run: |
hugo \
--gc \
--minify \
--baseURL "${{ steps.pages.outputs.base_url }}" # 明确传递 baseURL
- name: Upload artifact
uses: actions/upload-pages-artifact@v3 # 上传构建好的静态文件作为 artifact
with:
path: ./public # Hugo 默认的输出目录
# 部署任务
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }} # 设置部署环境的 URL
runs-on: ubuntu-latest
needs: build # 依赖于构建任务成功完成
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # 从 artifact 部署到 GitHub Pages