improve:GitHub工作流

This commit is contained in:
2025-12-13 21:02:11 +08:00
parent 441f8b6e26
commit e9fde97453
+20 -11
View File
@@ -12,6 +12,7 @@ on:
- patch - patch
- minor - minor
- major - major
- build
prerelease: prerelease:
description: 'Create as pre-release' description: 'Create as pre-release'
required: true required: true
@@ -51,7 +52,7 @@ jobs:
echo "Found latest tag: $latestTag" echo "Found latest tag: $latestTag"
} else { } else {
# 如果没有tag,使用默认版本 # 如果没有tag,使用默认版本
$version = "1.0.0" $version = "1.0.0.0"
echo "No tags found, using default version" echo "No tags found, using default version"
} }
echo "current_version=$version" >> $env:GITHUB_OUTPUT echo "current_version=$version" >> $env:GITHUB_OUTPUT
@@ -63,16 +64,18 @@ jobs:
$currentVersion = "${{ steps.get_version.outputs.current_version }}" $currentVersion = "${{ steps.get_version.outputs.current_version }}"
$versionParts = $currentVersion.Split('.') $versionParts = $currentVersion.Split('.')
# 确保版本号格式正确(至少3部分) # 确保版本号格式正确(支持4部分)
if ($versionParts.Length -ge 3) { if ($versionParts.Length -ge 3) {
$major = [int]$versionParts[0] $major = [int]$versionParts[0]
$minor = [int]$versionParts[1] $minor = [int]$versionParts[1]
$patch = [int]$versionParts[2] $patch = [int]$versionParts[2]
$build = [int]$versionParts[3]
} else { } else {
# 如果版本号格式不正确,使用默认值 # 如果版本号格式不正确,使用默认值
$major = 1 $major = 1
$minor = 0 $minor = 0
$patch = 0 $patch = 0
$build = 0
} }
$versionType = "${{ github.event.inputs.version_type }}" $versionType = "${{ github.event.inputs.version_type }}"
@@ -82,18 +85,24 @@ jobs:
$major++ $major++
$minor = 0 $minor = 0
$patch = 0 $patch = 0
$build = 0
} }
"minor" { "minor" {
$minor++ $minor++
$patch = 0 $patch = 0
$build = 0
} }
"patch" { "patch" {
$patch++ $patch++
$build = 0
}
"build" {
$build++
} }
} }
# 生成新版本号(保持3位格式,如1.7.13 # 生成新版本号(4位格式,如1.7.18.0
$newVersion = "$major.$minor.$patch" $newVersion = "$major.$minor.$patch.$build"
echo "new_version=$newVersion" >> $env:GITHUB_OUTPUT echo "new_version=$newVersion" >> $env:GITHUB_OUTPUT
echo "New version: $newVersion" echo "New version: $newVersion"
@@ -150,7 +159,7 @@ jobs:
# 生成changelog内容 # 生成changelog内容
$version = "${{ steps.calc_version.outputs.new_version }}" $version = "${{ steps.calc_version.outputs.new_version }}"
$changelog = "# ICC CE $version.0 更新日志`n`n## 修复 (Fixes)" $changelog = "# ICC CE $version 更新日志`n`n## 修复 (Fixes)"
if ($fixes.Count -gt 0) { if ($fixes.Count -gt 0) {
foreach ($fix in $fixes) { foreach ($fix in $fixes) {
@@ -236,7 +245,7 @@ jobs:
- name: Create Release Archive - name: Create Release Archive
run: | run: |
$version = "${{ steps.calc_version.outputs.new_version }}" $version = "${{ steps.calc_version.outputs.new_version }}"
$archiveName = "InkCanvasForClass.CE.$version.0.zip" $archiveName = "InkCanvasForClass.CE.$version.zip"
# 创建发布目录 # 创建发布目录
New-Item -ItemType Directory -Path "release" -Force New-Item -ItemType Directory -Path "release" -Force
@@ -254,7 +263,7 @@ jobs:
with: with:
name: release-files-${{ steps.calc_version.outputs.new_version }} name: release-files-${{ steps.calc_version.outputs.new_version }}
path: | path: |
InkCanvasForClass.CE.${{ steps.calc_version.outputs.new_version }}.0.zip InkCanvasForClass.CE.${{ steps.calc_version.outputs.new_version }}.zip
CHANGELOG_${{ steps.calc_version.outputs.new_version }}.md CHANGELOG_${{ steps.calc_version.outputs.new_version }}.md
- name: Prepare Release Info - name: Prepare Release Info
@@ -265,14 +274,14 @@ jobs:
- name: Create GitHub Release - name: Create GitHub Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
tag_name: ${{ steps.calc_version.outputs.new_version }}.0 tag_name: ${{ steps.calc_version.outputs.new_version }}
name: ICC CE ${{ steps.calc_version.outputs.new_version }}.0 name: ICC CE ${{ steps.calc_version.outputs.new_version }}
body: | body: |
${{ steps.changelog.outputs.changelog }} ${{ steps.changelog.outputs.changelog }}
draft: false draft: false
prerelease: ${{ github.event.inputs.prerelease }} prerelease: ${{ github.event.inputs.prerelease }}
files: | files: |
InkCanvasForClass.CE.${{ steps.calc_version.outputs.new_version }}.0.zip InkCanvasForClass.CE.${{ steps.calc_version.outputs.new_version }}.zip
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -285,7 +294,7 @@ jobs:
$changelogContent = Get-Content $changelogFile -Raw $changelogContent = Get-Content $changelogFile -Raw
# 生成预览内容 # 生成预览内容
$previewContent = "ICC CE $version.0 更新日志`n" + $changelogContent $previewContent = "ICC CE $version 更新日志`n" + $changelogContent
echo "UpdateLog preview generated (not written to file):" echo "UpdateLog preview generated (not written to file):"
echo $previewContent echo $previewContent