Add documentation and scripts
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
89
CLONE.md
Normal file
89
CLONE.md
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
# 项目克隆地址和使用说明
|
||||||
|
|
||||||
|
## 📦 克隆地址
|
||||||
|
|
||||||
|
### HTTPS(推荐)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### SSH(需要配置 SSH 密钥)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 快速开始
|
||||||
|
|
||||||
|
### 1. 克隆项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
cd wecom-ai-assistant
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 配置环境
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 复制环境变量模板
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Windows PowerShell
|
||||||
|
Copy-Item .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 启动服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 访问服务
|
||||||
|
|
||||||
|
- 管理后台:http://localhost
|
||||||
|
- 后端 API:http://localhost:8000/api/health
|
||||||
|
|
||||||
|
## 📚 详细文档
|
||||||
|
|
||||||
|
- [Git 克隆和使用指南](./docs/git-clone-guide.md)
|
||||||
|
- [GitHub 快速开始](./docs/github-quickstart.md)
|
||||||
|
- [项目 README](./README.md)
|
||||||
|
|
||||||
|
## 🔐 推送代码
|
||||||
|
|
||||||
|
### 使用 Token(HTTPS)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 设置远程 URL(包含 token)
|
||||||
|
git remote set-url origin https://bujie9527:YOUR_TOKEN@github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
|
||||||
|
# 推送代码
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用 SSH
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 配置 SSH 密钥后
|
||||||
|
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📝 项目信息
|
||||||
|
|
||||||
|
- **仓库地址**:https://github.com/bujie9527/wecom-ai-assistant
|
||||||
|
- **默认分支**:`main`
|
||||||
|
- **项目类型**:Monorepo(Backend + Admin + Deploy)
|
||||||
|
|
||||||
|
## ⚠️ 注意事项
|
||||||
|
|
||||||
|
1. **环境变量**:`.env` 文件包含敏感信息,不要提交到 Git
|
||||||
|
2. **GitHub Token**:推送代码时需要 Personal Access Token
|
||||||
|
3. **Docker**:确保已安装 Docker 和 docker-compose
|
||||||
|
|
||||||
|
## 🆘 获取帮助
|
||||||
|
|
||||||
|
- 查看 [Git 克隆指南](./docs/git-clone-guide.md)
|
||||||
|
- 查看 [GitHub 配置指南](./docs/github-config-guide.md)
|
||||||
|
- 提交 Issue:https://github.com/bujie9527/wecom-ai-assistant/issues
|
||||||
270
docs/git-clone-guide.md
Normal file
270
docs/git-clone-guide.md
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
# Git 克隆和使用指南
|
||||||
|
|
||||||
|
## 项目信息
|
||||||
|
|
||||||
|
- **GitHub 仓库地址**:https://github.com/bujie9527/wecom-ai-assistant
|
||||||
|
- **默认分支**:`main`
|
||||||
|
- **项目类型**:Monorepo(backend + admin + deploy + docs)
|
||||||
|
|
||||||
|
## 克隆项目
|
||||||
|
|
||||||
|
### 方式一:HTTPS 克隆(推荐)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 克隆项目
|
||||||
|
git clone https://github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
|
||||||
|
# 进入项目目录
|
||||||
|
cd wecom-ai-assistant
|
||||||
|
```
|
||||||
|
|
||||||
|
**如果需要认证**(推送代码时):
|
||||||
|
```bash
|
||||||
|
# 使用 Personal Access Token 作为密码
|
||||||
|
git clone https://github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
# 用户名:bujie9527
|
||||||
|
# 密码:你的 GitHub Personal Access Token
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方式二:SSH 克隆(需要配置 SSH 密钥)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 克隆项目
|
||||||
|
git clone git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
|
||||||
|
# 进入项目目录
|
||||||
|
cd wecom-ai-assistant
|
||||||
|
```
|
||||||
|
|
||||||
|
**配置 SSH 密钥**:
|
||||||
|
1. 生成 SSH 密钥:`ssh-keygen -t ed25519 -C "your_email@example.com"`
|
||||||
|
2. 将公钥添加到 GitHub:https://github.com/settings/keys
|
||||||
|
3. 测试连接:`ssh -T git@github.com`
|
||||||
|
|
||||||
|
## 项目结构
|
||||||
|
|
||||||
|
```
|
||||||
|
wecom-ai-assistant/
|
||||||
|
├── backend/ # Python FastAPI 后端
|
||||||
|
├── admin/ # Next.js 管理后台
|
||||||
|
├── deploy/ # 部署配置和脚本
|
||||||
|
├── docs/ # 项目文档
|
||||||
|
├── scripts/ # 自动化脚本
|
||||||
|
├── docker-compose.yml # 本地开发配置
|
||||||
|
└── README.md # 项目说明
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 1. 克隆项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
cd wecom-ai-assistant
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 配置环境变量
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 复制环境变量模板
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Windows PowerShell
|
||||||
|
Copy-Item .env.example .env
|
||||||
|
|
||||||
|
# 编辑 .env 文件,填写必需配置
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 启动项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用 Docker Compose 一键启动
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
# 查看服务状态
|
||||||
|
docker compose ps
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
docker compose logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 访问服务
|
||||||
|
|
||||||
|
- **管理后台**:http://localhost
|
||||||
|
- **后端 API**:http://localhost:8000/api/health
|
||||||
|
- **PostgreSQL**:localhost:5432
|
||||||
|
|
||||||
|
## 常用 Git 操作
|
||||||
|
|
||||||
|
### 拉取最新代码
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 拉取远程最新代码
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# 或指定远程分支
|
||||||
|
git pull origin main --rebase
|
||||||
|
```
|
||||||
|
|
||||||
|
### 推送代码
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 添加更改
|
||||||
|
git add .
|
||||||
|
|
||||||
|
# 提交更改
|
||||||
|
git commit -m "描述你的更改"
|
||||||
|
|
||||||
|
# 推送到远程
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
### 查看分支
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看所有分支
|
||||||
|
git branch -a
|
||||||
|
|
||||||
|
# 查看远程分支
|
||||||
|
git branch -r
|
||||||
|
|
||||||
|
# 切换分支
|
||||||
|
git checkout branch-name
|
||||||
|
```
|
||||||
|
|
||||||
|
### 查看提交历史
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看提交历史
|
||||||
|
git log --oneline
|
||||||
|
|
||||||
|
# 查看最近 10 条提交
|
||||||
|
git log --oneline -10
|
||||||
|
|
||||||
|
# 查看图形化历史
|
||||||
|
git log --graph --oneline --all
|
||||||
|
```
|
||||||
|
|
||||||
|
## 分支管理
|
||||||
|
|
||||||
|
### 创建新分支
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 从 main 分支创建新分支
|
||||||
|
git checkout -b feature/new-feature
|
||||||
|
|
||||||
|
# 推送新分支到远程
|
||||||
|
git push -u origin feature/new-feature
|
||||||
|
```
|
||||||
|
|
||||||
|
### 合并分支
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 切换到 main 分支
|
||||||
|
git checkout main
|
||||||
|
|
||||||
|
# 拉取最新代码
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# 合并功能分支
|
||||||
|
git merge feature/new-feature
|
||||||
|
|
||||||
|
# 推送合并后的代码
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 推送代码到 GitHub
|
||||||
|
|
||||||
|
### 使用 HTTPS(需要 Token)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 方式一:在 URL 中嵌入 token(不推荐,但方便)
|
||||||
|
git remote set-url origin https://bujie9527:YOUR_TOKEN@github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
# 方式二:使用 Git Credential Manager(推荐)
|
||||||
|
# Git 会提示输入用户名和密码
|
||||||
|
# 用户名:bujie9527
|
||||||
|
# 密码:你的 GitHub Personal Access Token
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用 SSH(推荐,更安全)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 配置 SSH 密钥后
|
||||||
|
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置 Git 用户信息
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 设置用户名
|
||||||
|
git config user.name "bujie9527"
|
||||||
|
|
||||||
|
# 设置邮箱
|
||||||
|
git config user.email "your_email@example.com"
|
||||||
|
|
||||||
|
# 查看配置
|
||||||
|
git config --list
|
||||||
|
```
|
||||||
|
|
||||||
|
## 忽略文件
|
||||||
|
|
||||||
|
项目已配置 `.gitignore`,以下文件不会被提交:
|
||||||
|
|
||||||
|
- `.env`、`.env.prod`(环境变量文件)
|
||||||
|
- `.github-config`(GitHub 配置文件,包含敏感 token)
|
||||||
|
- `node_modules/`(Node.js 依赖)
|
||||||
|
- `__pycache__/`(Python 缓存)
|
||||||
|
- `.next/`(Next.js 构建文件)
|
||||||
|
- `logs/`(日志文件)
|
||||||
|
|
||||||
|
## 故障排查
|
||||||
|
|
||||||
|
### 推送时提示认证失败
|
||||||
|
|
||||||
|
**问题**:`fatal: Authentication failed`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
1. 检查 GitHub Personal Access Token 是否有效
|
||||||
|
2. 确认 token 权限包含 `repo`
|
||||||
|
3. 更新远程 URL:`git remote set-url origin https://bujie9527:YOUR_TOKEN@github.com/bujie9527/wecom-ai-assistant.git`
|
||||||
|
|
||||||
|
### 拉取时提示冲突
|
||||||
|
|
||||||
|
**问题**:`error: Your local changes would be overwritten by merge`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
```bash
|
||||||
|
# 保存本地更改
|
||||||
|
git stash
|
||||||
|
|
||||||
|
# 拉取最新代码
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# 恢复本地更改
|
||||||
|
git stash pop
|
||||||
|
```
|
||||||
|
|
||||||
|
### 无法连接到 GitHub
|
||||||
|
|
||||||
|
**问题**:`fatal: unable to access 'https://github.com/...'`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
1. 检查网络连接
|
||||||
|
2. 检查防火墙设置
|
||||||
|
3. 如果在中国大陆,可能需要配置代理或使用镜像
|
||||||
|
|
||||||
|
## 相关文档
|
||||||
|
|
||||||
|
- [GitHub 快速开始指南](./github-quickstart.md)
|
||||||
|
- [GitHub 配置文件指南](./github-config-guide.md)
|
||||||
|
- [项目 README](../README.md)
|
||||||
|
|
||||||
|
## 获取帮助
|
||||||
|
|
||||||
|
- **Git 官方文档**:https://git-scm.com/doc
|
||||||
|
- **GitHub 帮助**:https://docs.github.com
|
||||||
|
- **项目 Issues**:https://github.com/bujie9527/wecom-ai-assistant/issues
|
||||||
225
docs/git-network-troubleshooting.md
Normal file
225
docs/git-network-troubleshooting.md
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
# Git 网络连接问题排查指南
|
||||||
|
|
||||||
|
## 问题:`fatal: unable to access 'https://github.com/...': Recv failure: Connection was reset`
|
||||||
|
|
||||||
|
这是常见的网络连接问题,通常出现在中国大陆访问 GitHub 时。
|
||||||
|
|
||||||
|
## 解决方案
|
||||||
|
|
||||||
|
### 方案一:配置 Git 代理(推荐)
|
||||||
|
|
||||||
|
如果你有可用的代理(VPN/SSR/V2Ray),可以配置 Git 使用代理:
|
||||||
|
|
||||||
|
#### 设置 HTTP/HTTPS 代理
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 设置全局代理(所有 Git 操作都使用代理)
|
||||||
|
git config --global http.proxy http://127.0.0.1:7890
|
||||||
|
git config --global https.proxy http://127.0.0.1:7890
|
||||||
|
|
||||||
|
# 仅针对 GitHub 设置代理
|
||||||
|
git config --global http.https://github.com.proxy http://127.0.0.1:7890
|
||||||
|
git config --global https.https://github.com.proxy http://127.0.0.1:7890
|
||||||
|
|
||||||
|
# 查看代理配置
|
||||||
|
git config --global --get http.proxy
|
||||||
|
git config --global --get https.proxy
|
||||||
|
```
|
||||||
|
|
||||||
|
**常见代理端口**:
|
||||||
|
- Clash: `7890`
|
||||||
|
- V2Ray: `10808`
|
||||||
|
- SSR: `1080`
|
||||||
|
- 其他:根据你的代理软件设置
|
||||||
|
|
||||||
|
#### 取消代理设置
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 取消全局代理
|
||||||
|
git config --global --unset http.proxy
|
||||||
|
git config --global --unset https.proxy
|
||||||
|
|
||||||
|
# 取消 GitHub 特定代理
|
||||||
|
git config --global --unset http.https://github.com.proxy
|
||||||
|
git config --global --unset https.https://github.com.proxy
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方案二:使用 SSH 代替 HTTPS
|
||||||
|
|
||||||
|
SSH 连接通常比 HTTPS 更稳定:
|
||||||
|
|
||||||
|
#### 1. 生成 SSH 密钥
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 生成 SSH 密钥对
|
||||||
|
ssh-keygen -t ed25519 -C "your_email@example.com"
|
||||||
|
|
||||||
|
# 按 Enter 使用默认路径
|
||||||
|
# 可以设置密码或直接按 Enter(不设置密码)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. 添加 SSH 公钥到 GitHub
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 查看公钥内容
|
||||||
|
cat $env:USERPROFILE\.ssh\id_ed25519.pub
|
||||||
|
|
||||||
|
# 复制公钥内容,然后:
|
||||||
|
# 1. 访问 https://github.com/settings/keys
|
||||||
|
# 2. 点击 "New SSH key"
|
||||||
|
# 3. 粘贴公钥内容
|
||||||
|
# 4. 点击 "Add SSH key"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. 测试 SSH 连接
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 测试 SSH 连接
|
||||||
|
ssh -T git@github.com
|
||||||
|
|
||||||
|
# 如果看到 "Hi bujie9527! You've successfully authenticated..." 说明成功
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4. 更改远程仓库 URL 为 SSH
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 更改远程 URL 为 SSH
|
||||||
|
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
|
||||||
|
# 验证更改
|
||||||
|
git remote -v
|
||||||
|
|
||||||
|
# 再次推送
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方案三:使用 GitHub 镜像(临时方案)
|
||||||
|
|
||||||
|
可以使用 GitHub 镜像站点:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 使用镜像站点(不推荐,仅临时使用)
|
||||||
|
git remote set-url origin https://github.com.cnpmjs.org/bujie9527/wecom-ai-assistant.git
|
||||||
|
|
||||||
|
# 推送后改回原地址
|
||||||
|
git push -u origin main
|
||||||
|
git remote set-url origin https://github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方案四:增加超时和重试
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 增加 Git 超时时间
|
||||||
|
git config --global http.postBuffer 524288000
|
||||||
|
git config --global http.lowSpeedLimit 0
|
||||||
|
git config --global http.lowSpeedTime 999999
|
||||||
|
|
||||||
|
# 使用重试机制推送
|
||||||
|
git push -u origin main --verbose
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方案五:使用 GitHub CLI(gh)
|
||||||
|
|
||||||
|
如果安装了 GitHub CLI:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 安装 GitHub CLI(如果还没有)
|
||||||
|
# 下载:https://cli.github.com/
|
||||||
|
|
||||||
|
# 登录
|
||||||
|
gh auth login
|
||||||
|
|
||||||
|
# 推送代码
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 快速诊断
|
||||||
|
|
||||||
|
### 检查网络连接
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 测试 GitHub 连接
|
||||||
|
Test-NetConnection github.com -Port 443
|
||||||
|
|
||||||
|
# 测试 DNS 解析
|
||||||
|
nslookup github.com
|
||||||
|
|
||||||
|
# 使用 curl 测试
|
||||||
|
curl -I https://github.com
|
||||||
|
```
|
||||||
|
|
||||||
|
### 检查 Git 配置
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 查看所有 Git 配置
|
||||||
|
git config --list
|
||||||
|
|
||||||
|
# 查看远程仓库配置
|
||||||
|
git remote -v
|
||||||
|
|
||||||
|
# 查看当前分支
|
||||||
|
git branch
|
||||||
|
```
|
||||||
|
|
||||||
|
## 推荐方案
|
||||||
|
|
||||||
|
**最佳实践**(按优先级):
|
||||||
|
|
||||||
|
1. **配置代理**(如果你有 VPN/代理)
|
||||||
|
```powershell
|
||||||
|
git config --global http.https://github.com.proxy http://127.0.0.1:7890
|
||||||
|
git config --global https.https://github.com.proxy http://127.0.0.1:7890
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **使用 SSH**(更稳定,一次配置长期使用)
|
||||||
|
```powershell
|
||||||
|
# 生成 SSH 密钥并添加到 GitHub
|
||||||
|
# 然后更改远程 URL
|
||||||
|
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **重试推送**(网络临时问题时)
|
||||||
|
```powershell
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常见错误和解决方案
|
||||||
|
|
||||||
|
### 错误 1:`SSL certificate problem`
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 临时忽略 SSL 验证(不推荐,仅测试用)
|
||||||
|
git config --global http.sslVerify false
|
||||||
|
```
|
||||||
|
|
||||||
|
### 错误 2:`Authentication failed`
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 清除缓存的凭据
|
||||||
|
git credential-manager-core erase
|
||||||
|
# 或
|
||||||
|
git credential reject https://github.com
|
||||||
|
|
||||||
|
# 重新推送时会提示输入用户名和 token
|
||||||
|
```
|
||||||
|
|
||||||
|
### 错误 3:`Connection timed out`
|
||||||
|
|
||||||
|
- 检查防火墙设置
|
||||||
|
- 检查代理配置
|
||||||
|
- 尝试使用 SSH
|
||||||
|
|
||||||
|
## 验证推送成功
|
||||||
|
|
||||||
|
推送成功后,访问以下 URL 验证:
|
||||||
|
|
||||||
|
- **仓库地址**:https://github.com/bujie9527/wecom-ai-assistant
|
||||||
|
- **提交历史**:https://github.com/bujie9527/wecom-ai-assistant/commits/main
|
||||||
|
|
||||||
|
## 获取帮助
|
||||||
|
|
||||||
|
如果以上方案都无法解决:
|
||||||
|
|
||||||
|
1. 检查 GitHub 状态:https://www.githubstatus.com/
|
||||||
|
2. 查看 Git 日志:`git push -u origin main --verbose`
|
||||||
|
3. 提交 Issue:https://github.com/bujie9527/wecom-ai-assistant/issues
|
||||||
170
docs/github-token-permissions.md
Normal file
170
docs/github-token-permissions.md
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
# GitHub Personal Access Token 权限配置指南
|
||||||
|
|
||||||
|
## 问题:`refusing to allow a Personal Access Token to create or update workflow`
|
||||||
|
|
||||||
|
### 原因
|
||||||
|
|
||||||
|
GitHub 要求推送 `.github/workflows/` 目录下的文件时,Personal Access Token 必须包含 `workflow` 权限。
|
||||||
|
|
||||||
|
### 解决方案
|
||||||
|
|
||||||
|
## 方案一:更新 Token 权限(推荐)
|
||||||
|
|
||||||
|
### 步骤 1:创建新的 Personal Access Token
|
||||||
|
|
||||||
|
1. 访问:https://github.com/settings/tokens
|
||||||
|
2. 点击 **Generate new token (classic)**
|
||||||
|
3. 填写 Token 名称:`wecom-ai-assistant-full-access`
|
||||||
|
4. 选择过期时间:根据你的需求(推荐 90 天或 No expiration)
|
||||||
|
5. **选择以下权限**:
|
||||||
|
- ✅ **repo**(完整仓库访问权限)
|
||||||
|
- ✅ repo:status
|
||||||
|
- ✅ repo_deployment
|
||||||
|
- ✅ public_repo
|
||||||
|
- ✅ repo:invite
|
||||||
|
- ✅ security_events
|
||||||
|
- ✅ **workflow**(工作流权限)**← 必需**
|
||||||
|
- ✅ **write:packages**(推送 Docker 镜像到 GHCR)
|
||||||
|
- ✅ **read:packages**(从 GHCR 拉取镜像)
|
||||||
|
6. 点击 **Generate token**
|
||||||
|
7. **立即复制 token**(只显示一次)
|
||||||
|
|
||||||
|
### 步骤 2:更新配置文件
|
||||||
|
|
||||||
|
编辑 `.github-config` 文件,更新 token:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GITHUB_TOKEN=你的新token
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 3:更新 Git 远程 URL
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 使用新 token 更新远程 URL
|
||||||
|
git remote set-url origin https://bujie9527:你的新token@github.com/bujie9527/wecom-ai-assistant.git
|
||||||
|
|
||||||
|
# 验证
|
||||||
|
git remote -v
|
||||||
|
|
||||||
|
# 重新推送
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 方案二:临时跳过 Workflow 文件(快速解决)
|
||||||
|
|
||||||
|
如果暂时不想更新 token,可以先推送其他文件:
|
||||||
|
|
||||||
|
### 步骤 1:移除 workflow 文件从暂存区
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 从暂存区移除 workflow 文件
|
||||||
|
git reset HEAD .github/workflows/
|
||||||
|
|
||||||
|
# 提交其他文件
|
||||||
|
git commit -m "Initial commit: 企业微信 AI 机器人助理 MVP (without workflows)"
|
||||||
|
|
||||||
|
# 推送
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 2:稍后单独推送 workflow 文件
|
||||||
|
|
||||||
|
更新 token 后:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 添加 workflow 文件
|
||||||
|
git add .github/workflows/
|
||||||
|
|
||||||
|
# 提交
|
||||||
|
git commit -m "Add GitHub Actions workflows"
|
||||||
|
|
||||||
|
# 推送
|
||||||
|
git push origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 方案三:使用 GitHub CLI(gh)
|
||||||
|
|
||||||
|
如果安装了 GitHub CLI:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 安装 GitHub CLI(如果还没有)
|
||||||
|
# 下载:https://cli.github.com/
|
||||||
|
|
||||||
|
# 登录(会自动处理权限)
|
||||||
|
gh auth login
|
||||||
|
|
||||||
|
# 推送代码
|
||||||
|
git push -u origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## Token 权限说明
|
||||||
|
|
||||||
|
### 必需权限
|
||||||
|
|
||||||
|
| 权限 | 说明 | 用途 |
|
||||||
|
|------|------|------|
|
||||||
|
| `repo` | 完整仓库访问 | 推送代码、创建分支等 |
|
||||||
|
| `workflow` | 工作流权限 | 推送 `.github/workflows/` 文件 |
|
||||||
|
| `write:packages` | 写入包 | 推送 Docker 镜像到 GHCR |
|
||||||
|
| `read:packages` | 读取包 | 从 GHCR 拉取镜像 |
|
||||||
|
|
||||||
|
### 权限范围
|
||||||
|
|
||||||
|
- **Full control of private repositories**:如果你使用私有仓库
|
||||||
|
- **Public repositories only**:如果使用公开仓库
|
||||||
|
|
||||||
|
## 验证 Token 权限
|
||||||
|
|
||||||
|
推送成功后,检查:
|
||||||
|
|
||||||
|
1. **仓库文件**:https://github.com/bujie9527/wecom-ai-assistant
|
||||||
|
2. **Workflow 文件**:https://github.com/bujie9527/wecom-ai-assistant/tree/main/.github/workflows
|
||||||
|
3. **Actions**:https://github.com/bujie9527/wecom-ai-assistant/actions
|
||||||
|
|
||||||
|
## 安全建议
|
||||||
|
|
||||||
|
1. **Token 安全**:
|
||||||
|
- 不要将 token 提交到 Git
|
||||||
|
- 定期轮换 token(每 90 天)
|
||||||
|
- 如果 token 泄露,立即撤销
|
||||||
|
|
||||||
|
2. **最小权限原则**:
|
||||||
|
- 只授予必要的权限
|
||||||
|
- 使用 Fine-grained tokens(如果可用)限制仓库范围
|
||||||
|
|
||||||
|
3. **Token 存储**:
|
||||||
|
- 存储在 `.github-config`(已添加到 `.gitignore`)
|
||||||
|
- 或使用环境变量
|
||||||
|
- 或使用 Git Credential Manager
|
||||||
|
|
||||||
|
## 故障排查
|
||||||
|
|
||||||
|
### 问题:仍然提示权限不足
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
1. 确认 token 已更新并包含 `workflow` 权限
|
||||||
|
2. 清除 Git 凭据缓存:
|
||||||
|
```powershell
|
||||||
|
git credential-manager-core erase
|
||||||
|
git credential reject https://github.com
|
||||||
|
```
|
||||||
|
3. 重新推送
|
||||||
|
|
||||||
|
### 问题:Token 在哪里查看/更新?
|
||||||
|
|
||||||
|
**答案**:
|
||||||
|
- 查看现有 tokens:https://github.com/settings/tokens
|
||||||
|
- 创建新 token:https://github.com/settings/tokens/new
|
||||||
|
|
||||||
|
### 问题:如何撤销旧 Token?
|
||||||
|
|
||||||
|
**答案**:
|
||||||
|
1. 访问:https://github.com/settings/tokens
|
||||||
|
2. 找到对应的 token
|
||||||
|
3. 点击 **Revoke**(撤销)
|
||||||
|
|
||||||
|
## 相关文档
|
||||||
|
|
||||||
|
- [GitHub Token 文档](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
|
||||||
|
- [GitHub Actions 权限](https://docs.github.com/en/actions/security-guides/automatic-token-authentication)
|
||||||
|
- [项目 Git 配置指南](./github-config-guide.md)
|
||||||
95
scripts/fix-git-network.ps1
Normal file
95
scripts/fix-git-network.ps1
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
# Git 网络连接问题修复脚本
|
||||||
|
# 用途:配置 Git 代理或切换到 SSH
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$ProxyHost = "127.0.0.1",
|
||||||
|
[int]$ProxyPort = 7890,
|
||||||
|
[switch]$UseSSH,
|
||||||
|
[switch]$RemoveProxy
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "=== Git 网络连接问题修复 ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
if ($RemoveProxy) {
|
||||||
|
Write-Host "移除 Git 代理配置..." -ForegroundColor Yellow
|
||||||
|
git config --global --unset http.proxy 2>$null
|
||||||
|
git config --global --unset https.proxy 2>$null
|
||||||
|
git config --global --unset http.https://github.com.proxy 2>$null
|
||||||
|
git config --global --unset https.https://github.com.proxy 2>$null
|
||||||
|
Write-Host "✓ 代理配置已移除" -ForegroundColor Green
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($UseSSH) {
|
||||||
|
Write-Host "切换到 SSH 连接..." -ForegroundColor Yellow
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 检查 SSH 密钥是否存在
|
||||||
|
$sshKeyPath = "$env:USERPROFILE\.ssh\id_ed25519.pub"
|
||||||
|
if (-not (Test-Path $sshKeyPath)) {
|
||||||
|
Write-Host "未找到 SSH 密钥,正在生成..." -ForegroundColor Yellow
|
||||||
|
ssh-keygen -t ed25519 -C "bujie9527@github.com" -f "$env:USERPROFILE\.ssh\id_ed25519" -N '""'
|
||||||
|
Write-Host "✓ SSH 密钥已生成" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
# 显示公钥
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "SSH 公钥内容(需要添加到 GitHub):" -ForegroundColor Cyan
|
||||||
|
Write-Host "---"
|
||||||
|
Get-Content $sshKeyPath
|
||||||
|
Write-Host "---"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "请执行以下步骤:" -ForegroundColor Yellow
|
||||||
|
Write-Host "1. 复制上面的公钥内容" -ForegroundColor Gray
|
||||||
|
Write-Host "2. 访问: https://github.com/settings/keys" -ForegroundColor Gray
|
||||||
|
Write-Host "3. 点击 'New SSH key'" -ForegroundColor Gray
|
||||||
|
Write-Host "4. 粘贴公钥并保存" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$continue = Read-Host "已添加 SSH 密钥到 GitHub? (y/n)"
|
||||||
|
if ($continue -eq "y" -or $continue -eq "Y") {
|
||||||
|
# 测试 SSH 连接
|
||||||
|
Write-Host "测试 SSH 连接..." -ForegroundColor Yellow
|
||||||
|
$testResult = ssh -T git@github.com 2>&1
|
||||||
|
if ($testResult -match "successfully authenticated") {
|
||||||
|
Write-Host "✓ SSH 连接成功" -ForegroundColor Green
|
||||||
|
|
||||||
|
# 更改远程 URL
|
||||||
|
Write-Host "更改远程仓库 URL 为 SSH..." -ForegroundColor Yellow
|
||||||
|
git remote set-url origin git@github.com:bujie9527/wecom-ai-assistant.git
|
||||||
|
Write-Host "✓ 远程 URL 已更改为 SSH" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "现在可以尝试推送:" -ForegroundColor Cyan
|
||||||
|
Write-Host " git push -u origin main" -ForegroundColor Gray
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ SSH 连接失败,请检查 SSH 密钥是否正确添加到 GitHub" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "配置 Git HTTP/HTTPS 代理..." -ForegroundColor Yellow
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "代理地址: http://${ProxyHost}:${ProxyPort}" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 仅针对 GitHub 设置代理
|
||||||
|
git config --global http.https://github.com.proxy "http://${ProxyHost}:${ProxyPort}"
|
||||||
|
git config --global https.https://github.com.proxy "http://${ProxyHost}:${ProxyPort}"
|
||||||
|
|
||||||
|
Write-Host "✓ 代理已配置" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "验证配置:" -ForegroundColor Yellow
|
||||||
|
git config --global --get http.https://github.com.proxy
|
||||||
|
git config --global --get https.https://github.com.proxy
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "现在可以尝试推送:" -ForegroundColor Cyan
|
||||||
|
Write-Host " git push -u origin main" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "如果代理端口不同,请使用:" -ForegroundColor Yellow
|
||||||
|
Write-Host " .\scripts\fix-git-network.ps1 -ProxyPort 你的端口号" -ForegroundColor Gray
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "其他选项:" -ForegroundColor Cyan
|
||||||
|
Write-Host " - 切换到 SSH: .\scripts\fix-git-network.ps1 -UseSSH" -ForegroundColor Gray
|
||||||
|
Write-Host " - 移除代理: .\scripts\fix-git-network.ps1 -RemoveProxy" -ForegroundColor Gray
|
||||||
64
scripts/update-github-token.ps1
Normal file
64
scripts/update-github-token.ps1
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
# 更新 GitHub Token 脚本
|
||||||
|
# 用途:更新 Git 远程 URL 中的 token
|
||||||
|
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$NewToken
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "=== 更新 GitHub Token ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 验证 token 格式
|
||||||
|
if ($NewToken -notmatch '^ghp_[A-Za-z0-9]{36}$') {
|
||||||
|
Write-Host "警告: Token 格式可能不正确(应以 ghp_ 开头)" -ForegroundColor Yellow
|
||||||
|
$continue = Read-Host "是否继续? (y/n)"
|
||||||
|
if ($continue -ne "y" -and $continue -ne "Y") {
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 更新远程 URL
|
||||||
|
Write-Host "更新 Git 远程 URL..." -ForegroundColor Yellow
|
||||||
|
git remote set-url origin "https://bujie9527:${NewToken}@github.com/bujie9527/wecom-ai-assistant.git"
|
||||||
|
|
||||||
|
Write-Host "✓ 远程 URL 已更新" -ForegroundColor Green
|
||||||
|
|
||||||
|
# 验证
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "验证远程配置:" -ForegroundColor Cyan
|
||||||
|
$remoteUrl = git remote get-url origin
|
||||||
|
# 隐藏 token 显示
|
||||||
|
$safeUrl = $remoteUrl -replace ':(ghp_[^@]+)@', ':****@'
|
||||||
|
Write-Host " $safeUrl" -ForegroundColor Gray
|
||||||
|
|
||||||
|
# 更新配置文件
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "更新配置文件..." -ForegroundColor Yellow
|
||||||
|
$configFile = ".github-config"
|
||||||
|
if (Test-Path $configFile) {
|
||||||
|
$content = Get-Content $configFile
|
||||||
|
$newContent = $content | ForEach-Object {
|
||||||
|
if ($_ -match '^GITHUB_TOKEN=') {
|
||||||
|
"GITHUB_TOKEN=${NewToken}"
|
||||||
|
} else {
|
||||||
|
$_
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newContent | Set-Content $configFile
|
||||||
|
Write-Host "✓ 配置文件已更新" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ 配置文件不存在,跳过更新" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "=== 完成 ===" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "现在可以尝试推送:" -ForegroundColor Cyan
|
||||||
|
Write-Host " git push -u origin main" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "如果仍然遇到权限问题,请确认 token 包含以下权限:" -ForegroundColor Yellow
|
||||||
|
Write-Host " - repo (完整仓库访问)" -ForegroundColor Gray
|
||||||
|
Write-Host " - workflow (工作流权限) ← 必需" -ForegroundColor Gray
|
||||||
|
Write-Host " - write:packages (推送镜像)" -ForegroundColor Gray
|
||||||
|
Write-Host " - read:packages (拉取镜像)" -ForegroundColor Gray
|
||||||
Reference in New Issue
Block a user