chore: 优化工作流

This commit is contained in:
知一一 2025-05-31 14:42:13 +08:00
parent 6e6319cc93
commit ea90ec9c51
1 changed files with 27 additions and 11 deletions

View File

@ -1,7 +1,7 @@
name: Compile AHK 2.0 and Release name: Compile AHK 2.0 and Release
on: on:
workflow_dispatch: # 允许手动触发 workflow_dispatch:
inputs: inputs:
version_override: version_override:
description: "Override version from AHK script (e.g., v1.0.0)" description: "Override version from AHK script (e.g., v1.0.0)"
@ -27,7 +27,7 @@ jobs:
if ([string]::IsNullOrWhiteSpace($version)) { if ([string]::IsNullOrWhiteSpace($version)) {
if (-not (Test-Path $scriptPath)) { if (-not (Test-Path $scriptPath)) {
Write-Warning "Script file '${scriptPath}' not found for version extraction. Current directory: $(Get-Location)" Write-Warning "Script file '${scriptPath}' not found for version extraction. Current directory: $(Get-Location)"
$version = "0.0.0" # 如果找不到脚本,使用默认版本号 $version = "0.0.0"
} else { } else {
$content = Get-Content -Path $scriptPath -Raw $content = Get-Content -Path $scriptPath -Raw
$match = $content | Select-String -Pattern 'currentVersion\s*:=\s*"([^"]+)"' $match = $content | Select-String -Pattern 'currentVersion\s*:=\s*"([^"]+)"'
@ -95,13 +95,16 @@ jobs:
} }
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
# 在创建标签后,尝试更新一下本地的 Git 标签缓存,以防万一
- name: Fetch all tags again (after potential tag creation)
run: git fetch --tags
- name: Determine if Pre-release - name: Determine if Pre-release
id: prerelease_check id: prerelease_check
shell: bash shell: bash
run: | run: |
VERSION_TAG="${{ steps.get_version.outputs.VERSION_TAG }}" VERSION_TAG="${{ steps.get_version.outputs.VERSION_TAG }}"
IS_PRERELEASE="false" IS_PRERELEASE="false"
# 检查版本号是否包含预发布标识符 (beta, alpha, rc)
if [[ "$VERSION_TAG" == *beta* || "$VERSION_TAG" == *alpha* || "$VERSION_TAG" == *rc* ]]; then if [[ "$VERSION_TAG" == *beta* || "$VERSION_TAG" == *alpha* || "$VERSION_TAG" == *rc* ]]; then
IS_PRERELEASE="true" IS_PRERELEASE="true"
fi fi
@ -134,13 +137,26 @@ jobs:
CHANGELOG_BODY="" CHANGELOG_BODY=""
if [ -z "${LAST_TAG}" ]; then if [ -z "${LAST_TAG}" ]; then
# 如果没有上一个标签,则获取从第一次提交到当前标签的所有提交 # 如果没有上一个标签或者新创建的标签在当前Git环境中可能还没完全同步
echo "No previous tag found. Generating changelog from initial commit to ${CURRENT_TAG}." # 我们将从上一个提交到当前提交HEAD生成日志
CHANGELOG_BODY=$(git log --pretty=format:"* %s (%h)" "${CURRENT_TAG}") echo "No previous tag found or current tag not fully recognized. Generating changelog from last commit to HEAD."
# 获取最近的非合并提交作为起始点,或者直接从仓库的起源点开始
# git log HEAD^..HEAD 获取当前提交与前一个提交之间的差异
# git log --pretty=format:"* %s (%h)" HEAD 只获取当前提交的信息
# 为了确保包含所有自上次"已知"状态以来的提交
# 我们可以使用 git log <last_known_tag>..HEAD 或者直接 HEAD
# 但如果您确定这是第一次发布,那么从 HEAD 开始生成所有日志也可以
# 最稳妥的方法是如果LAST_TAG为空日志内容是“首次发布”或只包含当前提交
# 如果您想包含所有历史,需要从根提交开始,但这通常不适用于“更新日志”
CHANGELOG_BODY=$(git log --pretty=format:"* %s (%h)" HEAD)
echo "Note: This is likely the first release or a tag issue. Changelog shows current commit(s)."
else else
# 获取上一个标签到当前标签之间的所有提交 # 获取上一个标签到当前标签之间的所有提交
echo "Generating changelog from ${LAST_TAG}..${CURRENT_TAG}" # 这里使用 HEAD 作为终点,以确保获取到当前工作树中的所有提交
CHANGELOG_BODY=$(git log --pretty=format:"* %s (%h)" "${LAST_TAG}..${CURRENT_TAG}") echo "Generating changelog from ${LAST_TAG}..HEAD"
CHANGELOG_BODY=$(git log --pretty=format:"* %s (%h)" "${LAST_TAG}..HEAD")
fi fi
# 使用EOF语法输出多行字符串 # 使用EOF语法输出多行字符串
@ -157,13 +173,13 @@ jobs:
icon: .\doro.ico icon: .\doro.ico
target: x64 target: x64
ahk-tag: v2.0.19 ahk-tag: v2.0.19
github-token: ${{ secrets.GITHUB_TOKEN }} # 用于避免 GitHub API 限速 github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Release - name: Create GitHub Release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ steps.get_version.outputs.VERSION_TAG }} # 使用从脚本提取的版本号作为标签名 tag_name: ${{ steps.get_version.outputs.VERSION_TAG }}
name: ${{ steps.get_version.outputs.VERSION_TAG }} # Release 的标题 name: ${{ steps.get_version.outputs.VERSION_TAG }}
body: | body: |
${{ steps.changelog.outputs.CHANGELOG_BODY }} ${{ steps.changelog.outputs.CHANGELOG_BODY }}