Skip to content

Commit 723e894

Browse files
committed
新增(CI/CD): 添加 GitHub Actions 工作流和模板
新增 GitHub Actions 工作流以支持 CI/CD,包括 nuget-publish.yml 和 release.yml,分别用于构建、测试和发布 NuGet 包。 新增 PR 模板、Bug 报告模板和功能请求模板以规范化贡献流程。 新增本地构建验证脚本 build-check.ps1 和版本发布脚本 release.ps1,支持本地验证和自动化版本发布。 更新 README.md,添加徽章、功能对比表和 CI/CD 使用指南。 更新 Directory.Build.props,修正项目链接。
1 parent a3a1f08 commit 723e894

File tree

11 files changed

+804
-9
lines changed

11 files changed

+804
-9
lines changed

.github/CICD.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# CodeInject GitHub Actions 配置
2+
3+
[![Build and Publish](https://github.com/RRQM/CodeInject/actions/workflows/nuget-publish.yml/badge.svg)](https://github.com/RRQM/CodeInject/actions/workflows/nuget-publish.yml)
4+
[![Release](https://github.com/RRQM/CodeInject/actions/workflows/release.yml/badge.svg)](https://github.com/RRQM/CodeInject/actions/workflows/release.yml)
5+
[![NuGet Version](https://img.shields.io/nuget/v/CodeInject)](https://www.nuget.org/packages/CodeInject/)
6+
7+
## 自动化 CI/CD 流程
8+
9+
本项目使用 GitHub Actions 实现自动化的持续集成和部署流程。
10+
11+
### 🔄 持续集成工作流 (nuget-publish.yml)
12+
13+
**触发条件:**
14+
- 推送到 `main``master` 分支
15+
-`main``master` 分支创建 Pull Request
16+
- 修改 `src/` 目录下的文件
17+
18+
**执行步骤:**
19+
1. ✅ 检出代码
20+
2. 🔧 设置 .NET 环境
21+
3. 📦 还原依赖项
22+
4. 🏗️ 构建源代码生成器
23+
5. 🏗️ 构建主项目
24+
6. 🧪 运行测试(如果存在)
25+
7. 📦 打包 NuGet 包
26+
8. 🚀 发布到 NuGet.org 和 GitHub Packages(仅在推送到主分支时)
27+
28+
### 🚀 发布工作流 (release.yml)
29+
30+
**触发条件:**
31+
- 推送版本标签(格式:`v*`,如 `v1.0.0`
32+
33+
**执行步骤:**
34+
1. ✅ 检出代码
35+
2. 🔧 设置 .NET 环境
36+
3. 🏷️ 从标签获取版本号
37+
4. 📝 更新 Directory.Build.props 中的版本
38+
5. 📦 还原依赖项
39+
6. 🏗️ 构建项目
40+
7. 📦 打包 NuGet 包
41+
8. 📋 创建 GitHub Release
42+
9. 🚀 发布到 NuGet.org 和 GitHub Packages
43+
44+
## 🛠️ 设置指南
45+
46+
### 1. 配置 NuGet API Key
47+
48+
需要在 GitHub 仓库中设置以下 Secret:
49+
50+
| Secret 名称 | 描述 | 获取方式 |
51+
| --------------- | ------------------ | ---------------------------------------------------------- |
52+
| `NUGET_API_KEY` | NuGet.org API 密钥 |[NuGet.org](https://www.nuget.org/account/apikeys) 创建 |
53+
54+
**详细步骤:**
55+
1. 登录 [NuGet.org](https://www.nuget.org/)
56+
2. 导航到:用户名 → API Keys
57+
3. 点击 "Create" 创建新的 API Key
58+
4. 选择适当的权限范围
59+
5. 复制生成的 API Key
60+
6. 在 GitHub 仓库中添加:Settings → Secrets and variables → Actions → New repository secret
61+
62+
### 2. 验证项目配置
63+
64+
确保以下文件配置正确:
65+
66+
**src/Directory.Build.props:**
67+
```xml
68+
<PropertyGroup>
69+
<Version>0.0.5</Version>
70+
<PackageProjectUrl>https://github.com/RRQM/CodeInject</PackageProjectUrl>
71+
<RepositoryUrl>https://github.com/RRQM/CodeInject</RepositoryUrl>
72+
<!-- 其他包信息 -->
73+
</PropertyGroup>
74+
```
75+
76+
**src/CodeInject/CodeInject.csproj:**
77+
```xml
78+
<PropertyGroup>
79+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
80+
<!-- 其他项目配置 -->
81+
</PropertyGroup>
82+
```
83+
84+
## 📋 使用指南
85+
86+
### 开发版本发布
87+
88+
```bash
89+
# 提交代码
90+
git add .
91+
git commit -m "feat: 添加新功能"
92+
git push origin main
93+
```
94+
95+
推送到主分支后,GitHub Actions 会自动:
96+
- 构建项目
97+
- 运行测试
98+
- 发布 NuGet 包
99+
100+
### 正式版本发布
101+
102+
```bash
103+
# 创建并推送版本标签
104+
git tag v1.2.3
105+
git push origin v1.2.3
106+
```
107+
108+
推送标签后,GitHub Actions 会自动:
109+
- 更新版本号
110+
- 构建项目
111+
- 创建 GitHub Release
112+
- 发布 NuGet 包
113+
114+
### 版本号管理
115+
116+
- 开发版本:使用 `Directory.Build.props` 中的版本号
117+
- 发布版本:使用 Git 标签中的版本号(自动更新)
118+
119+
## 🔍 监控和调试
120+
121+
### 查看构建状态
122+
123+
1. 前往 GitHub 仓库的 "Actions" 标签页
124+
2. 查看工作流运行历史
125+
3. 点击具体的运行记录查看详细日志
126+
127+
### 常见问题排查
128+
129+
| 问题 | 可能原因 | 解决方案 |
130+
| -------------- | ---------------------- | ------------------------------ |
131+
| NuGet 发布失败 | API Key 无效或权限不足 | 重新生成 API Key 并更新 Secret |
132+
| 构建失败 | 代码编译错误 | 检查代码语法和依赖项 |
133+
| 版本冲突 | 相同版本已存在 | 更新版本号或使用新标签 |
134+
| 权限错误 | GitHub Token 权限不足 | 检查仓库权限设置 |
135+
136+
### 日志查看
137+
138+
在 GitHub Actions 运行页面可以查看:
139+
- 构建输出
140+
- 测试结果
141+
- 发布状态
142+
- 错误信息
143+
144+
## 🔧 自定义配置
145+
146+
### 修改触发条件
147+
148+
编辑 `.github/workflows/nuget-publish.yml`
149+
150+
```yaml
151+
on:
152+
push:
153+
branches: [ main, develop ] # 添加其他分支
154+
paths:
155+
- 'src/**'
156+
- 'tests/**' # 添加其他路径
157+
```
158+
159+
### 添加额外步骤
160+
161+
可以在工作流中添加:
162+
- 代码质量检查
163+
- 安全扫描
164+
- 性能测试
165+
- 文档生成
166+
167+
### 环境变量配置
168+
169+
在工作流文件中可配置:
170+
171+
```yaml
172+
env:
173+
DOTNET_VERSION: '8.0.x'
174+
BUILD_CONFIGURATION: 'Release'
175+
PACKAGE_OUTPUT_PATH: './packages'
176+
```
177+
178+
## 📈 最佳实践
179+
180+
1. **版本管理**: 使用语义化版本号(SemVer)
181+
2. **分支策略**: main 分支保持稳定,使用 feature 分支开发
182+
3. **测试覆盖**: 确保有足够的单元测试
183+
4. **文档更新**: 及时更新 CHANGELOG 和 README
184+
5. **安全考虑**: 定期更新依赖项和 API Key
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: Bug Report
3+
about: Create a report to help us improve
4+
title: '[BUG] '
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
## 🐛 Bug Description
11+
A clear and concise description of what the bug is.
12+
13+
## 🔄 Steps to Reproduce
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
## ✅ Expected Behavior
21+
A clear and concise description of what you expected to happen.
22+
23+
## ❌ Actual Behavior
24+
A clear and concise description of what actually happened.
25+
26+
## 📱 Environment Information
27+
- OS: [e.g. Windows 11, macOS 13, Ubuntu 22.04]
28+
- .NET Version: [e.g. .NET 8.0]
29+
- CodeInject Version: [e.g. 0.0.5]
30+
- IDE: [e.g. Visual Studio 2022, VS Code, Rider]
31+
32+
## 📎 Code Sample
33+
```csharp
34+
// Please provide a minimal code sample that reproduces the issue
35+
[CodeInject("TemplateName", "RegionName")]
36+
public partial class MyClass
37+
{
38+
}
39+
```
40+
41+
## 📄 Template File
42+
```csharp
43+
// If applicable, include the template file content
44+
#region RegionName
45+
// Template code here
46+
#endregion
47+
```
48+
49+
## 📊 Additional Context
50+
Add any other context about the problem here, such as:
51+
- Error messages
52+
- Log files
53+
- Screenshots
54+
- Related issues
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Feature Request
3+
about: Suggest an idea for this project
4+
title: '[FEATURE] '
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
## 🚀 Feature Description
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
## 💡 Proposed Solution
14+
A clear and concise description of what you want to happen.
15+
16+
## 🔄 Use Case
17+
Describe the use case for this feature:
18+
- Who would use this feature?
19+
- When would they use it?
20+
- Why is it needed?
21+
22+
## 📝 Code Example
23+
```csharp
24+
// If applicable, provide an example of how this feature would be used
25+
[YourProposedAttribute]
26+
public partial class Example
27+
{
28+
// Expected generated code
29+
}
30+
```
31+
32+
## 🎯 Acceptance Criteria
33+
- [ ] Feature should do X
34+
- [ ] Feature should support Y
35+
- [ ] Feature should be backward compatible
36+
- [ ] Documentation should be updated
37+
38+
## 🔀 Alternatives Considered
39+
A clear and concise description of any alternative solutions or features you've considered.
40+
41+
## 📊 Additional Context
42+
Add any other context or screenshots about the feature request here.

.github/pull_request_template.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## 📋 Pull Request Description
2+
3+
### 🎯 What does this PR do?
4+
Briefly describe what this pull request accomplishes.
5+
6+
### 🔗 Related Issues
7+
Fixes #(issue_number)
8+
Closes #(issue_number)
9+
Related to #(issue_number)
10+
11+
### 🧪 Type of Change
12+
- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
13+
- [ ] ✨ New feature (non-breaking change which adds functionality)
14+
- [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
15+
- [ ] 📚 Documentation update
16+
- [ ] 🔧 Build/CI change
17+
- [ ] ♻️ Code refactoring
18+
- [ ] 🎨 Style/formatting change
19+
20+
### 🔍 Changes Made
21+
-
22+
-
23+
-
24+
25+
### 🧪 Testing
26+
- [ ] I have added tests that prove my fix is effective or that my feature works
27+
- [ ] New and existing unit tests pass locally with my changes
28+
- [ ] I have tested this change in a real project
29+
30+
### 📝 Testing Instructions
31+
1.
32+
2.
33+
3.
34+
35+
### 📱 Environment Tested
36+
- OS: [e.g. Windows 11]
37+
- .NET Version: [e.g. .NET 8.0]
38+
- IDE: [e.g. Visual Studio 2022]
39+
40+
### 📄 Code Quality Checklist
41+
- [ ] My code follows the existing code style
42+
- [ ] I have performed a self-review of my own code
43+
- [ ] I have commented my code, particularly in hard-to-understand areas
44+
- [ ] I have made corresponding changes to the documentation
45+
- [ ] My changes generate no new warnings
46+
- [ ] Any dependent changes have been merged and published
47+
48+
### 📊 Performance Impact
49+
- [ ] No performance impact
50+
- [ ] Improved performance
51+
- [ ] Potential performance impact (please describe)
52+
53+
**Performance details:**
54+
55+
### 🔒 Security Considerations
56+
- [ ] No security implications
57+
- [ ] Security review required
58+
- [ ] Security improvements
59+
60+
**Security details:**
61+
62+
### 📸 Screenshots (if applicable)
63+
Add screenshots to help explain your changes.
64+
65+
### 📋 Additional Notes
66+
Add any other notes about this pull request here.

0 commit comments

Comments
 (0)