Skip to content

Commit f0e0f07

Browse files
committed
fix(gh-actions): 增补部署所需权限
- 添加 actions: read 权限 - 添加 deployments: write 权限 - 新增 SETUP_GUIDE.md 配置指南文档 Refs: #gh-actions-fix-permissions
1 parent 4251bb6 commit f0e0f07

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

.github/workflows/SETUP_GUIDE.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# GitHub Pages 部署配置指南
2+
3+
## 🔴 部署失败的常见原因
4+
5+
如果你看到类似以下的错误:
6+
```
7+
Error: Creating Pages deployment failed
8+
Error: HttpError: Not Found
9+
```
10+
11+
或者:
12+
```
13+
Error: Ensure GITHUB_TOKEN has permission "pages: write".
14+
```
15+
16+
这是因为 GitHub 仓库的 Pages 设置没有正确配置。
17+
18+
---
19+
20+
## ✅ 解决步骤
21+
22+
### 步骤 1: 启用 GitHub Pages
23+
24+
1. 打开仓库页面:`https://github.com/PyChina/weekly`
25+
2. 点击 **Settings** 标签
26+
3. 左侧菜单点击 **Pages**
27+
4.**Build and deployment** 部分:
28+
- **Source**: 选择 **GitHub Actions**
29+
30+
![source selection](https://docs.github.com/assets/images/help/pages/pages-source-github-actions.png)
31+
32+
> ⚠️ **重要**: 不要选择 "Deploy from a branch",必须选择 **GitHub Actions**
33+
34+
---
35+
36+
### 步骤 2: 检查 Workflow 权限
37+
38+
1. 在 Settings 页面,点击左侧 **Actions****General**
39+
2. 找到 **Workflow permissions** 部分:
40+
- 选择 **Read and write permissions**
41+
- 勾选 **Allow GitHub Actions to create and approve pull requests**
42+
43+
---
44+
45+
### 步骤 3: 重新运行工作流
46+
47+
配置完成后:
48+
49+
1. 进入 **Actions** 标签页
50+
2. 找到失败的 workflow run
51+
3. 点击 **Re-run jobs****Re-run all jobs**
52+
53+
或者推送一个新的 commit 触发新的部署:
54+
```bash
55+
git commit --allow-empty -m "触发重新部署"
56+
git push
57+
```
58+
59+
---
60+
61+
## 📋 完整的 GitHub 设置检查清单
62+
63+
| 设置项 | 路径 | 应该设置为 |
64+
|--------|------|-----------|
65+
| Pages Source | Settings → Pages → Source | GitHub Actions |
66+
| Workflow 权限 | Settings → Actions → General | Read and write permissions |
67+
| 环境保护规则 | Settings → Environments | 无(或允许 github-pages 分支) |
68+
69+
---
70+
71+
## 🔧 如果仍然失败
72+
73+
### 检查 Environment 设置
74+
75+
有些仓库需要配置 Environment:
76+
77+
1. Settings → Environments
78+
2. 点击 **github-pages**(如果没有就创建一个)
79+
3. 确保没有设置 **Deployment protection rules**,或暂时关闭 "Required reviewers"
80+
81+
### 检查 Token 权限
82+
83+
确保使用的是 `GITHUB_TOKEN` 而不是 `DEPLOY_TOKEN`
84+
85+
```yaml
86+
# 工作流中应该使用默认的 GITHUB_TOKEN
87+
permissions:
88+
pages: write
89+
id-token: write
90+
```
91+
92+
不需要在 Secrets 中设置任何 token。
93+
94+
---
95+
96+
## 📖 参考文档
97+
98+
- [GitHub Pages 文档](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)
99+
- [Deploy Pages Action](https://github.com/actions/deploy-pages)
100+
- [Upload Pages Artifact](https://github.com/actions/upload-pages-artifact)

.github/workflows/build-and-deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ permissions:
1616
contents: write
1717
pages: write
1818
id-token: write
19+
actions: read
20+
deployments: write
1921

2022
concurrency:
2123
group: "pages"

0 commit comments

Comments
 (0)