Skip to content

feat: add PowerShell release automation script for one-command releases#46

Merged
chsword merged 3 commits intomainfrom
copilot/create-powershell-script-for-csproj
Oct 11, 2025
Merged

feat: add PowerShell release automation script for one-command releases#46
chsword merged 3 commits intomainfrom
copilot/create-powershell-script-for-csproj

Conversation

Copy link
Contributor

Copilot AI commented Oct 11, 2025

概述 / Overview

创建了一个 PowerShell 自动化脚本 release.ps1,实现"一气呵成"的发布流程:自动修改 csproj 版本号、提交代码并创建 Tag。

Added a PowerShell automation script release.ps1 that provides a seamless one-command release workflow: automatically updates csproj version, commits changes, and creates tags.

📦 新增内容 / What's New

1. release.ps1 - 发布自动化脚本

一个功能完整的 PowerShell 脚本(299 行),支持跨平台使用(Windows/Linux/macOS)。

核心功能 / Core Features:

  • ✅ 自动更新 Chsword.Excel2Object.csproj 中的版本号
  • ✅ 使用约定式提交格式提交代码:chore: bump version to X.Y.Z
  • ✅ 自动创建 Git Tag:vX.Y.Z
  • ✅ 推送代码和 Tag 到远程仓库

安全检查 / Safety Checks:

  • ✅ 语义化版本格式验证
  • ✅ Tag 冲突检测
  • ✅ 工作目录状态检查
  • ✅ 用户确认提示

使用示例 / Usage Examples:

# 基本用法 - 发布新版本
.\release.ps1 -Version 2.0.4

# 仅本地提交,不推送到远程
.\release.ps1 -Version 2.0.4 -SkipPush

# 跳过确认提示,直接执行
.\release.ps1 -Version 2.0.4 -Force

2. RELEASE_SCRIPT_GUIDE.md - 详细使用指南

双语(中英文)使用文档,包含:

  • 前置要求和安装说明
  • 快速开始示例
  • 参数详细说明
  • 常见问题解决方案

Bilingual (EN/CN) comprehensive guide with prerequisites, quick start, parameter descriptions, and troubleshooting.

3. 更新现有文档 / Updated Documentation

  • RELEASE_AUTOMATION.md - 添加了脚本详细说明和使用示例
  • README.md / README_EN.md - 添加了快速发布章节,引导用户使用新脚本

🎯 解决的问题 / Problem Solved

Issue 要求 / Issue Requirement:

创建一个脚本,支持 powershell,作用是修改csproj的版本,提交代码、提交Tag,一气呵成

解决方案 / Solution:

脚本将原本需要多个手动步骤的发布流程:

# 之前:需要手动执行 4-5 个步骤
1. 编辑 Chsword.Excel2Object.csproj,修改版本号
2. git add .
3. git commit -m "chore: bump version to 2.0.4"
4. git tag v2.0.4
5. git push origin main
6. git push origin v2.0.4

简化为一条命令:

# 现在:一条命令完成所有操作
.\release.ps1 -Version 2.0.4

🔍 技术亮点 / Technical Highlights

  1. 跨平台兼容 - 支持 Windows PowerShell 5.1+ 和 PowerShell Core 7+
  2. 彩色输出 - 使用不同颜色区分信息类型(成功/错误/警告/提示)
  3. 完善的错误处理 - 捕获并友好地显示各类错误
  4. 灵活的参数 - 支持本地模式、强制模式等不同使用场景
  5. 详细的进度显示 - 实时显示每个步骤的执行状态

🧪 测试验证 / Testing

  • ✅ PowerShell 语法验证通过
  • ✅ 版本格式验证功能正常(拒绝无效格式)
  • ✅ 完整工作流测试通过(使用 -SkipPush -Force 标志)
  • ✅ 安全检查功能验证(Tag 冲突检测、工作目录状态检查)
  • ✅ 错误处理机制正常工作

📝 相关文档 / Related Documentation

💡 使用建议 / Recommendations

发布新版本时,推荐使用此脚本替代手动操作:

# 推荐的发布流程
1. 更新代码和测试
2. 更新 README 发布说明
3. 运行脚本:.\release.ps1 -Version X.Y.Z
4. 等待 GitHub Actions 自动构建和发布

此脚本显著提升了发布效率,减少了人为错误,使版本发布过程更加标准化和可靠。

This script significantly improves release efficiency, reduces human error, and makes the version release process more standardized and reliable.

Original prompt

