From c3b2a1c8b75d782e6b0356e4bbb6178216e032c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Oct 2025 13:32:31 +0000 Subject: [PATCH 1/3] Initial plan From 07209efa56ffb3ddefee0680b10919133d62bf0c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Oct 2025 13:40:46 +0000 Subject: [PATCH 2/3] feat: add PowerShell release automation script Co-authored-by: chsword <274085+chsword@users.noreply.github.com> --- README.md | 15 +++ README_EN.md | 15 +++ RELEASE_AUTOMATION.md | 87 ++++++++++++ release.ps1 | 299 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 416 insertions(+) create mode 100644 release.ps1 diff --git a/README.md b/README.md index 1d18e0c..bbc57b1 100644 --- a/README.md +++ b/README.md @@ -235,11 +235,26 @@ var bytes = ExcelHelper.ObjectToExcelBytes(models, options => ## 开发和发布 +- **[自动化发布脚本 `release.ps1`](release.ps1)** - 一键完成版本更新、提交和 Tag 创建的 PowerShell 脚本 - **[自动化发布系统说明](RELEASE_AUTOMATION.md)** - 包含 Copilot 指令、版本管理和自动发布流程的完整说明 - **[版本管理规范](.github/VERSIONING.md)** - 语义化版本规范和版本号递增规则 - **[发布流程指南](.github/RELEASE_GUIDE.md)** - 详细的发布步骤和故障排查指南 - **[Copilot 使用说明](.github/copilot-instructions.md)** - GitHub Copilot 开发指导和项目规范 +### 快速发布新版本 + +使用自动化脚本一键发布: + +```powershell +# Windows +.\release.ps1 -Version 2.0.4 + +# Linux/macOS (需要 PowerShell Core) +pwsh ./release.ps1 -Version 2.0.4 +``` + +详细说明请参阅 [RELEASE_AUTOMATION.md](RELEASE_AUTOMATION.md)。 + ## 贡献者 [![Contributors](https://contrib.rocks/image?repo=chsword/Excel2Object)](https://github.com/chsword/Excel2Object/graphs/contributors) diff --git a/README_EN.md b/README_EN.md index d163aaa..6a4fbbf 100644 --- a/README_EN.md +++ b/README_EN.md @@ -232,11 +232,26 @@ For more information, please visit: http://www.cnblogs.com/chsword/p/excel2objec ## Development and Release +- **[Automated Release Script `release.ps1`](release.ps1)** - PowerShell script for one-click version update, commit, and tag creation - **[Automated Release System Documentation](RELEASE_AUTOMATION.md)** - Complete guide including Copilot instructions, version management, and automated release workflow - **[Versioning Guidelines](.github/VERSIONING.md)** - Semantic versioning specification and version increment rules - **[Release Process Guide](.github/RELEASE_GUIDE.md)** - Detailed release steps and troubleshooting guide - **[Copilot Instructions](.github/copilot-instructions.md)** - GitHub Copilot development guidelines and project conventions +### Quick Release + +Use the automation script for one-click release: + +```powershell +# Windows +.\release.ps1 -Version 2.0.4 + +# Linux/macOS (PowerShell Core required) +pwsh ./release.ps1 -Version 2.0.4 +``` + +See [RELEASE_AUTOMATION.md](RELEASE_AUTOMATION.md) for detailed instructions. + ## Contributors [![Contributors](https://contrib.rocks/image?repo=chsword/Excel2Object)](https://github.com/chsword/Excel2Object/graphs/contributors) diff --git a/RELEASE_AUTOMATION.md b/RELEASE_AUTOMATION.md index f3c1179..ea6aa5f 100644 --- a/RELEASE_AUTOMATION.md +++ b/RELEASE_AUTOMATION.md @@ -101,6 +101,32 @@ graph TD ### 发布新版本 / Releasing a New Version +#### 方法一:使用自动化脚本(推荐)/ Method 1: Using Automation Script (Recommended) + +**一键发布 / One-Click Release**: + +```powershell +# Windows +.\release.ps1 -Version 2.0.4 + +# Linux/macOS (需要 PowerShell Core) +pwsh ./release.ps1 -Version 2.0.4 +``` + +该脚本会自动完成以下所有步骤 / This script automatically completes all the following steps: +- ✓ 更新 csproj 版本号 / Update csproj version +- ✓ 提交代码 / Commit changes +- ✓ 创建 Tag / Create tag +- ✓ 推送到远程仓库 / Push to remote + +详细参数和用法请参阅 [工具和脚本](#工具和脚本--tools-and-scripts) 章节。 + +See [Tools and Scripts](#工具和脚本--tools-and-scripts) section for detailed parameters and usage. + +--- + +#### 方法二:手动发布 / Method 2: Manual Release + **步骤 / Steps**: 1. **更新版本号** / Update Version Number @@ -229,6 +255,67 @@ GitHub 仓库 → Settings → Environments → New environment ## 🛠️ 工具和脚本 / Tools and Scripts +### 自动化发布脚本 / Automated Release Script + +**脚本位置 / Script Location**: `release.ps1` + +这是一个 PowerShell 脚本,可以一键完成版本更新、代码提交和 Tag 创建的全部流程。 + +This is a PowerShell script that automates the entire process of version update, code commit, and tag creation. + +**基本用法 / Basic Usage**: + +```powershell +# Windows +.\release.ps1 -Version 2.0.4 + +# Linux/macOS (需要安装 PowerShell Core) +pwsh ./release.ps1 -Version 2.0.4 +``` + +**参数说明 / Parameters**: + +| 参数 | 必需 | 说明 | +|------|------|------| +| `-Version` | 是 | 新版本号,格式:主版本.次版本.修订版 (例如: 2.0.3) | +| `-SkipPush` | 否 | 仅创建本地提交和标签,不推送到远程仓库 | +| `-Force` | 否 | 强制执行,跳过所有确认提示 | + +**使用示例 / Examples**: + +```powershell +# 发布新版本 2.0.4(会提示确认) +.\release.ps1 -Version 2.0.4 + +# 仅本地提交,不推送到远程 +.\release.ps1 -Version 2.1.0 -SkipPush + +# 强制执行,跳过确认提示 +.\release.ps1 -Version 3.0.0 -Force + +# 组合参数使用 +.\release.ps1 -Version 2.0.5 -SkipPush -Force +``` + +**脚本执行流程 / Script Workflow**: + +1. ✓ 验证版本号格式(必须符合语义化版本) +2. ✓ 检查 Git 仓库状态 +3. ✓ 检查 Tag 是否已存在 +4. ✓ 更新 `Chsword.Excel2Object.csproj` 中的版本号 +5. ✓ 提交代码:`git commit -m "chore: bump version to X.Y.Z"` +6. ✓ 创建 Git Tag:`git tag vX.Y.Z` +7. ✓ 推送到远程仓库(除非使用 `-SkipPush`) + +**注意事项 / Notes**: + +- 脚本会自动检查工作目录是否有未提交的更改 +- 如果 Tag 已存在,脚本会报错并提示如何删除 +- 推送后会自动触发 GitHub Actions 的发布流程 +- Windows 用户可能需要设置 PowerShell 执行策略:`Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser` + +--- + ### 本地测试 NuGet 包构建 / Test NuGet Package Build Locally ```bash diff --git a/release.ps1 b/release.ps1 new file mode 100644 index 0000000..1ffca0c --- /dev/null +++ b/release.ps1 @@ -0,0 +1,299 @@ +#!/usr/bin/env pwsh +<# +.SYNOPSIS + 自动化发布脚本 - 更新版本号、提交代码、创建并推送Tag + Release automation script - Update version, commit changes, create and push tag + +.DESCRIPTION + 该脚本自动执行以下操作: + 1. 更新 Chsword.Excel2Object.csproj 中的版本号 + 2. 提交代码到 Git 仓库 + 3. 创建 Git Tag (格式: v{version}) + 4. 推送代码和 Tag 到远程仓库 + + This script automates the following operations: + 1. Update version in Chsword.Excel2Object.csproj + 2. Commit changes to Git repository + 3. Create Git Tag (format: v{version}) + 4. Push code and tag to remote repository + +.PARAMETER Version + 新版本号,格式:主版本.次版本.修订版 (例如: 2.0.3) + New version number, format: Major.Minor.Patch (e.g., 2.0.3) + +.PARAMETER SkipPush + 仅创建本地提交和标签,不推送到远程仓库 + Only create local commits and tags, do not push to remote + +.PARAMETER Force + 强制执行,跳过确认提示 + Force execution, skip confirmation prompts + +.EXAMPLE + ./release.ps1 -Version 2.0.3 + 更新版本到 2.0.3,提交并推送 + +.EXAMPLE + ./release.ps1 -Version 2.1.0 -SkipPush + 更新版本到 2.1.0,仅本地提交,不推送 + +.EXAMPLE + ./release.ps1 -Version 3.0.0 -Force + 强制更新版本到 3.0.0,跳过确认提示 +#> + +param( + [Parameter(Mandatory = $true, HelpMessage = "版本号 (例如: 2.0.3)")] + [string]$Version, + + [Parameter(Mandatory = $false)] + [switch]$SkipPush, + + [Parameter(Mandatory = $false)] + [switch]$Force +) + +# 设置错误处理 +$ErrorActionPreference = "Stop" + +# 颜色输出函数 +function Write-ColorOutput { + param( + [string]$Message, + [string]$Color = "White" + ) + Write-Host $Message -ForegroundColor $Color +} + +function Write-Success { + param([string]$Message) + Write-ColorOutput "✓ $Message" "Green" +} + +function Write-Error { + param([string]$Message) + Write-ColorOutput "✗ $Message" "Red" +} + +function Write-Info { + param([string]$Message) + Write-ColorOutput "ℹ $Message" "Cyan" +} + +function Write-Warning { + param([string]$Message) + Write-ColorOutput "⚠ $Message" "Yellow" +} + +# 验证版本号格式 (语义化版本) +function Test-VersionFormat { + param([string]$Ver) + + if ($Ver -match '^\d+\.\d+\.\d+$') { + return $true + } + return $false +} + +# 提取当前版本号 +function Get-CurrentVersion { + $csprojPath = "Chsword.Excel2Object/Chsword.Excel2Object.csproj" + + if (-not (Test-Path $csprojPath)) { + throw "找不到项目文件: $csprojPath" + } + + $content = Get-Content $csprojPath -Raw + if ($content -match '([^<]+)') { + return $Matches[1] + } + + throw "无法从项目文件中提取版本号" +} + +# 更新版本号 +function Update-Version { + param( + [string]$NewVersion + ) + + $csprojPath = "Chsword.Excel2Object/Chsword.Excel2Object.csproj" + + $content = Get-Content $csprojPath -Raw + $newContent = $content -replace '[^<]+', "$NewVersion" + + Set-Content -Path $csprojPath -Value $newContent -NoNewline + + Write-Success "版本号已更新为: $NewVersion" +} + +# 检查 Git 状态 +function Test-GitClean { + $status = git status --porcelain + if ($status) { + return $false + } + return $true +} + +# 检查是否在 Git 仓库中 +function Test-GitRepository { + try { + git rev-parse --git-dir 2>&1 | Out-Null + return $LASTEXITCODE -eq 0 + } + catch { + return $false + } +} + +# 检查 Tag 是否已存在 +function Test-TagExists { + param([string]$TagName) + + $tags = git tag -l $TagName + return ($tags -eq $TagName) +} + +# 主流程 +try { + Write-Info "===== Excel2Object 自动化发布脚本 =====" + Write-Info "" + + # 验证版本号格式 + if (-not (Test-VersionFormat -Ver $Version)) { + Write-Error "版本号格式错误!请使用语义化版本格式 (例如: 2.0.3)" + exit 1 + } + + # 检查是否在 Git 仓库中 + if (-not (Test-GitRepository)) { + Write-Error "当前目录不是 Git 仓库!" + exit 1 + } + + # 获取当前版本 + $currentVersion = Get-CurrentVersion + Write-Info "当前版本: $currentVersion" + Write-Info "目标版本: $Version" + Write-Info "" + + # 检查版本是否相同 + if ($currentVersion -eq $Version) { + Write-Warning "目标版本与当前版本相同,无需更新。" + if (-not $Force) { + $continue = Read-Host "是否继续?(y/N)" + if ($continue -ne 'y' -and $continue -ne 'Y') { + Write-Info "操作已取消。" + exit 0 + } + } + } + + # 检查工作目录是否干净 + if (-not (Test-GitClean)) { + Write-Warning "工作目录有未提交的更改!" + git status --short + Write-Info "" + + if (-not $Force) { + $continue = Read-Host "是否继续?这将提交所有更改 (y/N)" + if ($continue -ne 'y' -and $continue -ne 'Y') { + Write-Info "操作已取消。" + exit 0 + } + } + } + + # 检查 Tag 是否已存在 + $tagName = "v$Version" + if (Test-TagExists -TagName $tagName) { + Write-Error "Tag '$tagName' 已存在!" + Write-Info "请使用不同的版本号或删除现有 Tag:" + Write-Info " git tag -d $tagName" + Write-Info " git push origin :refs/tags/$tagName" + exit 1 + } + + # 确认操作 + if (-not $Force) { + Write-Info "" + Write-Warning "即将执行以下操作:" + Write-Info " 1. 更新版本号: $currentVersion → $Version" + Write-Info " 2. 提交更改: 'chore: bump version to $Version'" + Write-Info " 3. 创建 Tag: $tagName" + if (-not $SkipPush) { + Write-Info " 4. 推送到远程仓库" + } + Write-Info "" + + $confirm = Read-Host "确认执行?(y/N)" + if ($confirm -ne 'y' -and $confirm -ne 'Y') { + Write-Info "操作已取消。" + exit 0 + } + Write-Info "" + } + + # 步骤 1: 更新版本号 + Write-Info "步骤 1/4: 更新版本号..." + Update-Version -NewVersion $Version + + # 步骤 2: 提交更改 + Write-Info "步骤 2/4: 提交更改..." + git add . + git commit -m "chore: bump version to $Version" + Write-Success "代码已提交" + + # 步骤 3: 创建 Tag + Write-Info "步骤 3/4: 创建 Tag..." + git tag $tagName + Write-Success "Tag '$tagName' 已创建" + + # 步骤 4: 推送到远程 + if (-not $SkipPush) { + Write-Info "步骤 4/4: 推送到远程仓库..." + + # 获取当前分支 + $currentBranch = git rev-parse --abbrev-ref HEAD + + # 推送代码 + Write-Info "推送分支 '$currentBranch'..." + git push origin $currentBranch + Write-Success "代码已推送到 origin/$currentBranch" + + # 推送 Tag + Write-Info "推送 Tag '$tagName'..." + git push origin $tagName + Write-Success "Tag 已推送" + } + else { + Write-Info "步骤 4/4: 跳过推送 (使用了 -SkipPush 参数)" + Write-Warning "请手动推送代码和 Tag:" + Write-Info " git push origin $(git rev-parse --abbrev-ref HEAD)" + Write-Info " git push origin $tagName" + } + + # 完成 + Write-Info "" + Write-Success "===== 发布流程完成 =====" + Write-Info "" + Write-Info "版本 $Version 已准备就绪!" + + if (-not $SkipPush) { + Write-Info "" + Write-Info "GitHub Actions 将自动开始构建和发布流程:" + Write-Info " → https://github.com/chsword/Excel2Object/actions" + Write-Info "" + Write-Info "预计 5-10 分钟后可在以下位置查看发布结果:" + Write-Info " → NuGet: https://www.nuget.org/packages/Chsword.Excel2Object" + Write-Info " → GitHub: https://github.com/chsword/Excel2Object/releases" + } +} +catch { + Write-Error "发生错误: $_" + Write-Info "" + Write-Info "如需帮助,请查看文档:" + Write-Info " → RELEASE_AUTOMATION.md" + exit 1 +} From 934e97f803fa715076a91573edbc48e4526458ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Oct 2025 13:42:05 +0000 Subject: [PATCH 3/3] docs: add comprehensive release script usage guide Co-authored-by: chsword <274085+chsword@users.noreply.github.com> --- RELEASE_AUTOMATION.md | 2 + RELEASE_SCRIPT_GUIDE.md | 167 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 RELEASE_SCRIPT_GUIDE.md diff --git a/RELEASE_AUTOMATION.md b/RELEASE_AUTOMATION.md index ea6aa5f..852646e 100644 --- a/RELEASE_AUTOMATION.md +++ b/RELEASE_AUTOMATION.md @@ -259,6 +259,8 @@ GitHub 仓库 → Settings → Environments → New environment **脚本位置 / Script Location**: `release.ps1` +**详细指南 / Detailed Guide**: 📖 [RELEASE_SCRIPT_GUIDE.md](RELEASE_SCRIPT_GUIDE.md) + 这是一个 PowerShell 脚本,可以一键完成版本更新、代码提交和 Tag 创建的全部流程。 This is a PowerShell script that automates the entire process of version update, code commit, and tag creation. diff --git a/RELEASE_SCRIPT_GUIDE.md b/RELEASE_SCRIPT_GUIDE.md new file mode 100644 index 0000000..e81b9c2 --- /dev/null +++ b/RELEASE_SCRIPT_GUIDE.md @@ -0,0 +1,167 @@ +# Release Script Usage Guide / 发布脚本使用指南 + +## English + +### Prerequisites + +- **Windows**: PowerShell 5.1 or later (comes with Windows 10/11) +- **Linux/macOS**: PowerShell Core 7.0+ ([Install PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell)) + +### Quick Start + +```powershell +# Release a new version +.\release.ps1 -Version 2.0.4 +``` + +The script will: +1. ✓ Validate version format +2. ✓ Update version in `.csproj` file +3. ✓ Commit changes +4. ✓ Create git tag +5. ✓ Push to remote repository + +### Usage Examples + +#### Basic Release +```powershell +.\release.ps1 -Version 2.0.4 +``` +This will prompt for confirmation before each major step. + +#### Local-Only Release +```powershell +.\release.ps1 -Version 2.0.4 -SkipPush +``` +Creates commit and tag locally, but doesn't push to remote. + +#### Force Release (No Confirmations) +```powershell +.\release.ps1 -Version 2.0.4 -Force +``` +Skips all confirmation prompts. + +#### Combined Flags +```powershell +.\release.ps1 -Version 2.0.4 -SkipPush -Force +``` +Creates local commit/tag without pushing, no confirmations. + +### Parameters + +| Parameter | Required | Description | +|-----------|----------|-------------| +| `-Version` | Yes | Version number in format: `Major.Minor.Patch` (e.g., `2.0.4`) | +| `-SkipPush` | No | Create local commits and tags only, don't push to remote | +| `-Force` | No | Skip all confirmation prompts | + +### Troubleshooting + +#### Error: "Tag already exists" +```powershell +# Delete local and remote tag +git tag -d v2.0.4 +git push origin :refs/tags/v2.0.4 + +# Then run the script again +.\release.ps1 -Version 2.0.4 +``` + +#### Error: "Execution policy" +On Windows, you might need to allow script execution: +```powershell +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +``` + +#### Get Help +```powershell +Get-Help .\release.ps1 -Detailed +``` + +--- + +## 中文 + +### 前置要求 + +- **Windows**: PowerShell 5.1 或更高版本(Windows 10/11 自带) +- **Linux/macOS**: PowerShell Core 7.0+ ([安装 PowerShell](https://docs.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell)) + +### 快速开始 + +```powershell +# 发布新版本 +.\release.ps1 -Version 2.0.4 +``` + +脚本将执行: +1. ✓ 验证版本号格式 +2. ✓ 更新 `.csproj` 文件中的版本号 +3. ✓ 提交更改 +4. ✓ 创建 git 标签 +5. ✓ 推送到远程仓库 + +### 使用示例 + +#### 基本发布 +```powershell +.\release.ps1 -Version 2.0.4 +``` +在每个主要步骤前会提示确认。 + +#### 仅本地发布 +```powershell +.\release.ps1 -Version 2.0.4 -SkipPush +``` +在本地创建提交和标签,但不推送到远程。 + +#### 强制发布(无确认) +```powershell +.\release.ps1 -Version 2.0.4 -Force +``` +跳过所有确认提示。 + +#### 组合参数 +```powershell +.\release.ps1 -Version 2.0.4 -SkipPush -Force +``` +创建本地提交/标签但不推送,无确认提示。 + +### 参数说明 + +| 参数 | 必需 | 说明 | +|------|------|------| +| `-Version` | 是 | 版本号格式:`主版本.次版本.修订版`(例如:`2.0.4`)| +| `-SkipPush` | 否 | 仅创建本地提交和标签,不推送到远程 | +| `-Force` | 否 | 跳过所有确认提示 | + +### 故障排除 + +#### 错误:"Tag 已存在" +```powershell +# 删除本地和远程标签 +git tag -d v2.0.4 +git push origin :refs/tags/v2.0.4 + +# 然后重新运行脚本 +.\release.ps1 -Version 2.0.4 +``` + +#### 错误:"执行策略" +在 Windows 上,您可能需要允许脚本执行: +```powershell +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +``` + +#### 获取帮助 +```powershell +Get-Help .\release.ps1 -Detailed +``` + +--- + +## See Also / 另见 + +- [RELEASE_AUTOMATION.md](RELEASE_AUTOMATION.md) - Complete release automation documentation +- [.github/VERSIONING.md](.github/VERSIONING.md) - Versioning guidelines +- [.github/RELEASE_GUIDE.md](.github/RELEASE_GUIDE.md) - Detailed release process guide