From ae41c4aeefe229a1525f347e26eafcc441610c36 Mon Sep 17 00:00:00 2001 From: xunxi Date: Mon, 4 May 2026 16:44:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=E5=8A=A0=E5=85=A5=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=91=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 98 +++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4773c87 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,98 @@ +name: Auto Release + +on: + push: + branches: [main, master] + paths: + - 'metadata.yaml' + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Extract version from metadata.yaml + id: get_version + run: | + # 提取版本号(去除 # 后面的注释) + VERSION=$(grep -E '^version:' metadata.yaml | sed 's/version: *//' | sed 's/ *#.*//' | tr -d ' ') + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Extracted version: $VERSION" + + - name: Check if release exists + id: check_release + run: | + if gh release view ${{ steps.get_version.outputs.version }} &>/dev/null; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Release ${{ steps.get_version.outputs.version }} already exists" + else + echo "exists=false" >> $GITHUB_OUTPUT + echo "Release ${{ steps.get_version.outputs.version }} does not exist" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract changelog for version + if: steps.check_release.outputs.exists == 'false' + id: get_changelog + run: | + VERSION="${{ steps.get_version.outputs.version }}" + echo "Looking for version: $VERSION" + + # 使用 Python 提取 changelog + CHANGELOG=$(python3 -c " + import re + import sys + + version = '$VERSION' + + try: + with open('CHANGELOG.md', 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + print('修复了一些已知问题') + sys.exit(0) + + # 匹配指定版本的内容 + pattern = rf'^## \\[{re.escape(version)}\\].*?\\n(.*?)$(?=\\n## \\[|\\Z)' + match = re.search(pattern, content, re.MULTILINE | re.DOTALL) + + if match: + changelog = match.group(1).strip() + if changelog: + print(changelog) + else: + print('修复了一些已知问题') + else: + print('修复了一些已知问题') + ") + + # 如果 changelog 为空,使用默认提示 + if [ -z "$CHANGELOG" ]; then + CHANGELOG="修复了一些已知问题" + fi + + echo "Extracted changelog:" + echo "$CHANGELOG" + + # 写入输出 + { + echo "changelog<> $GITHUB_OUTPUT + + - name: Create Release + if: steps.check_release.outputs.exists == 'false' + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.get_version.outputs.version }} + name: ${{ steps.get_version.outputs.version }} + body: ${{ steps.get_changelog.outputs.changelog }} + generate_release_notes: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 602b565bb885432bf0725a8fe4a504f89d5a1390 Mon Sep 17 00:00:00 2001 From: xunxi Date: Mon, 4 May 2026 19:06:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=91=E7=89=88?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4773c87..d9991dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Auto Release on: push: - branches: [main, master] + branches: [main] paths: - 'metadata.yaml' @@ -43,12 +43,12 @@ jobs: VERSION="${{ steps.get_version.outputs.version }}" echo "Looking for version: $VERSION" - # 使用 Python 提取 changelog - CHANGELOG=$(python3 -c " + # 创建 Python 脚本文件来提取 changelog + cat > extract_changelog.py << 'PYTHON_SCRIPT' import re import sys - version = '$VERSION' + version = sys.argv[1] try: with open('CHANGELOG.md', 'r', encoding='utf-8') as f: @@ -57,9 +57,9 @@ jobs: print('修复了一些已知问题') sys.exit(0) - # 匹配指定版本的内容 - pattern = rf'^## \\[{re.escape(version)}\\].*?\\n(.*?)$(?=\\n## \\[|\\Z)' - match = re.search(pattern, content, re.MULTILINE | re.DOTALL) + # 匹配指定版本的内容 (匹配 ## [vX.Y.Z] 到下一个 ## [ 或文件结尾) + pattern = rf'## \[{re.escape(version)}\]\s*-\s*\d{{4}}-\d{{2}}-\d{{2}}\s*\n(.*?)(?=\n## \[|\Z)' + match = re.search(pattern, content, re.DOTALL) if match: changelog = match.group(1).strip() @@ -69,7 +69,13 @@ jobs: print('修复了一些已知问题') else: print('修复了一些已知问题') - ") + PYTHON_SCRIPT + + # 执行 Python 脚本并将输出写入文件 + python3 extract_changelog.py "$VERSION" > changelog_output.txt + + # 读取文件内容到变量 + CHANGELOG=$(cat changelog_output.txt) # 如果 changelog 为空,使用默认提示 if [ -z "$CHANGELOG" ]; then @@ -79,12 +85,15 @@ jobs: echo "Extracted changelog:" echo "$CHANGELOG" - # 写入输出 + # 写入 GitHub Actions 输出 { echo "changelog<> $GITHUB_OUTPUT + + # 清理临时文件 + rm -f extract_changelog.py changelog_output.txt - name: Create Release if: steps.check_release.outputs.exists == 'false'