创建一个脚本 ,支持 powershell ,作用是 修改csproj 的版本,提交 代码、提交Tag,一气呵成


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 11, 2025 13:40
Co-authored-by: chsword <274085+chsword@users.noreply.github.com>
Co-authored-by: chsword <274085+chsword@users.noreply.github.com>
Copilot AI changed the title [WIP] Add PowerShell script to modify csproj version and commit changes feat: add PowerShell release automation script for one-command releases Oct 11, 2025
Copilot AI requested a review from chsword October 11, 2025 13:44
@chsword chsword marked this pull request as ready for review October 11, 2025 14:37
Copilot AI review requested due to automatic review settings October 11, 2025 14:37
@chsword chsword merged commit 1b749e4 into main Oct 11, 2025
7 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive PowerShell-based release automation system for the Excel2Object project, enabling one-command releases that automatically update version numbers, commit changes, and create tags.

  • Adds a PowerShell script release.ps1 that automates the entire release workflow
  • Provides comprehensive bilingual documentation for the release automation system
  • Updates README files to include quick release instructions for improved developer experience

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
release.ps1 Main PowerShell automation script with cross-platform support and comprehensive error handling
RELEASE_SCRIPT_GUIDE.md Bilingual usage guide with examples, parameters, and troubleshooting
RELEASE_AUTOMATION.md Updated automation documentation with script integration details
README_EN.md Added quick release section referencing the automation script
README.md Added quick release section referencing the automation script

Comment on lines +102 to +103
if (-not (Test-Path $csprojPath)) {
throw "找不到项目文件: $csprojPath"
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded path Chsword.Excel2Object/Chsword.Excel2Object.csproj should be made configurable or detected dynamically. Consider adding a parameter to specify the project file path or automatically discovering .csproj files in the repository.

Copilot uses AI. Check for mistakes.
$content = Get-Content $csprojPath -Raw
$newContent = $content -replace '<Version>[^<]+</Version>', "<Version>$NewVersion</Version>"

Set-Content -Path $csprojPath -Value $newContent -NoNewline
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using -NoNewline might cause issues if the original file had a trailing newline. This could lead to formatting inconsistencies or merge conflicts. Consider preserving the original file's newline behavior.

Suggested change
Set-Content -Path $csprojPath -Value $newContent -NoNewline
Set-Content -Path $csprojPath -Value $newContent

Copilot uses AI. Check for mistakes.
Comment on lines +141 to +147
try {
git rev-parse --git-dir 2>&1 | Out-Null
return $LASTEXITCODE -eq 0
}
catch {
return $false
}
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error redirection 2>&1 | Out-Null followed by checking $LASTEXITCODE is unnecessary since the try-catch block already handles errors. Consider simplifying to just git rev-parse --git-dir | Out-Null; return $true in the try block.

Copilot uses AI. Check for mistakes.
@chsword
Copy link
Owner

chsword commented Oct 11, 2025

所在位置 C:\Github\Excel2Object\release.ps1:120 字符: 20

  • $csprojPath = "Chsword.Excel2Object/Chsword.Excel2Object.csproj"
    
  •                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

表达式或语句中包含意外的标记“Chsword.Excel2Object/Chsword.Excel2Object.csproj"

$content = Get-Content $csprojPath -Raw
$newContent = $content -replace '<Version>[^<]+</Version>', "<Version>$NewVersion</Version>"

Set-Content -Path $csprojPath -Value $newContent -NoNewline

Write-Success "鐗堟湰鍙峰凡鏇存柊涓?”。

所在位置 C:\Github\Excel2Object\release.ps1:182 字符: 39

  • if ($currentVersion -eq $Version) {
    
  •                                   ~
    

语句块或类型定义中缺少右“}”。
所在位置 C:\Github\Excel2Object\release.ps1:185 字符: 47

  •         $continue = Read-Host "鏄惁缁х画锛?y/N)"
    
  •                                           ~
    

表达式或语句中包含意外的标记“)”。
所在位置 C:\Github\Excel2Object\release.ps1:187 字符: 29

  •             Write-Info "鎿嶄綔宸插彇娑堛€?
    
  •                         ~~~~~~~~~~
    

表达式或语句中包含意外的标记“鎿嶄綔宸插彇娑堛€?”。
所在位置 C:\Github\Excel2Object\release.ps1:189 字符: 13

  •         }
    
  •         ~
    

表达式或语句中包含意外的标记“}”。
所在位置 C:\Github\Excel2Object\release.ps1:190 字符: 9

  •     }
    
  •     ~
    

表达式或语句中包含意外的标记“}”。
所在位置 C:\Github\Excel2Object\release.ps1:191 字符: 5

  • }
    
  • ~
    

表达式或语句中包含意外的标记“}”。
所在位置 C:\Github\Excel2Object\release.ps1:219 字符: 22

  • if (-not $Force) {
    
  •                  ~
    

语句块或类型定义中缺少右“}”。
所在位置 C:\Github\Excel2Object\release.ps1:199 字符: 26

  •     if (-not $Force) {
    
  •                      ~
    

语句块或类型定义中缺少右“}”。
所在位置 C:\Github\Excel2Object\release.ps1:194 字符: 31

  • if (-not (Test-GitClean)) {
    
  •                           ~
    

语句块或类型定义中缺少右“}”。
并未报告所有分析错误。请更正报告的错误并重试。
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments