Skip to content

Commit c2966f8

Browse files
committed
📝 docs: 准备发布 v0.2.0
1 parent 6246a31 commit c2966f8

File tree

6 files changed

+542
-12
lines changed

6 files changed

+542
-12
lines changed

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
release:
10+
runs-on: windows-latest
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Get version from tag
19+
id: get_version
20+
shell: pwsh
21+
run: |
22+
$tag = $env:GITHUB_REF -replace 'refs/tags/', ''
23+
echo "version=$tag" >> $env:GITHUB_OUTPUT
24+
echo "Version: $tag"
25+
26+
- name: Read release notes
27+
id: release_notes
28+
shell: pwsh
29+
run: |
30+
$body = Get-Content -Raw -Path "docs/RELEASE.md" -ErrorAction SilentlyContinue
31+
if (-not $body) {
32+
$body = "Release notes not found."
33+
}
34+
# 转义特殊字符
35+
$body = $body -replace "'", "''"
36+
# 使用 heredoc 语法
37+
$heredoc = "body<<EOF`n$body`nEOF"
38+
Add-Content -Path $env:GITHUB_OUTPUT -Value $heredoc
39+
40+
- name: Find installation file
41+
id: find_file
42+
shell: pwsh
43+
run: |
44+
$version = "${{ steps.get_version.outputs.version }}"
45+
# 尝试 .upx 和 .upxs 两种扩展名
46+
$fileNames = @(
47+
"git commit helper-$version.upxs",
48+
"git commit helper-$version.upx"
49+
)
50+
# 在项目根目录的 build 文件夹中查找
51+
$basePath = "build"
52+
53+
$foundFile = $null
54+
foreach ($fileName in $fileNames) {
55+
$filePath = Join-Path $basePath $fileName
56+
Write-Host "Looking for: $filePath"
57+
58+
if (Test-Path $filePath) {
59+
Write-Host "✅ Found: $filePath"
60+
$foundFile = @{
61+
path = $filePath
62+
name = $fileName
63+
}
64+
break
65+
}
66+
}
67+
68+
if ($foundFile) {
69+
echo "file_path=$($foundFile.path)" >> $env:GITHUB_OUTPUT
70+
echo "file_name=$($foundFile.name)" >> $env:GITHUB_OUTPUT
71+
echo "found=true" >> $env:GITHUB_OUTPUT
72+
} else {
73+
Write-Host "❌ File not found in: $basePath"
74+
Write-Host "Tried files:"
75+
$fileNames | ForEach-Object { Write-Host " - $_" }
76+
Write-Host "Please make sure the file exists in the 'build' folder of your repository"
77+
echo "found=false" >> $env:GITHUB_OUTPUT
78+
exit 1
79+
}
80+
81+
- name: Create Release
82+
uses: softprops/action-gh-release@v1
83+
if: steps.find_file.outputs.found == 'true'
84+
with:
85+
name: Release v${{ steps.get_version.outputs.version }}
86+
body: ${{ steps.release_notes.outputs.body }}
87+
draft: false
88+
prerelease: false
89+
files: |
90+
${{ steps.find_file.outputs.file_path }}
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
94+
- name: Upload artifact for verification
95+
if: steps.find_file.outputs.found == 'true'
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: installation-file
99+
path: ${{ steps.find_file.outputs.file_path }}

build/git commit helper-0.2.0.upxs

466 KB
Binary file not shown.

docs/RELEASE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [eeb29a8] 🐛 fix: 添加贡献者和问题id等属性,添加自动分类功能
1313

1414
### 🔧 其他
15+
- [6246a31] 📝 docs: 准备发布 v0.2.0
1516
- [44ca1c8] 📝 docs: 准备发布 v0.2.0
1617
- [7636cb4] 📝 docs: 准备发布 v0.2.0
1718
- [82e2456] 📄 docs: 添加变更日志文件

docs/changelog.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

scripts/generate-release-notes.ps1

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# 生成发布说明脚本
2+
param(
3+
[Parameter(Mandatory = $false)]
4+
[string]$LatestTag,
5+
6+
[Parameter(Mandatory = $false)]
7+
[string]$PreviousTag
8+
)
9+
10+
$ErrorActionPreference = "Stop"
11+
12+
function Get-CommitsBetweenTags {
13+
param($LatestTag, $PreviousTag)
14+
15+
try {
16+
# 检查标签是否存在
17+
$tagExists = git tag -l $LatestTag 2>$null
18+
19+
if (-not $tagExists) {
20+
# 如果标签不存在,获取从上一个标签到HEAD的提交
21+
if ($PreviousTag) {
22+
$commitRange = "$PreviousTag..HEAD"
23+
Write-Host "标签 $LatestTag 不存在,获取从 $PreviousTag 到 HEAD 的提交记录" -ForegroundColor Cyan
24+
}
25+
else {
26+
# 如果没有上一个标签,获取所有提交
27+
$commitRange = "HEAD"
28+
Write-Host "这是第一个版本,获取所有提交记录" -ForegroundColor Cyan
29+
}
30+
}
31+
else {
32+
$commitRange = if ($PreviousTag) {
33+
"$PreviousTag..$LatestTag"
34+
}
35+
else {
36+
$LatestTag
37+
}
38+
Write-Host "获取提交记录范围: $commitRange" -ForegroundColor Cyan
39+
}
40+
41+
$commits = git log $commitRange --pretty=format:"%h|%s" 2>$null
42+
43+
if ($LASTEXITCODE -ne 0) {
44+
Write-Warning "无法获取提交记录"
45+
return @{ feat = @(); fix = @(); others = @() }
46+
}
47+
48+
$commitList = @{
49+
feat = @()
50+
fix = @()
51+
others = @()
52+
}
53+
54+
foreach ($commit in $commits) {
55+
if ([string]::IsNullOrWhiteSpace($commit)) { continue }
56+
57+
$parts = $commit -split '\|', 2
58+
if ($parts.Count -eq 2) {
59+
$hash = $parts[0].Trim()
60+
$message = $parts[1].Trim()
61+
62+
$commitObj = @{
63+
ShortHash = $hash
64+
Message = $message
65+
}
66+
67+
if ($message -match '^✨\s*feat') {
68+
$commitList.feat += $commitObj
69+
}
70+
elseif ($message -match '^🐛\s*fix') {
71+
$commitList.fix += $commitObj
72+
}
73+
else {
74+
$commitList.others += $commitObj
75+
}
76+
}
77+
}
78+
79+
return $commitList
80+
}
81+
catch {
82+
Write-Error "获取提交记录时出错: $_"
83+
exit 1
84+
}
85+
}
86+
87+
function Generate-ReleaseNotes {
88+
param($LatestTag, $PreviousTag, $Commits)
89+
90+
$output = "## 更新内容`n`n"
91+
92+
# 生成 feat 部分
93+
if ($Commits.feat.Count -gt 0) {
94+
$output += "### ✨ 新功能`n"
95+
foreach ($commit in $Commits.feat) {
96+
$output += "- [$($commit.ShortHash)] $($commit.Message)`n"
97+
}
98+
$output += "`n"
99+
}
100+
101+
# 生成 fix 部分
102+
if ($Commits.fix.Count -gt 0) {
103+
$output += "### 🐛 修复`n"
104+
foreach ($commit in $Commits.fix) {
105+
$output += "- [$($commit.ShortHash)] $($commit.Message)`n"
106+
}
107+
$output += "`n"
108+
}
109+
110+
# 生成 others 部分
111+
if ($Commits.others.Count -gt 0) {
112+
$output += "### 🔧 其他`n"
113+
foreach ($commit in $Commits.others) {
114+
$output += "- [$($commit.ShortHash)] $($commit.Message)`n"
115+
}
116+
$output += "`n"
117+
}
118+
119+
# 如果没有任何提交
120+
if ($Commits.feat.Count -eq 0 -and $Commits.fix.Count -eq 0 -and $Commits.others.Count -eq 0) {
121+
$output += "本次发布没有新的提交内容。`n`n"
122+
}
123+
124+
$output += "---`n"
125+
if ($PreviousTag) {
126+
$output += "📋 [查看完整更新日志](https://github.com/caolib/git-commit-helper/compare/$PreviousTag...$LatestTag)`n"
127+
}
128+
else {
129+
$output += "📋 [查看完整更新日志](https://github.com/caolib/git-commit-helper/commits/$LatestTag)`n"
130+
}
131+
132+
return $output
133+
}
134+
135+
# 主逻辑
136+
Write-Host "开始生成发布说明..." -ForegroundColor Green
137+
138+
# 获取标签信息
139+
$allTags = git tag --sort=-v:refname 2>$null | Where-Object { $_ -match '^\d+\.\d+\.\d+$' }
140+
141+
if (-not $LatestTag) {
142+
$LatestTag = $allTags | Select-Object -First 1
143+
}
144+
145+
if (-not $PreviousTag -and $allTags.Count -gt 1) {
146+
$PreviousTag = $allTags | Select-Object -Skip 1 -First 1
147+
}
148+
149+
Write-Host "最新标签: $LatestTag" -ForegroundColor Cyan
150+
if ($PreviousTag) {
151+
Write-Host "上一个标签: $PreviousTag" -ForegroundColor Cyan
152+
}
153+
else {
154+
Write-Host "这是第一个版本" -ForegroundColor Cyan
155+
}
156+
157+
# 获取提交记录
158+
$commits = Get-CommitsBetweenTags -LatestTag $LatestTag -PreviousTag $PreviousTag
159+
160+
# 生成发布说明
161+
$releaseNotes = Generate-ReleaseNotes -LatestTag $LatestTag -PreviousTag $PreviousTag -Commits $commits
162+
163+
# 保存到文件
164+
$outputPath = Join-Path $PSScriptRoot ".." "docs" "RELEASE.md"
165+
$releaseNotes | Out-File -FilePath $outputPath -Encoding UTF8 -NoNewline
166+
167+
Write-Host "✅ 发布说明已保存到: $outputPath" -ForegroundColor Green
168+
Write-Host ""
169+
Write-Host "发布说明内容:" -ForegroundColor Yellow
170+
Write-Host $releaseNotes

0 commit comments

Comments
 (0)